Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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