下面的行可以从Powershell提示符中很好地工作,但是从计划的任务中失败。
$pass = gc C:\secrets\shhh.txt | convertTo-secureString
$Cred = new-object -typeName System.management.automation.psCredential -argumentlist "domain\domainUser",$pass
$path = "\\server\share\folder"
$j = start-job {gci -path $args[0]} -cred $Cred -argumentList $path | wait-job | receive-job
$body = $j | out-string
$error | out-file C:\temp\err.txt
send-mailMessage -to me@domain.tld -from server@domain.tld -subject halp -smtpserver mailserver.domain.tld -body $body在c:\temp\err.txt中,Windows2008R2计划的任务留下一个面包屑:
[localhost] The background process exited abnormally.
+ CategoryInfo : OpenError: (localhost:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : 2101,PSSessionStateBroken...which把我们带到了这个Microsoft bug报告。报告提到了本地主机回送远程处理的解决方法,这听起来有点脏。我应该去那里吗?
有没有更好的解决办法?可能是使用*会话cmdlet之一还是调用-命令?已设置了计划任务的Start in值,但可能后台进程以某种糟糕的方式使用了一些变量,如所以
还没有用–version 2或-command "& {bigKlugeyScriptblock}"语法调用-command "& {bigKlugeyScriptblock}"。
编辑:我试图避免创建一个新的域帐户来运行任务。任务不能从domainUser以$cred的形式运行,因为该帐户不应该具有本地主机的权限。
发布于 2013-03-14 22:48:15
当一些可能的工作围绕在一起时,不如:
https://stackoverflow.com/questions/15420769
复制相似问题