Skip to content

PowerShell Functions

Nmap Function

  1. Open your $PROFILE for editing with

  2. Set Notepad alias to use norepad++ instead of regular norepad

    ## Aliases
    Set-Alias -Name notepad -Value "C:\Program Files\Notepad++\notepad++.exe"
    
  3. Add it in the $PROFILE to load each time.

    notepad $PROFILE
    
  4. Then add the below function outside any code blocks . It’s a standalone function

function nmap {

$IP=$args[0]
$port=$args[1]

Write-Output "Selected IP Address = $IP and Port Number = $port" 
Write-Output "Checking if port is open Please Wait..."

$Result = Test-NetConnection $IP -Port $port -InformationLevel "Detailed"

if ($Result.TcpTestSucceeded -eq $true) {
    Write-Output "Port $($Result.RemotePort) at $($Result.RemoteAddress) is Open"
} else {
    Write-Output "Port $($Result.RemotePort) at $($Result.RemoteAddress) is Closed"
}


}
  1. Reload/Restart your PowerShell and test it .

Example

nmap 10.2.32.60 2087
Selected IP Address = 10.2.32.60 and Port Number = 2087
Checking if port is open Please Wait...
Port 2087 at 10.2.32.60 is Open

Dig custom function using Resolve-DnsName utility of PowerShell

function dig {
param (
[string]$type,
[string]$domain

)

Resolve-DnsName -Type $type $domain

}
  • Usage
dig NS cpanel.net
  • Possible options for type. Unfortunately not all of them give trustworthy results. Stick to regular ones like A, MX , NS
A_AAAA, A, NS, MD, MF, CNAME, SOA, MB, MG, 
MR, NULL, WKS, PTR, HINFO, MINFO, MX, TXT, 
RP, AFSDB, X25, ISDN, RT, AAAA, SRV, DNAME, 
OPT, DS, RRSIG, NSEC, DNSKEY, DHCID, NSEC3, 
NSEC3PARAM, ANY, ALL, WINS"

cPanel verify license function

  • Verify License via PowerShell. Simply opens up new tab in chrome with the license website with post request
# Verify cPanel License
function verify {
$IP=$args[0]
start chrome https://verify.cpanel.net/app/verify?ip=$IP

}
  • Usage
verify 184.94.197.2

Ipinfo Function

  • Checking IP address details
function ipinfo {
param (
[string]$ipaddress
)

curl https://ipinfo.io/$ipaddress

}
  • Example Output
    PS C:\Users\vladimir.ivanov> ipinfo 184.94.197.2
    {
      "ip": "184.94.197.2",
      "hostname": "hou-2.nat.cptxoffice.net",
      "city": "South Houston",
      "region": "Texas",
      "country": "US",
      "loc": "29.6630,-95.2355",
      "org": "AS33522 cPanel, LLC.",
      "postal": "77587",
      "timezone": "America/Chicago",
      "readme": "https://ipinfo.io/missingauth"
    }
    

Command cheat sheets from cheat.sh. Wrapper function PowerShell

function cheat {
    param ( 
    [string]$command)

    curl    https://cheat.sh/$command

}

Get WMI Object

  • BIOS DATA
    Get-WmiObject -Class Win32_BIOS | Format-List -Property *