Skip to content

Instantly share code, notes, and snippets.

@jimfrenette
Last active February 19, 2017 17:26
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 jimfrenette/3182daec188a9937800647632fd3a8c4 to your computer and use it in GitHub Desktop.
Save jimfrenette/3182daec188a9937800647632fd3a8c4 to your computer and use it in GitHub Desktop.
PowerShell Script with menu and utility functions to demonstrate env: and other system variables
function ListProcess
{
Get-Process | Group-Object Company | Sort-Object Count -Descending
}
function ListEnvVars
{
Get-ChildItem env:
}
function ListEventLog
{
Get-EventLog -List
}
function Cleanup
{
Write-Host "Delete files from $env:temp older than 24 hours"
Get-ChildItem -path $env:temp | where {$_.Lastwritetime -lt (date).addhours(-24)} | remove-item
<# Clear-RecycleBin #>
$Shell = New-Object -ComObject Shell.Application
$RecBin = $Shell.Namespace(0xA)
$RecBin.Items() | %{Remove-Item $_.Path -Recurse -Confirm:$false}
}
function ShowMenu
{
param (
[string]$Title = 'Menu'
)
Write-Host "====== $env:USERPROFILE - $Title ======="
Write-Host "1: List Running Processes"
Write-Host "2: List Environment Variables"
Write-Host "3: List Event Log"
Write-Host "4: Clean Temp and Recycle Bin"
Write-Host "q: quit"
}
do
{
ShowMenu
$input = Read-Host "Please make a selection"
switch ($input)
{
'1' {
Clear-Host
ListProcess
}
'2' {
Clear-Host
ListEnvVars
}
'3' {
Clear-Host
ListEventLog
}
'4' {
Clear-Host
Cleanup
}
'q' {
return
}
}
pause
}
until ($input -eq 'q')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment