I am a beginner at Powershell. I have a script that I’m using to copy a file to a list of computers.
The problem I’m running into is that when I add a string representing a computer name to the list ends up being a number that is the length of the string.
#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 + "\C$\keeper"
#copies the file over to target machine
new-Item -Path "$name" -ItemType Directory -Force
Copy-Item -path $Source -Destination $name
}
#if ping fails, log which workstation and that workstation’s IP in a new CSV.
else
{
write-host “false”, $line.Name
$items.add($line.Name)
}
} #exports array of workstations that were unreachable for manual processing at a later date.
$items | Export-Csv -NoTypeInformation -Path $Output
Where the last Write-Host it returns the actual name of the computer, but then on the next line I get the length of the string. How can I fix this?
When you post code or sample data or console output please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
Thanks in advance
Michael Kerrick
IT Manager Holy Family Parish and School
M: 425 786-4318
D: 425 947-7859
When sending to a large distribution list, please put the list on the BCC line.
This will prevent people from Replying All
It will alleviate extra email flooding into our Inboxes.