https://github.com/ramsailopal/powershell
Simple Powershell scripts
https://github.com/ramsailopal/powershell
powershell
Last synced: 9 months ago
JSON representation
Simple Powershell scripts
- Host: GitHub
- URL: https://github.com/ramsailopal/powershell
- Owner: RamSailopal
- Created: 2022-11-03T13:16:04.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-11-29T11:43:03.000Z (over 3 years ago)
- Last Synced: 2025-05-21T05:37:13.558Z (11 months ago)
- Topics: powershell
- Language: PowerShell
- Homepage:
- Size: 23.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Powershell
Simple Powershell examples
# Adding script to shell as function when Powershell loads (.bashrc/.profile equivalent)
New-Item $profile -Type File -Force
Navigate to the location of the created file and then create functions i.e.
Function grep {
& 'C:\Documents and Settings\rsailopal\Documents\Powershell1\grep1.ps1'
}
# Additional Commands
**List installed software:**
Get-WMIObject -Class Win32_Product | Select-Object -Property Name
**Parse logs:**
Get-Eventlog -List
Get a list of the log types
Get-WinEvent -Logname Application -MaxEvents 5
Get the last 5 application errors
**Remote Connections**
Enable-PSRemoting -Force
Enable remote connection to machine
$hostnme = hostname
Invoke-Command -ComputerName $hostnme -ScriptBlock { hostname }
Execute the command **hostname** on the localhost
$hostnme = hostname
$s = New-PSSession -ComputerName $hostnme
Invoke-Command -Session $s { hostname }
Execute the same command creating a persistent session (variables created remotely are persisted across Invoke-Command calls)
**Environmental Variables**
Get-ChildItem -Path Env:
Get environmental variables.
**Memory usage**
systeminfo | ForEach-Object { If ( $_ -like "*Memory*") { Write-Host $_ } }
**CPU utlisation**
Get-WmiObject Win32_Processor | Measure-Object -Property LoadPercentage -Average | Select Average