Skip to content

Instantly share code, notes, and snippets.

@acast15
Created February 8, 2021 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acast15/bdb8d3a3dad64a49d448e11fd545fe75 to your computer and use it in GitHub Desktop.
Save acast15/bdb8d3a3dad64a49d448e11fd545fe75 to your computer and use it in GitHub Desktop.
Running External PS1
## Displays a Message Box
[System.Windows.Forms.Messagebox]::Show('Checking App Log Files Complete.','App Logs','OK','Information')
## Define the log file
$logDir = 'c:\temp'
$logFile = "$logDir\AppLog_$(Get-Date -format 'yyyy-mm-dd_hh-mm-ss-tt').xml"
## Get the ten latest application log events and export as an XML file
Get-WinEvent -LogName application -MaxEvents 10 | Out-File $logFile -Force
## Get the script's path
if ($MyInvocation.MyCommand.CommandType -eq "ExternalScript")
{ $ScriptPath = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition }
else
{ $ScriptPath = Split-Path -Parent -Path ([Environment]::GetCommandLineArgs()[0])
if (!$ScriptPath){ $ScriptPath = "." }}
try{
## Call AppLogsComplete.ps1
& $ScriptPath"\AppLogsComplete.ps1"
}catch{
Write-Host $_.ScriptStackTrace
Pause
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment