%20%E7%9A%84%20Power%20Shell%20%E8%85%B3%E6%9C%AC.png)
我在 Windows Server 2008 R2 上嘗試使用以下腳本來刪除 Windows 7 用戶端電腦上的使用者設定檔。
PS C:\> get-content localcomputer-list.txt | get-userprofile | where {$_.LastUse 'lt (Get-Date).AddDays(-90)}} | remove-userprofile -whatif
這不起作用。
我該如何解決這個問題?
答案1
我假設你從這裡得到了你的片段:
http://www.itninja.com/blog/view/manage-purge-local-windows-user-profiles
您需要載入 get-userprofile 模組。
另外,buddy 在他的程式碼中使用 ' 來表示 - 。所以:
取得內容 mydesktops.txt |取得使用者個人資料 |其中 {$_.LastUse -lt (Get-Date).AddDays(-90)} |刪除使用者設定檔
如果我嘗試按照他的帖子中的指示遠端使用腳本,則腳本對我不起作用。
因此這有效:
取得使用者個人資料 |其中 {$_.LastUse -lt (Get-Date).AddDays(-90)} |刪除使用者設定檔