2014-08-27 3 views
0

도메인에 데이터베이스 서버가 없으며 작업 스케줄러가 손상되어 있으며이를 복구 할 시간이나 리소스가 없으므로 파일을 복사하기 위해 데이터베이스 서버에있는 두 x 째 스크립트를 활성화하는 타스크 스케줄러를 사용하여 다른 비 도메인 서 v에서 실행하는 스크립트. 데이터베이스 서버에서 스크립트를 수동으로 활성화하면 모든 것을 볼 수 있지만 작업을 수행하지만 원격으로 스크립트를 활성화하려고하면 실행되고 네트워크 드라이브 (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 
+0

마십시오 RU 드라이브 W가 아닌 다른 사용자와이 스크립트 : \? W : \가 아닌 UCN 경로 (\\ server \ share)를 사용할 수 있습니까? – Patrick

+0

Patrick이 말한 것처럼 credssp가 실제로 작동하면 직접 UNC 경로를 사용할 수 있어야합니다. 원격 ps 세션에서 실행되는 스크립트에서 "net use"권한으로 드라이브를 매핑 한 다음 해당 드라이브 문자로 복사하는 것은 일반적으로 수행하기 쉬운 해킹 이었지만 credssp는이를 불필요하게 만듭니다. 위임이 작동하면 UNC 경로를 사용할 때 "이중 홉"오류가 발생하지 않게됩니다. 또한이 작은 해킹으로 futz보다 태스크 스케줄러 엔진을 수정하는 것이 훨씬 더 많은 노력입니까? – red888

답변

0

문자를 드라이브 또는 "인터넷 사용 X : \ 내 \ UNC \ 공유"를하지 전체 UNC 경로를 사용하여 스크립트의 상단에 스크립트에서 드라이브를 올바르게 매핑합니다.

편집 :이 작업을 수행 할 경우 명시 적으로 net use 명령에 암호를 지정해야합니다 : net use x: \\my\share /user:mydom\myuser mypassword

관련 문제