I have an aprox 1000 line-script which loops through all servers in AD. The script pings each server and does a bunch of WMI-querys if ping=ok. My script stores the results in a hashtable that I output to a CSV at the end of the script. This works, but it is sloooow.. We are talking close to two hours. I've been looking into doing this more efficient and I think -asjob sounds like a good idea.
But can I do this as concurrent jobs? Would my server handle the load? And is -asjob the way to do it?
Hoping for some input while I'm waiting for my script to run it's cycle..
EDIT
My opinion is that the script waits for test-connection (ping) to return true or false. I would like to run multiple pings at the same time.
EDIT 2
(NOTE: I Have started a separate question as I feel my original question has been answered. I include my current code anyways as this has been requested. Thank you everyone for pitching in! new question here!)
Thank you everybody for the help so far! I've been asked to list my code to provide a real-world example of what I am trying to do.
This is a small, but valid excerpt from my code:
# List 4 servers (for testing)
$servers = Get-QADComputer -sizelimit 4 -WarningAction SilentlyContinue -OSName *server*,*hyper*
# Create list
$serverlistlist = @()
# Loop servers
foreach($server in $servers) {
# Fetch IP
$ipaddress = [System.Net.Dns]::GetHostAddresses($Server.name)| select-object IPAddressToString -expandproperty IPAddressToString
# Gather OSName through WMI
$OSName = (Get-WmiObject Win32_OperatingSystem -ComputerName $server.name ).caption
# Ping the server
if (Test-Connection -ComputerName $server.name -count 1 -Quiet ) {
$reachable = "Yes"
}
# Save info about server
$serverInfo = New-Object -TypeName PSObject -Property @{
SystemName = ($server.name).ToLower()
IPAddress = $IPAddress
OSName = $OSName
}
$serverlistlist += $serverinfo | Select-Object SystemName,IPAddress,OSName
}
Notes: I am outputting $serverlist to a csv-file at the end of the script I list aprox 500 servers in my full script.