Hi, just another noob here.
Background; When we have an incident, we need to collect certain log files from several servers.
They are stored in the servers’ log depository, which cointains logs for a lot more than what we need.
I wrote and tested the script at home in the latest PS version and am having some trouble getting it to work over the network at work, and in PS2.
Seems I’ve gotten the paths to work, but it looks like it ignores my exlusions. I used -notin at home, but that didn’t work in PS2.
'Copying files from CR...'
$servers = @()
$servers = (
"Servername",
"Servername2"
)
##set destination folder, makes it if not already exsist
$destServer = @()
$destServer = ( "Destinationserver")
$destinationFolder = "\\" + $destServer + "d$\Logs\"
if (!(Test-Path -path $destinationFolder)) {New-Item $destinationFolder -Type Directory}
##Exluded directories, separate by comma
$excludes = "huge", "list", "ofExcluded", "folders"
Foreach ($srcServer in $servers){
Write-Host "------------------ " $srcServer "--------------------" -ForegroundColor Yellow
#Get items, where the name does not include excluded directories, copies them, keeping filestructure, only copies .log
$logFiles = "\\" + $srcServer + "\d$\Logs\"
Get-ChildItem $logFiles |
Where-Object{$excludes -NotContains $_.Name}|
Copy-Item -Destination $destinationfolder -Recurse -Force -Filter *.log
Write-Host "File Copy complete"
}
Do you guys have any tips for me?