Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #requires -version 3.0
- #remote computers must be running PowerShell 3.0
- $computers = "chi-dc01","chi-fp01","chi-dc04","chi-fp02"
- $cred = Get-Credential globomantics\administrator
- $eventlog = "Application"
- invoke-command -ScriptBlock {
- $log = get-wmiobject win32_nteventlogfile -filter "logfilename = '$using:eventlog'"
- $file = "{0}_{1}_{2}.evtx" -f (get-date -f "yyyyMMdd"),$log.CSName,$log.FileName.Replace(" ","")
- #map a PSDrive with credentials
- New-PSDrive -name B -PSProvider Filesystem -Root \\chi-fp01\it -Credential $using:cred | Out-Null
- #backup path must be something Windows can see like a UNC
- $backup = join-path (get-psdrive B).root $file
- write-host "Backing up to $backup" -ForegroundColor cyan
- $r = $log | Invoke-WmiMethod -Name BackupEventlog -ArgumentList $backup
- if ($r.returnValue -eq 0) {
- Get-Item $backup
- }
- else {
- Throw "Backup failed with returnvalue $($r.returnvalue)"
- }
- } -ComputerName $computers
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement