Hi,
I'm trying to write a script that copies a file to the temp folder of multiple remove computers across the network. I want to to look in a CVS file for the host name, Ping the host name, If it gets a response then copies the file. If not then writes it out to another CSV file so I can copy it at a later date. When i run the below I get the error saying:
else : The term 'else' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
This is the script im running:
$csv = Import-Csv "C:\temp\computers.csv"
$Source = "\\Server1\FileToCopy.exe"
$dest = "C:\temp\"
$Output = "C:\temp\missingworkstations.csv"
$items = @()
reads .csv for workstation NAME.
foreach ($line in $csv)
{
pings each Host. If true, Copy file.
if (Test-Connection $line.Name -count 1 -quiet)
{
write-Host "true", $line.Name
$name = "\\" + $line.Name
#copies the file over to target machine
Copy-Item -path $Source -Destination $dest
if ping fails, log which workstation and that workstation's IP in a new CSV.
else
{
write-host "false" $line.Name $line.IP
$items += New-Object psobject -Property @{IP=$line.IP; Name=$line.Name}
}
}
exports array of workstations that were unreachable for manual processing at a later date.
$items | Export-Csv -NoTypeInformation -Path $Output}