Jan 04 2022 05:44 AM - edited Jan 04 2022 05:45 AM
I am using Invoke-Command to execute commands on remote computers. Throughout the course of the commands, I would like to generate logs locally on the remote computers. The commands that perform the actions I need work fine; however, the commands that I have to generate the logs (write-output) are not. Any help is appreciated.
$ScriptBlock = {
function Get-TimeStampLocal {
return "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date)
}
$Logfile = "c:\image\RemedComplete.txt"
#Check for and delete logfile.
If (Test-Path $Logfile){
Remove-Item $Logfile
} else {
}
Write-Output "$(Get-TimeStamp) Beginning application Remediation." >> $Logfile
< Commands that work >
< Commands that work >
< Commands that work >
Write-Output "$(Get-TimeStamp)Beginning System remediation for " >> $Logfile
< Commands that work >
< Commands that work >
< Commands that work >
Write-Output "$(Get-TimeStamp)Remediation Complete" >> $Logfile
}
Invoke-Command -ComputerName $vm -ScriptBlock $ScriptBlock -AsJob
Jan 11 2022 01:48 PM
Feb 03 2022 09:51 AM