I'm writing a function to collect logs for analysis.
I'm trying to use variables to keep it as tight as possible, but for some reason the function won't create, moans about brackets and variables.
Any assistance would be appreciated.
FUNCTION GetLogs ($CompName)
{
$LOGS = "CcmExec.log,Scheduler.log,WUAHandler.log"
$CCMPath = "C$\Windows\CCM\Logs"
$Target = "C:\Temp\Logs"
foreach (file$ IN $LOGS ) {file$ = Copy-Item \\$CompName\$CCMPath\$LOGS $Target\$CompName-$LOGS}
}
That code won't work.
I think you meant to define an array in $LOGS, but you are actually defining just one String.
Try this: $LOGS = "CcmExec.log", "Scheduler.log", "WUAHandler.log"
Also it looks like you are trying to copy those 3 Files somewhere, but what you are doing is setting the var $file each turn to something else. The statement $file In $LOGS
means that the variable $file will be "CcmExec.log" the first time of the loop, then "Scheduler.log" and so on.
So what I think you want to do is this:
Function GetLogs ($CompName) {
$LOGS = "CcmExec.log","Scheduler.log","WUAHandler.log"
$CCMPath = "C$\Windows\CCM\Logs"
$Target = "C:\Temp\Logs"
foreach ($file In $LOGS ) {
Copy-Item -Path \\$CompName\$CCMPath\$file -Destination $Target\$CompName-$file
}
}
I also removed some typos.
Is that about right?
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments