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.
invoke-command
ie...{ write-host "working on pc $_"; invoke-command -computerName...
. This will help you zone in on the problem. – Raf