While running the following snippet in powershell, I see an error(an error occurred while creating the pipeline). can anyone help me here?
# This file contains the list of servers you want to copy files/folders to
$computers = gc "C:\folder1\sub1\server.txt"
# This is the file/folder(s) you want to copy to the servers in the $computer variable
$source = "\\usa-chicago1\c$\Program Files\"
# The destination location you want the file/folder(s) to be copied to
$destination = "c$\July\"
$username = 'harry'
$password = 'hqwtrey$1'
$secpw = ConvertTo-SecureString $password -AsPlainText -Force
$cred = New-Object Management.Automation.PSCredential ($username, $secpw)
foreach ($computer in $computers) {
if ((Test-Path -Path \\$computer\$destination)) {
Write-Output "INSIDE IF BLOCK"
#Copy-Item $source -Destination \\$computer\$destination -Recurse
Invoke-Command -Computername $computer -ScriptBlock { & '\\$computer\July\' --service install --config-directory '\\$computer\July\conf' }
Invoke-Command -Computername $computer -ScriptBlock { & net start telegraf }
}
else {
Write-Output $computer
New-Item -Path "\\$computer\july\" -ItemType Directory
Write-Output \\$computer\$destination
Copy-Item $source -Destination \\$computer\$destination -Recurse
}
}