I mentioned this before as a way to script adding tasks to a server.  So I came across an issue the other day, where I ran it once, but then it failed on the second time:

ERROR: Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again.

It turns out that schtasks create a mapping to ipc$ on the server, and in some cases doesn’t clear it when the command has completed.

So the easy fix is to unmap it and try again!

So here is the code I use to script test-exchange.cmd that fires off test-exchange.ps1 that I will post next week

$TaskUser = Read-Host “Account DomainAccount “

$TaskPswd = Read-Host “Account Password”

$TaskName = “Test-Exchange”

$ServerName = Hostname

Net use \$ServerNameIPC$ /delete

schtasks /create /s \$ServerName  /tn $TaskName /tr C:PSTest-Exchange.cmd /sc MINUTE /mo 10 /du 0023:55 /u $TaskUser /P $TaskPswd

schtasks /run /s \$ServerName  /tn $TaskName

schtasks /query


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.