
我在該網域中有一些客戶,有些則不在該網域中。我需要知道如何檢索特定本機使用者在哪些客戶端上存在,然後將其刪除。對於網域客戶端來說,使用 GPO 非常容易,但是非網域客戶端呢?我知道 Powershell 命令取得本地用戶和刪除本機用戶,但我不想在每台 PC 上啟動它。您知道有什麼腳本可以幫忙嗎?
謝謝
答案1
您需要啟用 PSRemoting (工作群組模式)在那些非網域電腦上,然後您可以使用遠端處理來執行此操作,並且這些系統必須具有最新的 PSv5 或具有來自 MS powershellgallery.com 的本機使用者管理模組。
您仍然需要接觸每台機器才能設定遠端處理。
•在獨立(工作小組)電腦上啟用 PowerShell 遠端處理
•獨立工作小組電腦之間的 PowerShell PS 遠端處理
閱讀每篇文章,了解所有詳細信息,但在一個片段中,它是:
### Remote Computer
NetConnectionProfile -NetworkCategory Private
Enable-PSRemoting -SkipNetworkProfileCheck -Force
Set-NetFirewallRule –Name "WINRM-HTTP-In-TCP-PUBLIC" –RemoteAddress Any
### Local computer
# Review teh trusted host file
Get-Item WSMan:\localhost\Client\TrustedHosts
# Set the trusted a specific target
Set-Item WSMan:\localhost\Client\TrustedHosts -Value "10.0.2.33" -Force
# Or for several hosts if you don't want to specify them individually
Set-Item WSMan:\localhost\Client\TrustedHosts -Value "*" -Force
# Connect to a host
Enter-PSSession -ComputerName 10.0.2.33 -Credential $Credentials
您可以執行一些 PowerShell 命令未啟用遠端處理:
•使用 Windows PowerShell 遠端工作,無需使用遠端處理或 WinRM
Get-WinEvent
Get-Counter
Get-EventLog
Clear-EventLog
Write-EventLog
Limit-EventLog
Show-EventLog
New-EventLog
Remove-EventLog
Get-WmiObject
Get-Process
Get-Service
Set-Service
Get-HotFix
Restart-Computer
Stop-Computer
Add-Computer
Remove-Computer
Rename-Computer
Reset-ComputerMachinePassword
或使用 MS Sysinternals PSExec.exe 工具: