我使用了幾個變量,但通常我使用從Get-ChildItem
cmdlet返回的對象來查找文件並使用已更改的if語句。查找特定文件並將其刪除(如果存在)
但是我怎樣才能找到目錄中的特定文件,如果它發現它然後刪除它?這是我做的代碼:
$VM_NAME="Test"
$search=Get-ChildItem -Path B:\Virtualservers\Disks\Users\* -include $VM_NAME.vhdx -filter *.vhdx -Recurse
if ($search.Name -contains "$VM_NAME.vhdx") {remove-item ??? }
else {write-host "Continue.."}
謝謝你,真的! –