Windows用户删除脚本
我需要有关此代码的一些帮助。从理论上讲,该代码可行,但是当代码运行所有用户配置文件以外的所有用户配置文件时,我的排除量将被删除。我希望最后一次登录配置文件保留在30天内,并在30天内删除用户。我尝试了不同的addday( - )
,但是问题仍然存在。
谁能帮忙?
$ExcludedUsers = "ExcludedFolder"
$LocalProfiles = Get-WMIObject -class Win32_UserProfile | Where-Object { (!$_.Special) -and (!$_.Loaded) -and ($_.ConvertToDateTime($_.LastUseTime) -lt (Get-Date).AddDays(-30)) }
foreach ($LocalProfile in $LocalProfiles) {
if (!($ExcludedUsers -like $LocalProfile.LocalPath.Replace("C:\Users\", ""))) {
$LocalProfile | Remove-WmiObject
Write-host $LocalProfile.LocalPath, "Profile Has Been Deleted” -ForegroundColor Red
}
}
感谢您的帮助
I need some help with this code. The code, in theory, works however, when the code runs all user profiles apart from the ones in my excluded are deleted. I want the last login profiles to remain within 30 days and users over 30 days to be deleted. I have tried different AddDays(-)
however the problem remains.
Could anyone help?
$ExcludedUsers = "ExcludedFolder"
$LocalProfiles = Get-WMIObject -class Win32_UserProfile | Where-Object { (!$_.Special) -and (!$_.Loaded) -and ($_.ConvertToDateTime($_.LastUseTime) -lt (Get-Date).AddDays(-30)) }
foreach ($LocalProfile in $LocalProfiles) {
if (!($ExcludedUsers -like $LocalProfile.LocalPath.Replace("C:\Users\", ""))) {
$LocalProfile | Remove-WmiObject
Write-host $LocalProfile.LocalPath, "Profile Has Been Deleted” -ForegroundColor Red
}
}
I appreciate your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论