我有一个数据库服务器不在域中,该任务计划程序已损坏,我没有时间或资源来修复它,所以我创建了一个脚本,该脚本使用任务计划程序从另一个非域服务器运行,该脚本激活位于数据库服务器上的第二个脚本以复制文件。在数据库服务器上,手动激活的脚本可以看到所有内容并执行其工作,但是当我尝试远程激活脚本时,它会运行并查看除网络驱动器(W :)之外的所有内容。我正在使用连接好的脚本中的credssp见下面 - 问题如何让脚本看到远程服务器上的网络共享远程计算机上的Powershell激活脚本 - 远程计算机无法看到网络共享
-------------脚本A-- -------------------------------------------
$username = "Administrator"
$computerA = "<addressA>"
$computerB = "<addressB>"
$PwdLocation = "c:\test\password.txt"
#enable-wsmancredssp -role client -delegatecomputer $computerB
$password = Get-Content $PwdLocation | ConvertTo-SecureString
$credential = new-object -typename System.Management.Automation.PSCredential - argumentlist $username,$password
Invoke-Command -ComputerName $computerB -ScriptBlock {\\<remote server>\test\delete.ps1} -ArgumentList $ComputerA -Credential $credential
exit
----------------------远程脚本B ------------------------- --------------
Function mailer {
$recipients = "<names>"
$smtp = "smtp.org"
$emailTo = $recipients
$emailFrom = "[email protected]"
$smtpserver="smtp.org"
$smtp=New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $message)
}
Function StopEverything {
$subject = "Stopped Script Delete.PS1 becuase of no connection"
$message = ""
for($i=0;$i -le $tot-1;$i++)
{
$path = $bfs[$i]
if (Exists-Dir($path))
{
$message += [string]::concat($path, " Connected`n")
}
else
{
$message += [string]::concat($path, " Cannot Connect`n")
}
}
mailer
Exit
}
Function Exists-Dir($path) {
if ([IO.Directory]::Exists($path))
{
return $true;
}
else
{
return $false;
}
}
$ScriptStart = (Get-Date)
[array]$bfs = "F:\Backups\NetPerfMon","F:\Backups\NetPerfMon_Aux","W:\Backups\NetPerfMon_Aux","W:\Backups\NetPerfMon"
$tot = $bfs.count
for($i=0;$i -le $tot-1;$i++)
{
$path = $bfs[$i]
if (Exists-Dir($path))
{
$message += [string]::concat($path, " Connected`n")
$subject = "Start Script Delete.PS1 on " + $ScriptStart
}
else
{
$message += [string]::concat($path, " Cannot Connect`n")
StopEverything
}
}
$message += " "
$message +=
mailer
$limit = (Get-Date).AddDays(-7)
$limit1 = (Get-Date).AddDays(-14)
$limit2 = (Get-Date).AddDays(-1)
$FB = "F:\Backups\NetPerfMon"
$FBAux = "F:\Backups\NetPerfMon_Aux"
$WBAux = "W:\Backups\NetPerfMon_Aux"
$WBBak = "W:\Backups\NetPerfMon"
Get-ChildItem -Path $FB | Where-Object { !$_.PSIsContainer -and $_.LastWriteTime - lt $limit } | Remove-Item -Force | OUT-NULL #Remove items greater than 7 days
Get-ChildItem -Path $FBAux | Where-Object { !$_.PSIsContainer -and $_.LastWriteTime -lt $limit } | Remove-Item -Force | OUT-NULL #Remove items greater than 7 days
Get-ChildItem -Path $WBBak | Where-Object { !$_.PSIsContainer -and $_.LastWriteTime -lt $limit1} | Remove-Item -Force | OUT-NULL #Remove items greater than 14 days
Get-ChildItem -Path $FB | where {$_.extension -eq ".bak"} | Where-Object { !$_.PSIsContainer -and $_.LastWriteTime -gt $limit2} | Copy-Item -destination $WBBak | OUT- NULL #Copy items within 1 day that have extension .bak
Get-ChildItem -Path $FBAux | where {$_.extension -eq ".bak"} | Where-Object { !$_.PSIsContainer -and $_.LastWriteTime -gt $limit2} | Copy-Item -destination $WBAux | OUT- NULL #Copy items within 1 day that have extension .bak
$ScriptEnd = (Get-Date)
$RunTime = New-Timespan -Start $ScriptStart -End $ScriptEnd
"Elapsed Time: {0}:{1}:{2}" -f $RunTime.Hours,$Runtime.Minutes,$RunTime.Seconds
$subject = "Stop Script Delete.PS1 on " + $ScriptEnd
$message = ""
$message += " "
$message += "Time to completion: {0}:{1}:{2}" -f $RunTime.Hours,$Runtime.Minutes,$RunTime.Seconds
mailer
你る这个剧本与没有驱动器W上的其他用户:\?你可以使用UCN路径(\\ server \ share)而不是W:\? – Patrick 2014-08-27 18:17:04
像帕特里克说,如果credssp实际上工作,你应该能够使用直接的UNC路径。在远程ps会话中运行的脚本中,将一个驱动器的“net use”映射到映射中,然后复制到该驱动器盘符是一种常见的,俗套的破解方法,但是,credssp使得这不必要。如果委派工作正常,则避免使用UNC路径时出现“双跳”错误。另外,仅仅修复任务调度引擎比在这个小小的黑客中解决问题真的要多得多吗? – red888 2014-08-27 20:44:31