【发布时间】:2012-08-11 18:49:11
【问题描述】:
#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...')
在尝试执行 Copy-Item 循环时,我似乎无法让脚本读取 $Destination1 和 $Destination2 路径中的 $Server 变量。请帮助已经花了几天的时间......
【问题讨论】:
-
您收到的错误信息是什么?
-
基本没有错误但没有预期的结果。
-
您的服务器列表在每个服务器之前都包含 \\,对吧?你可以试试
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呢?
标签: variables copy powershell-2.0 unc copy-item