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...')

尝试执行 Copy-Item 循环时,我似乎无法让脚本读取 $Destination1 和 $Destination2 路径中的 $Server 变量。请帮助已经花了几天的时间...

4

1 回答 1

0

变量 $Server 未在管道内设置。您必须将其分配给 $Server s中的当前管道对象:

# 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
...

希望这会有所帮助。

PS我注意到这个问题是2年前发布的,我现在是一个掘墓人:P

于 2015-07-17T11:24:48.287 回答