Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Change below code run in one attempt.

$
0
0

My code at the moments runs through the security permissions checks on a computer and places the results in a specified folder. But how do I change it from looking at one folder to looking at 10+ servers and then placing the results in an output file such based on the server it just run e.g. 

server1.output.csv

server2output.csv

I want the outputfiles to all be placed in one location on the same server.

# This is the directory you want to copy to the computer (IE. c:\folder_to_be_copied)

$source = "C:\Users\munjanga\Desktop\Execute\Testing.ps1"

# On the destination computer, where do you want the folder to be copied?

$dest = "c$"

Get-Content -Path "C:\Users\munjanga\Desktop\Execute\server.txt" {

if (test-Connection -ComputerName $Computername. -quiet) {

try {

Copy-Item -Source $source -Destination (Join-Path -Path "\\$_" -ChildPath $dest) -Recurse -ErrorAction Stop

} catch {

Write-Warning "Copy to $_ failed"

}

} else {

"$_ is not online"

}

}


Viewing all articles
Browse latest Browse all 6937

Trending Articles