PowerShell - 在屏幕上显示输出/操作

时间:2014-05-19 15:05:48

标签: powershell powershell-v2.0

有这个脚本

"`n" 
$user = Read-Host "Enter Username"
write-Host "Finding" -ForegroundColor Red
$filePath = "\\myserver\d$\location\$user\Profile\AppData\Roaming\app\$user" 
"`n" 

$Response = Read-Host "Do you want to delete the contents of this directory for '$user' ?(Y/N)"
if($Response -eq "Y"){
   get-childitem $filepath -recurse | foreach ($_) {remove-item $_.fullname}
 }else{
    Write-Host "No such user found or directory does not exist..."
}

write-Host "" 
write-Host "------------Process Complete Files Removed--------------------" -ForegroundColor magenta


Start-Sleep -s 120

我希望显示正在删除的文件的输出/实际发生的过程。在进程完成脚本的一部分之前,有什么办法吗?

1 个答案:

答案 0 :(得分:2)

使用-Verbose上的Remove-Item参数:

Get-ChildItem $filepath -recurse | Where {!$_.PSIsContainer} | Remove-Item -verbose