Check if Port is Open
$socket = new-object Net.Sockets.TcpClient
$socket.Connect($IPAddress,$Port)
$socket.Connected
Details
Just supply an IP Address and Port number and it will return true or false, based on if it was able to connect.
  
Check Remote Desktop Protocol Port
Test-NetConnection -Computer $Server -CommonTCPPort RDP
Details
Using the Test-NetConnection cmdlet you can confirm that a server is reachable via the standard RDP port of 3389.

Example
PS C:\> $Server = 'AD01'
>> Test-NetConnection -Computer $Server -CommonTCPPort RDP



ComputerName     : DC01
RemoteAddress    : 10.10.5.12
RemotePort       : 3389
InterfaceAlias   : vEthernet (External (NIC))
SourceAddress    : 10.10.5.200
TcpTestSucceeded : True


  
Determine if Hyper-Threading is enabled
Function Check-HyperThreading($ComputerName){
    # Get the Processor information for the computer
    $Proc = Get-WMIObject Win32_Processor -ComputerName $ComputerName
 
    # Determine if hyper-threading is enabled
    $CPUCount = @($Proc).count
    $NumberOfLogicalProcessors = $($Proc | measure-object -Property NumberOfLogicalProcessors -sum).Sum
    $NumberOfCores = $($Proc | measure-object -Property NumberOfCores -sum).Sum
    
    # Output the results as a PS object
    [pscustomobject]@{
        Computer = $ComputerName
        CPUCount = $CPUCount
        NumberOfLogicalProcessors  = $NumberOfLogicalProcessors
        NumberOfCores = $NumberOfCores
        HyperThreading = $($NumberOfLogicalProcessors -gt $NumberOfCores)
 
    }

}
Details
This function will return the process information from a local or remote computer and determine if HyperThreading is enabled. If the number of logical processors is greater than physical processors (cores), then hyperthreading is enabled and the function returns True for HyperThreading.

Example
PS C:\> Function Check-HyperThreading($ComputerName){
>>     # Get the Processor information for the computer
>>     $Proc = Get-WMIObject Win32_Processor -ComputerName $ComputerName
>>     # Determine if hyper-threading is enabled
>>     $CPUCount = @($Proc).count
>>     $NumberOfLogicalProcessors = $($Proc | measure-object -Property NumberOfLogicalProcessors -sum).Sum
>>     $NumberOfCores = $($Proc | measure-object -Property NumberOfCores -sum).Sum
>>     # Output the results as a PS object
>>     [pscustomobject]@{
>>         Computer = $ComputerName
>>         CPUCount = $CPUCount
>>         NumberOfLogicalProcessors  = $NumberOfLogicalProcessors
>>         NumberOfCores = $NumberOfCores
>>         HyperThreading = $($NumberOfLogicalProcessors -gt $NumberOfCores)
>>     }
>> }
>> 
>> Check-HyperThreading -ComputerName $env:COMPUTERNAME



Computer                  : MAT-F0CXE4G
CPUCount                  : 1
NumberOfLogicalProcessors : 4
NumberOfCores             : 2
HyperThreading            : True


  
Get External IP Address
Invoke-RestMethod 'https://api.ipify.org?format=json' | Select-Object -ExpandProperty IP
Details
Uses the ipify API to return your external IP address

Example
PS C:\> Invoke-RestMethod 'https://api.ipify.org?format=json' | Select-Object -ExpandProperty IP

72.30.35.10
  |  
Get Host Name from IP
[System.Net.Dns]::GetHostbyAddress($IPAddress) 
Details
Get the host name from an IP address

Example
PS C:\> $IPAddress = "8.8.8.8"
>> [System.Net.Dns]::GetHostbyAddress($IPAddress)


HostName                       Aliases AddressList
--------                       ------- -----------
google-public-dns-a.google.com {}      {8.8.8.8}

  |  
Get IP from Host Name
[System.Net.Dns]::GetHostAddresses($ServerName)
Details
Get the IP address based on the host name

Example
PS C:\> $ServerName = 'DC01'
>> [System.Net.Dns]::GetHostAddresses($ServerName)



Address            : 167840266
AddressFamily      : InterNetwork
ScopeId            :
IsIPv6Multicast    : False
IsIPv6LinkLocal    : False
IsIPv6SiteLocal    : False
IsIPv6Teredo       : False
IsIPv4MappedToIPv6 : False
IPAddressToString  : 10.10.1.10


  |  
