用於將使用者設定檔從 Windows Server 2008 r2 刪除到本機電腦 (Windows 7) 的 Power Shell 腳本

用於將使用者設定檔從 Windows Server 2008 r2 刪除到本機電腦 (Windows 7) 的 Power Shell 腳本

我在 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)} |刪除使用者設定檔

相關內容