如果名称超过260个字符,使用Powershell删除远程计算机上的文件的最简单方法是什么?我有以下代码,但我达到了260个字符的限制。
$s = New-PSSession -computername Server1
Invoke-Command -session $s -scriptblock
{Remove-Item "C:\Jenkins\workspace\Long Path with spaces" -force
-recurse}
Remove-PSSession $s
不幸的是,这是Powershell中的一个众所周知的限制。
这个问题已经在StackExchange中得到了回答,公认的答案是使用cmd
而dir
不是收集文件夹列表。
该答案还提供了以下参考链接:http: //asysadmin.tumblr.com/post/17654309496/powershell-path-length-limitation基本上解释dir
了在这种情况下为什么可以做到这一点,并显示了以下示例:
The Dir version is longer since you have to strip the extra information from the results.
$folders = cmd /c dir C:\Users /s /-c /a:h /a:d
$folders = $folders -match “Directory”
$folders = $folders | %{$_.Replace(“ Directory of ”,“”)}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句