使用 PowerShell 删除本地 Windows 配置文件 [英] Delete local windows profile with PowerShell
问题描述
我正在尝试编写一个脚本来删除测试帐户的本地配置文件.我正在使用以下行返回以test-"开头的任何帐户的 SID
I am trying to write a script that will delete the local profile of a test account. I am using the following line to return the SID of any account that starts with "test-"
PowerShell: $UserSID = (Get-WmiObject Win32_UserProfile | Where {$_.LocalPath -like '*\test-*'}).SID
PowerShell: $UserSID = (Get-WmiObject Win32_UserProfile | Where {$_.LocalPath -like '*\test-*'}).SID
获得 SID 后,我使用 wmic 进行删除,但我不确定如何将该代码转换为 PowerShell.
Once I had the SID I used wmic to do the deletion but, I am not sure how to translate that code into PowerShell.
WMIC:wmic/node:"localhost" path win32_UserProfile where Sid="%%b" 删除
推荐答案
我以为这会起作用,但我在 Win32_UserProfile 类中找不到删除方法
I was thinking this would work, but I don't find a delete method on the Win32_UserProfile class
$UserSID = (Get-WmiObject Win32_UserProfile | Where {$_.LocalPath -like '*\test-*'}).SID
(gwmi -class Win32_UserProfile -filter "SID='$UserSID'").Delete()
这篇关于使用 PowerShell 删除本地 Windows 配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!