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

I can't seem to get the script to Read the $Server variable out in the $Destination1 and $Destination2 paths when trying to do a Copy-Item loop. Please help have spent a couple days on this...

  • What is the error message you receive? – alroc Aug 12 '12 at 11:23
  • Basically no error but no expected results. – user1592499 Aug 23 '12 at 17:21
  • Your serverlist contains \\ before each server, right? Can you try `Copy-Item -Path $Source*.* -filter *.wsx -Destination $Server\c$\inetpub\wwwroot\ -Force` and see if it makes a difference? What about `Copy-Item -Path (join-path $Source *.wsx) -Destination $Server\c$\inetpub\wwwroot\ -Force`? – Joost Mar 29 '13 at 13:52

1 Answers1

0

variable $Server is not set inside pipeline. You have to assign it to the current pipeline object from $Servers:

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

Hope that this helps.

P.S. I've notice that this question was posted 2 years ago, I'm a grave digger now :P

ALIENQuake
  • 520
  • 3
  • 12
  • 28