在我们开始编写代码之前,我有一个包含 PC 列表且只有 1 列的 CSV。目标是使用 A 列中标记为“计算机”的信息,并获取这些机器的所有服务,并将它们输出到基于 A 列信息创建的文件夹中。到目前为止,脚本如下:
Import-Module activedirectory
$Group=import-csv C:\Users\axb3055\Documents\CSV_Test.csv
$ServiceList = Test-Path C:\ServiceList
if($ServiceList -eq $true)
{Write-Host "Service List Exists"}
else
{
Write-Host "Creating ServiceList folder"
New-Item C:\ServiceList\$CompName -ItemType directory -ErrorActionSilentlyContinue | Out-Null
}
$Group | foreach {$CompName = $_.Computers New-Item -Path C:\ServiceList\$CompName -ItemType directory | Get-Service -ComputerName $_.Computers} | Out-File C:\ServiceList\$CompName\$CompName.txt
现在发生的事情是创建了服务列表文件夹,但之后没有任何反应。我在 for-each 块中得到一个指向“New-Item”的错误点,但我不确定它可能是什么。有任何想法吗?