Skip to content

Instantly share code, notes, and snippets.

View manualbashing's full-sized avatar
:shipit:

Manuel Batsching manualbashing

:shipit:
View GitHub Profile
@manualbashing
manualbashing / get_windows_version.ps1
Last active June 7, 2019 11:02
Use WMI to get current Windows version
(gwmi Win32_Operatingsystem).Caption
@manualbashing
manualbashing / Add_path_to_environment_variable.ps1
Last active June 7, 2019 10:52
Working with environment variables
$ENV:PATH = $ENV:PATH + ";C:\Windows\System32"
@manualbashing
manualbashing / check_parameters.ps1
Last active June 7, 2019 10:51
Function that checks and validates its parameters
Function Foo
{
Param(
[ValidateSet("Tom","Dick","Jane")]
[String]$Name,
[ValidateRange(21,65)]
[Int]$Age,
[ValidateScript({Test-Path $_ -PathType 'Container'})]
Get-WmiObject win32_SystemEnclosure | select serialnumber
@manualbashing
manualbashing / uninstall_software.ps1
Last active June 7, 2019 10:47
Use WMI to uninstall programs and features on windows
gwmi Win32_Product -Filter 'Name like "%vCenter%"' | % { $_.uninstall() }
@manualbashing
manualbashing / vmkping-cheatsheet.sh
Last active June 7, 2019 10:40
Mini vmkping cheatsheet for network troubleshooting on ESXi
# Test Jumbo frames (with VLAN)
vmkping -d -s 8972 x.x.x.x
# Test Jumbo frames (without VLAN)
vmkping -d -s 8968 x.x.x.x
# Test interface
vmkping -I vmkX x.x.x.x
@manualbashing
manualbashing / Get-LoggedOnUser.ps1
Last active November 6, 2019 12:27
[Get Logged On User] Use WMI to find out, which user is logged in on a specific server.
foreach ($server in $serverNames)
{
Get-WMIObject Win32_Process -Filter 'name="explorer.exe"' -ComputerName $server -PipelineVariable pipedProcess -ErrorAction SilentlyContinue |
Select CSName, @{ Name='User'; Expression={$pipedProcess.GetOwner().User} } |
Write-Output -OutVariable +loggedOnUsers
}
@manualbashing
manualbashing / Delete-RecycleBin.ps1
Last active June 7, 2019 10:32
Empty the recycle bin on a Windows system
$Shell = New-Object -ComObject Shell.Application
$RecBin = $Shell.Namespace(0xA)
$RecBin.Items() | %{Remove-Item $_.Path -Recurse -Confirm:$false}
@manualbashing
manualbashing / Get-LocalAdmin.ps1
Last active June 7, 2019 10:30
Use cim to find local admin accounts on a Windows system.
Get-CimInstance -ClassName win32_group `
-Filter "Name LIKE 'admin%' AND Domain = '$env:COMPUTERNAME'" |
Get-CimAssociatedInstance -Association win32_groupuser |
Select-Object -ExpandProperty Name
@manualbashing
manualbashing / replaceUmlaut.ps1
Last active November 6, 2019 14:18
Replace Umlauts in #PowerShell with a replace function and regular expression
$replaceUmlaut = {
param ($Match)
$characterMap = New-Object System.Collections.Hashtable
$characterMap.ä = 'ae'
$characterMap.ö = 'oe'
$characterMap.ü = 'ue'
$characterMap.ß = 'ss'
$characterMap.Ä = 'Ae'
$characterMap.Ü = 'Ue'
$characterMap.Ö = 'Oe'