0
votes

New to Powershell and scripting. I have the following script that intermittently returns the System error 1312 A specified logon does not exist. It may have already been terminated.

Get-Content D:\Logbooks.txt | ForEach-Object {Invoke-Command -computername $_ -FilePath "D:\Folder\Script.ps1" if (-not$?){Write-Warning "$_ - SQL SCRIPT FAILED"} else {Write-Host "$_ - SQL SCRIPT SUCCESSFUL"-ForegroundColor "Green"}}

I wrote that script to execute this one.

net use \computername\D$ password /User:username
sqlcmd -S .\SQLEXPRESS -o C:\test.txt -d database -i "\computername\D$\Folder\SQL Script.sql"

I am using these to execute a SQL script on remote machines running SQL Express. All computers are running Windows 7. I also created a second admin account on the computer I am running the scripts from and using that login after the net use command. It works fine sometimes but other times I get the error from only a couple of remote computers.

1
I've not run into this myself, but I'd suggest that intermittent errors are because of network problems.crthompson
This was my assumption as well. I wanted to pose the question to be thorough as I am new to this.Kilgrinus
Dito to what @paqogomez said, add a line which will show which of your win7 boxes is being accessed in front of invoke-command ie. ..{ write-host "working on pc $_"; invoke-command -computerName... . This will help you zone in on the problem.Raf

1 Answers

-1
votes

It was a network issue. I was continually running the script to test every little change. Attempting to reconnect to all the remote computers constantly was too much for our small slow network.