I need to Run this PowerShell script in different servers remotely with credentials & collect data in single csv and send to email. i Include the Invoke Command, but getting error.
$servers = Get-Content "c:\serverlist\servers.txt"
$Report = foreach ($server in $servers){
Invoke-Command -ComputerName $server -ScriptBlock
}
{
$props = @(
@{
N='ServerName'
E={ $env:COMPUTERNAME }
}
'StartDate'
'EndDate'
'ConnectorName'
'RunProfileName'
'StepResult'
)
$profiles = @(
'Delta Import'
'Delta Synchronization'
'Full Import'
'Full Synchronization'
) -join '|'
Get-ADSyncToolsRunstepHistory | Group-Object RunProfileName |
Where-Object Name -Match $profiles | ForEach-Object {
$_.Group | Select-Object -First 2
} } | Select-Object $props | Export-Csv c:\serverlist\export.csv -NoTypeInformation