I wrote a powershell script that includes a check for the
invoke-sqlcmd cmdlet. Script runs fine under Windows Server 2016. On 2012 R2, the script fails with:
Add-Content : Cannot use interface...
errors when trying to create and write to a log file.
What I discovered is that on Windows Server 2012 R2, when the
Get-Command invoke-sqlcmd command is run, it changes my drive to
PS SQLSERVER:\> instead of
PS C:\>. This is apparently causing my
update log file sections to fail.
Any idea why
Get-Command would change the drive when checking for a SQL cmdlet, and suggestions to change it back or prevent it in the first place? I know I could throw a
c: in the script, but that seems too simple a solution and might have to do it after every DB call.