Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1096843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:20:27+00:00 2026-05-17T00:20:27+00:00

In the script below I am calling a batch file to break mirroring between

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:20:28+00:00Added an answer on May 17, 2026 at 12:20 am

    If Alexey’s solution doesn’t work, you can try this one:

    $job = Invoke-Command -Session $session -Scriptblock { Start-Process -FilePath "C:\MSSQL\DBMaintenance\Mirroring\SERVER_Remove_Mirroring.bat" -ArgumentList "xssqlk02", "ossqlk02" -Wait } -AsJob
    $job | Wait-Job
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The script below works fine if 3 and 3.2 are not links but i
The script below resides in my theme's functions.php file. It is designed to show
The script below should open all the files inside the folder 'pruebaba' recursively but
My script below will use two external tables to fill two separate tables, but
I have the following script below where I try to mimic a file upload
When I run the script below, I get $VAR1 = [ 'ok0.ok]][[file:ok1.ok', undef, undef,
By calling the example URL below my Java servlet caches one file at a
I have written the script run.sh below for calling a java class : java
I'm calling a jQuery GET on the test.php file code below. I'm trying to
Below is my code in a single PHP file named testOne.php <html> <head> <script

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.