I'm brand new to powershell and am trying to convert an old batch script that run some sql files via sqlcmd command to a powershell script.
This is my test script so far:
$server = Read-Host 'Server name: '
$db = Read-Host 'Database name: '
$user = Read-Host 'Username: '
$pass = Read-Host 'Password: '
$outputpath = (pwd).path
$File01 = $outputpath + '\Code\Scripts\Summarise_Data.sql'
# Output File
$Summary = $outputpath + '\Summary.csv'
if (Test-Path $Summary)
Invoke-Sqlcmd -ServerInstance $server -User $user -Password $pass -Database $db -InputFile $File01 | Export-Csv -Delimiter ',' -NoTypeInformation $Summary
The code works, and creates the output CSV file with the correct data in it. However, when the Invoke command is run, the following error is returned to the console 5 times.
WARNING: Could not obtain SQL Server Service information. An attempt to connect to WMI on 'Microsoft.WindowsAzure.Commands.SqlDatabase.Types.ps1xml' failed with the following error: The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
The error appears to be a red herring because as I said above, the actual code and output works fine.
As I am new to powershell I'm not sure how I can suppress this error, or what I need to do to prevent it happening. I've tried searching for a solution but nothing I have seen has given a solution. The one solution I did find involved changing a config file, but permissions on the file wouldn't allow me to do this, even though I am a local admin on my machine.
Has anybody else experienced this and been able to resolve?
I'm running Windows 10. I experience this on all instances of SQL I have tried, regardless of SQL version.