In the script below I am calling a batch file to break mirroring between some dbs. The batch file has a user prompt to start the script but the PS script races right past it. When I call the batch file directly from the powershell console it works fine. How can I keep the script from move past the invoke command block with until the batch file is complete?
$session = New-PSSession -computerName xssqlk02 -credential $cred
Invoke-Command -Session $session -Scriptblock {c:\MSSQL\DBMaintenance\Mirroring\SERVER_Remove_Mirroring.bat xssqlk02 ossqlk02}
Remove-PSSession $session
edit: I trimmed up just the part of the code that I am having problems with. When this is run from a ps script I just noticed (it's been a long day....) I am getting the following error and it runs through the user prompt at that point.
PS C:\Users\dans> C:\Tools\Scripts\test5.ps1 A subdirectory or file c:\MSSQL\DBMaintenance\Mirroring\Common already exists. + CategoryInfo : NotSpecified: (A subdirectory ...already exists.:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError
Invalid drive specification Remove Mirroring for RCM databases between xssqlk02 and ossqlk02: Continue? y/n 0 File(s) copied
Here is what the output is when I just run the batchfile directly from the PS console on the local machine.
PS C:\Documents and Settings\DanS> c:\MSSQL\DBMaintenance\Mirroring\SERVER_Remove_Mirroring.bat xssqlk02 ossqlk02
Remove Mirroring for RCM databases between xssqlk02 and ossqlk02: Continue? y/n y
A subdirectory or file c:\MSSQL\DBMaintenance\Mirroring\Common already exists.
\OPFLSK02\SQLBackupsForTape\DBMaintenance\Mirroring\Common\DB_Create_Snapshots.bat \OPFLSK02\SQLBackupsForTape\DBMaintenance\Mirroring\Common\DB_Force_Mirror_To_Principal.bat ....... 18 File(s) copied
The error occurs because the batch file does not have a check to see if the directory already exists. How do I handle this is from the invoke command block to allow the script to continue? For the moment I am not able to change the batch file itself.