【发布时间】:2018-04-18 00:03:22
【问题描述】:
目前我正在我的 PowerShell 脚本中执行此操作:
$ServiceTagsPath=$filePath + '\DellAPIWarrantyLIST.csv'
write-host 'get all computer names from Active Directory...for Windows 7...'
Get-ADComputer -properties * -filter {(operatingsystem -like "*Windows 7*")} |
Where-Object {$_.name -like "*-*"} |
Where-Object {$_.name -NotLike "V7-*"} |
Where-Object {$_.name -NotLike "*-NONE"} |
Where-Object {$_.name -NotLike "*-ONCALL"} |
Where-Object {$_.name -NotLike "*-BLACKBAUD"} |
Where-Object {$_.name -NotLike "SC-WIN7-1"} |
Where-Object {$_.name -NotLike "UT-SWCLIENT-01"} |
Select-Object -property Name , LastLogonDate | export-csv $ServiceTagsPath -NoTypeInformation -Force
$computers= Get-ADComputer -properties * -filter {(operatingsystem -like "*Windows 7*")} |
Where-Object {$_.name -like "*-*"} |
Where-Object {$_.name -NotLike "V7-*"} |
Where-Object {$_.name -NotLike "*-NONE"} |
Where-Object {$_.name -NotLike "*-ONCALL"} |
Where-Object {$_.name -NotLike "*-BLACKBAUD"} |
Where-Object {$_.name -NotLike "SC-WIN7-1"} |
Where-Object {$_.name -NotLike "UT-SWCLIENT-01"} |
Select-Object -Expand Name
Write-Host $computers.Length + ' computers found in Active Directory...'
第一个给我一个包含 2 列和大约 1500 条记录的 csv 文件,第二个给我一个数组变量,我在对 API 的 Web 服务调用中使用它...
但是有可能一步完成吗? 有没有办法同时完成这两项工作,以及拥有一个包含 2 列的 csv 文件,显示计算机名称和 LastLogondate,我将有一个仅包含计算机名称的数组?
【问题讨论】:
-
为什么不只使用一个 Get-ADComputer 查询($computers,去掉 Select-Object 语句),然后用它做任何你需要做的事情。搜索 AD 2x 只是为了以不同的方式输出它似乎没有必要。
标签: powershell