Skip to content

Instantly share code, notes, and snippets.

@joswr1ght
Last active March 17, 2024 01:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joswr1ght/d8e9c63b8a1c4df84b6dfcb3c227a5df to your computer and use it in GitHub Desktop.
Save joswr1ght/d8e9c63b8a1c4df84b6dfcb3c227a5df to your computer and use it in GitHub Desktop.
PowerShell script to copy event logs from one or more remote systems to the local file system
# https://chat.openai.com/share/6d96527b-288d-45a9-8eb4-e8b43d52486a
# Input parameters
param (
[Parameter(Mandatory=$true)]
[string]$inputFile,
[Parameter(Mandatory=$true)]
[System.Management.Automation.PSCredential]$Credential
)
# Read hostnames from input file
$hostnames = Get-Content $inputFile
foreach ($hostname in $hostnames) {
Write-Host "Copying event logs files from $hostname"
# Create directory for this hostname
New-Item -ItemType directory -Path ".\Logs\$hostname" -ErrorAction SilentlyContinue | Out-Null
# Copy log files from remote host to local directory
Copy-Item -Path "\\$hostname\C$\Windows\System32\winevt\Logs\" -Destination ".\Logs\$hostname" -Recurse -Force | Out-Null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment