我是 PowerShell 的新手,正在寻求帮助。在这里,我试图在所有驱动器中创建一个文本文件,但似乎我在这里遗漏了一些东西,任何帮助表示赞赏:
$drives = get-psdrive -p "FileSystem"
foreach ($drive in $drives)
{
New-Item -Path '$drive:\IO.txt' -ItemType File
}
另外,还有另一个关于如何排除特定驱动器的问题,例如“A:”、“C:”、“D:”驱动器?
谢谢
我认为这更像是你所追求的。
$drives = get-psdrive -p "FileSystem"
$exclude = "C","D"
foreach ($drive in $drives) {
# Exclamation (!) is the same as -not meaning if not $true > Do the thing
If(!$exclude.Contains($drive.Name)) {
New-Item -Path "$($drive):\IO.txt" -ItemType File
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句