Get Memory Utilization Percentage
Get-WmiObject Win32_OperatingSystem -ComputerName $computer | Select @{Label = "Computer"; Expression = {$computer}},
    @{Label = "MemoryUsage"; Expression = {100 - [math]::Round(($_.FreePhysicalMemory/$_.TotalVisibleMemorySize)*100,0)}}
Details
Returns the total percentage of memory ultization on your local or remote system.

Example
PS C:\> $computer = 'localhost'
>> Get-WmiObject Win32_OperatingSystem -ComputerName $computer | Select @{Label = "Computer"; Expression = {$computer}},
>>     @{Label = "MemoryUsage"; Expression = {100 - [math]::Round(($_.FreePhysicalMemory/$_.TotalVisibleMemorySize)*100,0)}}


Computer  MemoryUsage
--------  -----------
localhost          69

  |  |  
Get Processor Utilization Percentage
Get-WmiObject win32_processor -ComputerName $computer | Measure-Object -property LoadPercentage -Average | 
    Select @{Label = "Computer"; Expression = {$computer}},@{Label = "CpuUsage"; Expression = {$_.Average}}
Details
Returns the total percentage of process ultization on your local or remote system.

Example
PS C:\> $computer = 'localhost'
>> Get-WmiObject win32_processor -ComputerName $computer | Measure-Object -property LoadPercentage -Average |
>>     Select @{Label = "Computer"; Expression = {$computer}},@{Label = "CpuUsage"; Expression = {$_.Average}}


Computer  CpuUsage
--------  --------
localhost       15

  |  |  
Get Your Local IP Address
Get-NetIPAddress
Details
Get-NetIPAddress returns the all the local IP addresses of the machine it is run on.

Example
PS C:\> Get-NetIPAddress


IPAddress         : 10.10.1.10
InterfaceIndex    : 12
InterfaceAlias    : Ethernet
AddressFamily     : IPv4
Type              : Unicast
PrefixLength      : 24
PrefixOrigin      : Manual
SuffixOrigin      : Manual
AddressState      : Preferred
ValidLifetime     : Infinite ([TimeSpan]::MaxValue)
PreferredLifetime : Infinite ([TimeSpan]::MaxValue)
SkipAsSource      : False
PolicyStore       : ActiveStore

  |  
Query Remote Registry for Key Value
# Open the specified Registry Hive on a remote machine specified. LocalMachine = HKLM / CurrentUser = HKCU
$computer = 'localhost'
$w32reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine',$computer)

# Open the specific registry key (exclude hive from path)
$keypath = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI'
$SubKey = $w32reg.OpenSubKey($keypath)

# Return data for a specific value
$SubKey.GetValue('LastLoggedOnUser')

# List all values
$SubKey.GetValueNames()

# Return data for all values to hashtable
$AllValues = @{}
$SubKey.GetValueNames() | ForEach-Object{
    $AllValues.Add($_,$SubKey.GetValue($_))
}
$AllValues
Details
This command will create a connection to a remote machine and return the specified registry values. It also shows how you can return all values and data for a key.

  |  
Reboot remote computer and wait

This script that will send a reboot command to a remote computer. It will then monitor for it to go offline and then come back online. Optionally, you can have it monitor for a service to return to running.

# The remote computer to reboot
$computer = 'YourComputer'
# the name of a service to check for after reboot
$Service  = 'WinRM'

# send reboot command to remote computer
Restart-Computer -ComputerName $computer -Force -ErrorAction Stop

# ping computer every second until it goes offline
do{
    $test = Test-Connection -ComputerName $Computer -Count 1 -Quiet
    Start-Sleep -s 1
}while($test -ne $false)

# ping computer every 10 seconds until it comes back online
while($test -eq $false){
    $test = Test-Connection -ComputerName $Computer -Count 1 -Quiet
    Start-Sleep -s 10
}

# wait for service to show running
if(-not [string]::IsNullOrEmpty($Service)){
    do{
        $test = Get-Service -Name  -ComputerName $Computer -ErrorAction SilentlyContinue
        Start-Sleep -s 10
    }while($test.Status -ne 'Running')
}
  |