【发布时间】:2018-10-04 21:58:54
【问题描述】:
我有一些机器有很多配置文件,我想删除所有配置文件,除了 3 个是管理员。
如果我想删除所有内容,这将完成这项工作
Get-WMIObject -Class Win32_USerProfile -ComputerName $computer | Remove-WmiObject
我曾尝试使用where 子句和-filter 来做到这一点,但没有成功。
这里有一些例子
Get-WMIObject -Class Win32_UserProfile -ComputerName $computer | where {($.SID -neq $UserSID)} | Remove-WMIObject
...
Get-WMIObject -Class Win32_USerProfile -ComputerName $computer -Filter "SID = TEST" | Remove-WmiObject
编辑:我几乎是这样的:
Get-WMIObject -Class Win32_USerProfile -ComputerName $computer | Where-Object -FilterScript {$_.SID -ne "S-1-5-18" -and $_.SID -ne "S-1-5-19" -and $_.SID -ne "S-1-5-20"} |Remove-WmiObject -WhatIf
这样我可以过滤输出,但我遇到了异常
+ CategoryInfo : NotSpecified: (:) [Remove-WmiObject], ArgumentException
【问题讨论】:
标签: powershell wmi user-profile get-wmiobject