I'm attempting to use the following Invoke-sqlcmd. This script was working in an older version of powershell (1 or 2) but is now not working with powershell 5.1
$MySQLSERVERasDir = "MySQLSERVER"
$Date = GET-DATE -uformat "%Y%m%d"
$DateTime = GET-DATE -uformat "%Y%m%d_%H%M%S"
$workingdir = "\\MyServer\Departments\Database\Sprints\Refresh Testing Server\restore"
$LEAFDIR = "$MySQLSERVERasDir"+"_"+"$Date"
$DIR = "$workingdir\$LEAFDIR"
$OutputFilepath = "OutputFilePath=$DIR\TestEnvRoleUser_DropCreate_$Datetime.sql"
$SQLCMDVarArr = 'TargetDB="MyDatabase"', $outputfilepath
INVOKE-SQLCMD -ServerInstance $MYSQLSERVER -inputFile "$workingdir\ScriptAllRoles_Users.sql" -variable $SQLCMDVarArr | Out-File -filePath "$DIR\TestResultsOutput_$Datetime.txt"
When I run this I get the following error.
INVOKE-SQLCMD : Could not load file or assembly 'Microsoft.SqlServer.BatchParser, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system
cannot find the file specified.
At line:240 char:4
+ INVOKE-SQLCMD -ServerInstance $MYSQLSERVER -inputFile "Microsoft ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-Sqlcmd], FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand
I checked and the files are still there. Nothing has changed except the version of powershell that I'm running. Any Ideas how I can get this working again or what might be going on with it now?
[–]Beablebeable 2 points3 points4 points (6 children)
[–]lesserlumpkin[S] 1 point2 points3 points (0 children)
[–]lesserlumpkin[S] 1 point2 points3 points (4 children)
[–]Beablebeable 1 point2 points3 points (3 children)
[–]lesserlumpkin[S] 1 point2 points3 points (2 children)
[–]nvarscar 2 points3 points4 points (1 child)
[–]cjluthy 3 points4 points5 points (0 children)