2012-08-11 41 views
2
#VARIABLES 
$Source = Read-host "Please provide DIR location you wish to copy its contents from. 
ie. (UNC, Absolute paths, etc)" 
$Serverlist = Read-Host "Please provide the location of the server list. (UNC, Absolute 
paths, etc)" 
$Servers = Get-Content -Path $Serverlist 
#$Destination1 = \\$Server\c$\inetpub\wwwroot\' 
#$Destination2 = \\$Server\c$\wmpub\wmroot\' 
#EXECUTION 
$Servers | foreach-object  {        
    Copy-Item -Path $Source*.wsx -Destination $Server\c$\inetpub\wwwroot\ - 
force 
    Copy-Item -Path $Source*.nsc -Destination $Server\c$\wmpub\wmroot\ -force 
          } 
#EVENTVWR LOGGING 
$EventLog = New-Object System.Diagnostics.EventLog('Application') 
$EventLog.MachineName = "." 
$EventLog.Source = "Streaming Media Engineering" 
$EventLog.WriteEntry('Copy Successful',"Information", 200) 
#VIEWING OVERLOADS 
($myevent.WriteEntry).OverloadDefinitions 
Add-Type -AssemblyName System.Speech 
$synthesizer = New-Object -TypeName System.Speech.Synthesis.SpeechSynthesizer 
$synthesizer.Speak('Files have been moved over successfully...') 

我似乎無法得到腳本來讀取$服務器變量出$目的地1和$嘗試執行Copy-Item循環時的Destination2路徑。請幫忙花了幾天的時間...爲什麼不能Powershell複製項目來源定製到一個UNC路徑被稱爲變量見下面

+0

您收到的錯誤消息是什麼? – alroc 2012-08-12 11:23:21

+0

基本上沒有錯誤,但沒有預期的結果。 – user1592499 2012-08-23 17:21:39

+0

您的服務器列表在每個服務器之前包含\\,對嗎?你可以嘗試'Copy-Item -Path $ Source *。* -filter * .wsx -Destination $ Server \ c $ \ inetpub \ wwwroot \ -Force'並查看它是否有所作爲?那麼'Copy-Item -Path(join-path $ Source * .wsx)-Destination $ Server \ c $ \ inetpub \ wwwroot \ -Force'呢? – Joost 2013-03-29 13:52:21

回答

0

變量$服務器沒有設置在管道內。你必須把它從$服務器小號分配給當前管道對象:

# For PS2 and above: 
$Servers | ForEach-Object { 
$Server = $_ 
... 

# If you are sure that you will always use PS3 or above 
$Servers | ForEach-Object { 
$Server = $PSItem 
... 

希望這有助於。

P.S.我注意到這個問題是在2年前發佈的,現在我是一名嚴重挖掘者:P

相關問題