I'm trying to run the following code, but PowerShell is not exporting the output correct and getting the following error:
Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
Here is the code:
$SERVERS = gc "C:\Users\listOfServers.txt"
$out = foreach ($SERVER in $SERVERS) {
$InvokeParams = @{
Server = $SERVER
Database = 'test'
Username = 'admin'
Password = 'testpassword'
InputFile = 'C:\business.sql'
}
Invoke-SqlCmd @InvokeParams |
Select-Object -Property *, @{L='Server';E={$SERVER}}
}
$path = 'C:\Users\test1.csv'
$out | Export-Csv -Path $path
Invoke-Item -Path $path
Goal is to export the current output to Excel, also ADD a statement for the servers that does not have any output as well.
ValueDate: 4/30/2019 12:00:00 AM PrevValueDate: 4/29/2019 12:00:00 AM Count:2100 Server 1 Server 2 : no errors **NEEDS TO BE ADDED ValueDate: 4/30/2019 12:00:00 AM PrevValueDate: 4/29/2019 12:00:00 AM Count:100 Server 3
Based on this questions and some helpful answers: Powershell - Separate output based on Server + export to Excel.
$outlook like before you export it and How much servers are in$servers? Do you get the Error for every server or once?-querytimeout xparameter where x is the number of seconds.