我该如何使用服务器列表

尝试做$ComputerList = gc <list location>,但似乎没有用
一台电脑正确

$Start = (Get-Date).AddMinutes(-120)
$ComputerList = $env:ComputerName
$Events = gc C:\Temp\ErrorCodes.txt

# Getting all event logs
Get-EventLog -AsString -ComputerName $Computername |
ForEach-Object {
# write status info
Write-Progress -Activity "Checking Eventlogs on \\$ComputerName" -Status $_

# get event entries and add the name of the log this came from
Get-EventLog -LogName $_ -EntryType Error, Warning -After $Start -ComputerName $ComputerName -ErrorAction SilentlyContinue |
  Add-Member NoteProperty EventLog $_ -PassThru | Where-Object {$Events -contains $_.eventid}

} |
# sort descending
Sort-Object -Property EventLog |
# select the properties for the report
Select-Object EventLog, EventID, TimeGenerated, EntryType, Source, Message
# output into grid view window
Out-GridView -Title "All Errors & Warnings from \\$Computername"

最佳答案

强制将其作为数组。否则,如果只有一项,它将作为字符串输入
$ComputerList = @(gc c:\folder\computerlist.txt)
PowerShell: How can I to force to get a result as an Array instead of Object

关于powershell - Powershell计算机列表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24397551/

10-11 03:26