[英]Getting Output of ADSI Command in Powershell
I'm trying to delete some local administrator users on multiple computers. 我正在尝试删除多台计算机上的一些本地管理员用户。 Here is the script I used and it works:
这是我使用的脚本,它可以工作:
Import-Csv c:/input.csv | ForEach-Object {
([ADSI]"WinNT://$($_.ComputerName)").Invoke("Delete", "user", $_.Username)
}
The problem is that I want to get the results of the non-deleted users directly to a text file. 问题是我想直接将未删除用户的结果获取到文本文件中。 What commands would help me?
什么命令对我有帮助? I've tried
Out-File
, but it's giving me an empty file. 我尝试了
Out-File
,但是给了我一个空文件。
Use Get-WmiObject
to query a remote host for local users: 使用
Get-WmiObject
查询本地用户的远程主机:
$csv = Import-Csv 'C:\input.csv'
$lcl = 'LocalAccount=True'
$csv | ForEach-Object { [ADSI]... }
$csv | Sort-Object -Unique ComputerName | ForEach-Object {
Get-WmiObject -Computer $_.ComputerName -Class Win32_UserAccount -Filter $lcl
} | Select-Object PSComputerName, Name | Export-Csv 'C:\output.csv' -NoType
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.