Skip to content

Instantly share code, notes, and snippets.

@mczerniawski
Created December 18, 2018 15:37
Show Gist options
  • Save mczerniawski/c6de35cd2ca9a4b7c47265f7417fa32b to your computer and use it in GitHub Desktop.
Save mczerniawski/c6de35cd2ca9a4b7c47265f7417fa32b to your computer and use it in GitHub Desktop.
$ComputerPSSession = New-PSSession -ComputerName $ServerList.servers.server.name -Credential $Credential
$params =@(
@{
ComputerName = 'ComputerName1'
Counter = $MetricList
SampleInterval = 3
MaxSamples = 3
},
@{
ComputerName = 'ComptuerName2'
Counter = $MetricList1
SampleInterval = 3
MaxSamples = 3
}
)
$processedComputers = invoke-command -Session $ComputerPSSession -ScriptBlock {
$fileName = '{0}_{1}_{2}.{3}' -f $USING:currentDate, $env:computername , $USING:profile, $USING:perfmonsOutputFileFormat
$destinationFileName = Join-Path -Path $env:temp -ChildPath $fileName
$currentParam = $USING:params | where-object {$PSItem.ComputerName -eq $env:computerName}
Get-Counter $currentParam | Export-Counter -Path $destinationFileName -FileFormat $USING:perfmonsOutputFileFormat
[pscustomobject]@{
FilePath = $destinationFileName
ComputerName = $env:ComputerName
}
}
foreach ($Computer in $processedComputers) {
$currentSession = $ComputerPSSession | Where-Object {$PSItem.ComputerName -eq $Computer.PSComputerName}
Copy-Item -FromSession $currentSession -Path $Computer.FilePath -Destination .\
}
if($ComputerPSSession) { $ComputerPSSession | Remove-PSSession }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment