Skip to content

Instantly share code, notes, and snippets.

View SweetAsNZ's full-sized avatar
🏠

Tim West SweetAsNZ

🏠
View GitHub Profile
@SweetAsNZ
SweetAsNZ / Get-Uptime.ps1
Created February 7, 2022 03:10
Get Server/PC Uptime
function Get-Uptime {
$OS = (Get-WmiObject Win32_OperatingSystem)
$UpTime = (Get-Date) - ($OS.ConvertToDateTime($OS.LastBootUpTime))
$Display = "" + $Uptime.Days + "days / " + $Uptime.Hours + "hours / " + $Uptime.Minutes + "minutes"
Write-Output $Display
}
@SweetAsNZ
SweetAsNZ / OS-Info.ps1
Created February 7, 2022 03:11
Get OS Info Like Name Build Number Version
function OS-Info {
[CmdletBinding()]
$OSInfo = Get-CimInstance Win32_OperatingSystem | Select-Object -property @{Name = "OS"; Expression = {$_.Caption} },Version,ServicePackMajorVersion,OSArchitecture, `
@{Name = "Hostname"; Expression = {$_.CSName} },WindowsDirectory
$OSName = ($OSInfo | Select-Object OS).OS # So we can use $OS
$OSBuild = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' �Name CurrentBuild).CurrentBuild
$BuildNum = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' �Name UBR).UBR
$OSVersion = $OSBuild + "." + $BuildNum
@SweetAsNZ
SweetAsNZ / Is-Admin.ps1
Created February 7, 2022 03:19
Am I Running As Administrator
function Is-Admin {
([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
# Use Like this:
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator") ) {
Write-Output "This script needs to be run as Admin"
Break
}
@SweetAsNZ
SweetAsNZ / Get-NetworkStuff.ps1
Created February 7, 2022 04:21
Get's Network Connection Info of Local Machine SYN ESTablished LIStening & the Status of a Port
function Syn {
Write-Host -Foregroundcolor Green "What is being blocked by a FW, Routing or other network issue etc...?"
cmd /c netstat -ano | findstr /i "syn"
}
function List {
Write-Host -Foregroundcolor Green "Am I Listening on a Port?"
cmd /c netstat -ano | findstr /i "List"
}
function Port-Status {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[string]$Port
)
Get-NetTCPConnection -LocalPort $Port
@SweetAsNZ
SweetAsNZ / Get-AllLAPSPw.ps1
Last active February 7, 2022 04:49
Get All Local Admin Password Solution Passwords
function Get-AllLAPSPw{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string]$ComputerName
)
Write-Host "if you can do this as a User you have security issues see here `r`n
https://techcommunity.microsoft.com/t5/itops-talk-blog/step-by-step-guide-how-to-configure-microsoft-local/ba-p/2806185 `r`n
@SweetAsNZ
SweetAsNZ / Get-LAPSPw
Last active February 7, 2022 04:49
Get Local Admin Password Solution Password
function Get-LAPSPw{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true,HelpMessage="Server or PC Name?")]
[ValidateNotNullOrEmpty()]
[string]$Device
)
Write-Host "if you can do this as a User you have security issues see here `r`n
@SweetAsNZ
SweetAsNZ / Get-UsersOnAllServers.ps1
Last active February 7, 2022 07:48
Get Users On All Servers RDP Citrix ICA & Console
function Get-UsersOnAllServers{
$Servers = (Get-ADComputer -Filter * -Properties Name,OperatingSystem,Enabled -ResultSetSize 1000000 |
Where-Object {$_.OperatingSystem -like "Windows Server*"} | Sort-Object Name).Name
foreach ($Item in $Servers)
{
Write-Host "################"
$Item # Server Name
qwinsta /server:$Item
@SweetAsNZ
SweetAsNZ / Get-UsersOnServer.ps1
Created February 7, 2022 07:50
Get Users On Server RDP Citrix ICA & Console
function Get-UsersOnServer{
#Get-RDPUsers -ComputerName SERVER
# Gets RDP & Citrix & Local Users e.g. rdp-tcp#77, console, ica-cgp#72
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string]$ComputerName
@SweetAsNZ
SweetAsNZ / Get-IISVersion.ps1
Created February 7, 2022 08:01
Get IIS Version
function Get-IISVersion{
Get-ItemProperty -Path registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp\ | Select-Object
}