我正在将文件夹与所有带有powershell的子文件夹进行比较,并在我的本地计算机上正常工作。但是当我在服务器上尝试它给我错误并追加
Microsoft.PowerShell.Core\FileSystem::\\
所有文件
如果有人早些做过这样的工作,请帮助
我的剧本是
$Path = '\\Server1\Folder1'
Get-ChildItem $Path -Recurse | ? { !$_.PSIsContainer } | % {
Add-Member -InputObject $_ -MemberType NoteProperty -Name RelativePath -Value $_.FullName.Substring($Path)
$_
}
它给我错误
Cannot convert argument "0", with value: "Microsoft.PowerShell.Core\FileSystem::\\Server1\Folder1\ServerListPowershell", for "Substring" to type "System.Int32": "Cannot convert value "M
icrosoft.PowerShell.Core\FileSystem::\\Server1\Folder1\ServerListPowershell" to type "System.Int32". Error: "Input string was not in a correct format.""
At C:\Users\cwr.satish.kumar\AppData\Local\Temp\898f72f1-a0d3-4003-b268-128c5efc9f2b.ps1:14 char:108
+ Add-Member -InputObject $_ -MemberType NoteProperty -Name RelativePath -Value $_.FullName.Substring <<<< ($Path)
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument
请帮忙
最佳答案
尝试Convert-Path
cmdlet:
PS> Convert-Path Microsoft.PowerShell.Core\FileSystem::C:\windows\system32
C:\windows\system32
关于powershell - 如何从路径中删除Microsoft.PowerShell.Core\FileSystem::\\,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14652333/