Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Scripting gathering and inventorying info

$
0
0

Hi David,

Scenario 1
Formatting is possible, but think of it separately from the actual data. Part of the reason for that is we sometimes want to process the data after it’s collected or even saved to disk. Once you format it you don’t try to sort/filter/calculate/process the data. It sounds like you want to use what is called a Hashtable. Since I’m not very familiar with them I don’t want to give incorrect info.

Scenario 2
The gpupdate command you listed just tells me that the GPs have been applied, so I’m not sure what info you are looking to collect specifically so this is a bit general.

You don’t need to store the info in a file on the remote computer. The command can be run on the remote computer with the results coming back to the computer you started it on. Think of it like this:

$Scriptblock = {gpupdate /force /wait:120}
$ServerList = Get-Content c:\Servers.txt
$LogFolder = “\\Server1\Files”

# Start the job on each server
Foreach ($Server in $ServerList) {
  Invoke-Command -scriptblock $ScriptBlock -computername $Server -asjob $(“Info-”+$server)
  }

# Wait for the information to be collected
$Totaljobs = (Get-Job Info*).count

do {
    Sleep -Seconds 5
    $FinishedJobs = (Get-Job Info* | where {$_.state -ne “Running”}).count
    Write-Host ”  $FinishedJobs completed so far…” -ForegroundColor DarkGray
    }while ($FinishedJobs -lt $Totaljobs)

Write-Host
Write-Host “All jobs are done” -ForegroundColor Green

#get-job Info* | ft Id, Name, State, HasMoreData -AutoSize
Write-Host

# Save the results
$ResultsFile = “Server_Audit-$((Get-Date -Format yyyyMMdd)).csv”
Receive-Job Info* | Select-Object -Property * -ExcludeProperty RunspaceID, PSShowComputerName | Export-Csv -NoTypeInformation -Path “$LogFolder\$ResultsFile”
Write-Host “You will find the results at $(“$LogFolder\$ResultsFile”)” -ForegroundColor Green
Remove-Job Info*

Viewing all articles
Browse latest Browse all 13067

Trending Articles