schtasks

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

%d bloggers like this: