Last active
January 30, 2026 01:34
-
-
Save SweetAsNZ/195cb116076e38846f5635f3aad282f5 to your computer and use it in GitHub Desktop.
Multiple Functions to get various Windows system information. Get-DNSServers, Get-DNS, Get-Gateway, Get-GW, Get-IP, Get-SubnetMask, Get-MACAddress, Get-MAC, Get-UpTime, Get-DiskSpace, Get-MappedDrives, Test-Gateway, Test-GW, Get-FreeSpace, Get-Proxy, Show-Proxy, Get-Routes, Touch, Get-MyExternalIP, Get-NetBIOS, Set-NetBIOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| .SYNOPSIS | |
| A collection of functions to retrieve various Windows system information such as DNS servers, gateway, IP addresses, subnet masks, MAC addresses, uptime, disk space, mapped drives, and more. | |
| .DESCRIPTION | |
| This script contains multiple functions that can be used to gather different pieces of information about a Windows | |
| system. Each function is designed to perform a specific task and can be called independently. | |
| .PARAMETER | |
| N/A | |
| .EXAMPLE | |
| Get-DNSServers | |
| Get-Gateway | |
| Get-GW | |
| Get-IP | |
| Get-SubnetMask -All | |
| Get-MAC | |
| Get-MACAddress | |
| Get-UpTime | |
| Get-DiskSpace | |
| Get-MappedDrives | |
| Test-Gateway | |
| Get-FreeSpace -DriveLetter C | |
| Get-Proxy | |
| Get-Routes -ShowIPv6 | |
| Get-NetBIOS | |
| Set-NetBIOS -Enable $false | |
| .FUNCTIONS | |
| Get-DNSServers, Get-DNS, Get-Gateway, Get-GW, Get-IP, Get-SubnetMask, Get-MACAddress, Get-MAC, Get-UpTime, Get-DiskSpace, Get-MappedDrives, Test-Gateway, Test-GW, | |
| Get-FreeSpace, Get-Proxy, Show-Proxy, Get-Routes, Touch, Get-MyExternalIP, Get-NetBIOS, Set-NetBIOS | |
| .NOTES | |
| Author: Tim West | |
| Created: 11/11/2025 | |
| Updated: 30/01/2026 | |
| Status: Production | |
| Version: 1.1.8 | |
| .CHANGELOG | |
| 1.0.0 - Initial creation of the script with multiple functions. | |
| 1.1.0 - Added additional filtering options to Get-DNSServers and Get-SubnetMask functions. | |
| 1.1.1 - Fixed minor bugs in Get-DNSServers function. | |
| 1.1.2 - Improved output formatting in Get-SubnetMask function. | |
| 1.1.3 - Added Get-MyIp function to retrieve public IP address | |
| 1.1.4 - Enhanced Get-Routes function to include filtering by string. | |
| 1.1.5 - Added touch function to create or update file timestamps also Get-MyIP. | |
| 1.1.6 - Added Get-Netbios & Set-NETBIOS NIC status comparison for All adapters. | |
| 1.1.7 - Changed Get-NetBIOS & Set-NETBIOS to use WMI for better compatibility with NIC drivers. | |
| #> | |
| function Get-DNSServers { | |
| <# | |
| .SYNOPSIS | |
| Gets DNS server addresses configured on the system. | |
| .DESCRIPTION | |
| Returns DNS server addresses configured on the system, optionally filtered by interface alias, IPv4 only, and status. | |
| .PARAMETER All | |
| If specified, returns all DNS server addresses with their interface aliases and address families. | |
| .PARAMETER InterfaceAlias | |
| If specified, filters the results to only include DNS servers for the given interface alias. | |
| .PARAMETER IPv4Only | |
| If specified, filters the results to only include IPv4 DNS servers. | |
| .PARAMETER Status | |
| Specifies the status of network adapters to filter by (default is 'Up'). Other possible values | |
| include 'Down', 'Disabled', etc. | |
| .EXAMPLE | |
| Get-DNSServers | |
| .EXAMPLE | |
| Get-DNSServers -IPv4Only -Status Up | |
| .NOTES | |
| Author: Tim West | |
| Version: 1.0 | |
| Status: Production | |
| Created: 11/11/2025 | |
| Updated: 13/11/2025 | |
| .CHANGELOG | |
| - Initial creation of the function to retrieve DNS server addresses with filtering options. | |
| #> | |
| [cmdletBinding()] | |
| Param( | |
| [Parameter(Mandatory=$false)] | |
| [switch]$All, | |
| [Parameter(Mandatory=$false)] | |
| [string]$InterfaceAlias, | |
| [Parameter(Mandatory=$false)] | |
| [switch]$IPv4Only, | |
| [Parameter(Mandatory=$false)] | |
| [ValidateSet('Up', 'Down', 'Disabled', 'Disconnected', 'NotPresent', 'LowerLayerDown')] | |
| [string]$Status = 'Up' | |
| ) | |
| $dnsServers = Get-DnsClientServerAddress | Where-Object { | |
| $_.InterfaceAlias -notlike "Loopback*" -and | |
| $_.InterfaceAlias -notlike "Bluetooth*" | |
| } | |
| # Get enabled adapters only | |
| $enabledAdapters = Get-NetAdapter | Where-Object {$_.Status -eq $Status} | Select-Object -ExpandProperty Name | |
| # Filter to enabled adapters | |
| $dnsServers = $dnsServers | Where-Object {$enabledAdapters -contains $_.InterfaceAlias} | |
| # Apply IPv4 filter if requested | |
| if ($IPv4Only) { | |
| $dnsServers = $dnsServers | Where-Object {$_.AddressFamily -eq 2} | |
| } | |
| # Apply interface filter if specified | |
| if ($InterfaceAlias) { | |
| $dnsServers = $dnsServers | Where-Object {$_.InterfaceAlias -eq $InterfaceAlias} | |
| } | |
| if ($All) { | |
| return ($dnsServers | Select-Object InterfaceAlias, AddressFamily, ServerAddresses | Sort-Object InterfaceAlias) | |
| } | |
| else { | |
| return ($dnsServers | Select-Object -ExpandProperty ServerAddresses | Sort-Object -Unique) | |
| } | |
| } | |
| function Get-DNS{ | |
| # Alias Function Get-DNS to Get-DNSServers coz I'm/You're lazy ;-) | |
| Get-DNSServers @PSBoundParameters | |
| } | |
| function Get-Gateway { | |
| <# | |
| .SYNOPSIS | |
| Gets the default gateway address. | |
| .DESCRIPTION | |
| Returns the default gateway address used for routing traffic to external networks. | |
| .EXAMPLE | |
| Get-Gateway | |
| .NOTES | |
| Author: Tim West | |
| Version: 1.0 | |
| Status: Production | |
| Created: 11/11/2025 | |
| Updated: 13/11/2025 | |
| #> | |
| [CmdletBinding()] | |
| param() | |
| return (Get-NetRoute -DestinationPrefix "0.0.0.0/0").NextHop | |
| } | |
| function Get-GW { | |
| # Alias Function for the lazy/disallusioned among us ;-) | |
| Get-Gateway @PSBoundParameters | |
| } | |
| function Get-IP { | |
| <# | |
| .SYNOPSIS | |
| Gets IP addresses configured on the system. | |
| .DESCRIPTION | |
| Returns IP addresses configured on the system, optionally filtered by interface alias, IPv6 addresses, | |
| and address state. | |
| .PARAMETER InterfaceAlias | |
| If specified, filters the results to only include IP addresses for the given interface alias. | |
| .PARAMETER IpV6Too | |
| If specified, includes IPv6 addresses in the results. | |
| .PARAMETER All | |
| If specified, returns all IP addresses with their interface aliases and address families. | |
| .EXAMPLE | |
| Get-IP | |
| .NOTES | |
| Author: Tim West | |
| Created: 13/11/2025 | |
| Updated: 13/11/2025 | |
| Status: Production | |
| Version: 1.0 | |
| #> | |
| [CmdletBinding()] | |
| Param( | |
| [Parameter(Mandatory=$false)] | |
| [string]$InterfaceAlias, | |
| [Parameter(Mandatory=$false)] | |
| [switch]$IpV6Too, | |
| [Parameter(Mandatory=$false)] | |
| [switch]$All | |
| ) | |
| if($All){ | |
| return (Get-NetIPAddress | Select-Object InterfaceAlias,AddressFamily,IPAddress,PrefixOrigin,AddressState | Format-Table -AutoSize) | |
| } | |
| elseif($IpV6Too){ | |
| return (Get-NetIPAddress | Where-Object {$_.AddressFamily -eq 'IPv4' -or $_.AddressFamily -eq 'IPv6' -and $_.IPAddress -ne '127.0.0.1' -and $_.IPAddress -ne '::1' -and $_.AddressState -eq 'Preferred'} | | |
| Select-Object InterfaceAlias,IPAddress,PrefixOrigin,AddressState | Format-Table -AutoSize) | |
| } | |
| elseif($InterfaceAlias){ | |
| return (Get-NetIPAddress -InterfaceAlias $InterfaceAlias | Select-Object InterfaceAlias,IPAddress,PrefixOrigin,AddressState | Format-Table -AutoSize) | |
| } | |
| else{ | |
| return ((Get-NetIPAddress | Where-Object {$_.AddressFamily -eq 'IPv4' -and $_.IPAddress -ne '127.0.0.1' -and $_.AddressState -eq 'Preferred'} | | |
| Select-Object InterfaceAlias,IPAddress,PrefixOrigin,AddressState).IPAddress) | |
| } | |
| } | |
| function Get-SubnetMask { | |
| <# | |
| .SYNOPSIS | |
| Gets subnet masks for network adapters. Displays as CIDR prefix length and dotted decimal | |
| .DESCRIPTION | |
| Returns subnet masks for network adapters on the system. By default, returns only subnet masks | |
| for adapters with 'Up' status. Use -All switch to return all adapters with their names and status. | |
| .PARAMETER All | |
| If specified, returns all network adapters with their names, subnet masks, and status. | |
| .PARAMETER Status | |
| Specifies the status of network adapters to filter by (default is 'Up'). Possible values include | |
| 'Up', 'Down', 'Disabled', 'Disconnected', 'NotPresent', or 'LowerLayerDown'. | |
| .EXAMPLE | |
| Get-SubnetMask | |
| .EXAMPLE | |
| Get-SubnetMask -All | |
| .EXAMPLE | |
| Get-SubnetMask -Status Down | |
| .NOTES | |
| Author: Tim West | |
| Created: 13/11/2025 | |
| Updated: 22/01/2026 | |
| Status: Production | |
| Version: 1.1 | |
| .CHANGELOG | |
| 1.0 - Initial version | |
| 1.1 - Fixed to properly display both CIDR and dotted decimal notation | |
| #> | |
| [CmdletBinding()] | |
| Param( | |
| [Parameter(Mandatory=$false)] | |
| [switch]$All, | |
| [Parameter(Mandatory=$false)] | |
| [ValidateSet('Up', 'Down', 'Disabled', 'Disconnected', 'NotPresent', 'LowerLayerDown')] | |
| [string]$Status = "Up" | |
| ) | |
| # Convert PrefixLength to Subnet Mask | |
| function Convert-PrefixLengthToSubnetMask { | |
| param ( | |
| [int]$PrefixLength | |
| ) | |
| $mask = [uint32]0 | |
| for ($i = 0; $i -lt $PrefixLength; $i++) { | |
| $mask = $mask -bor (1 -shl (31 - $i)) | |
| } | |
| $byte1 = ($mask -shr 24) -band 0xFF | |
| $byte2 = ($mask -shr 16) -band 0xFF | |
| $byte3 = ($mask -shr 8) -band 0xFF | |
| $byte4 = $mask -band 0xFF | |
| return "$byte1.$byte2.$byte3.$byte4" | |
| } | |
| if($All){ | |
| $ipAddresses = Get-NetIPAddress | |
| } | |
| else{ | |
| $ipAddresses = Get-NetIPAddress | Where-Object {$_.AddressState -eq 'Preferred'} | |
| } | |
| $results = $ipAddresses | ForEach-Object { | |
| $subnetMask = Convert-PrefixLengthToSubnetMask -PrefixLength $_.PrefixLength | |
| [PSCustomObject]@{ | |
| InterfaceAlias = $_.InterfaceAlias | |
| IPAddress = $_.IPAddress | |
| CIDR = "/$($_.PrefixLength)" | |
| SubnetMask = $subnetMask | |
| AddressFamily = $_.AddressFamily | |
| AddressState = $_.AddressState | |
| } | |
| } | |
| return $results | Sort-Object InterfaceAlias| Format-Table -AutoSize | |
| } | |
| function Get-MACAddress { | |
| <# | |
| .SYNOPSIS | |
| Gets MAC addresses for network adapters. | |
| .DESCRIPTION | |
| Returns MAC addresses for network adapters on the system. By default, returns only MAC addresses | |
| for adapters with 'Up' status. Use -All switch to return all adapters with their names and status. | |
| .PARAMETER All | |
| If specified, returns all network adapters with their names, MAC addresses, and status. | |
| .PARAMETER Status | |
| Specifies the status of network adapters to filter by (default is 'Up'). Possible values include | |
| 'Up', 'Down', 'Disabled', 'Disconnected', 'NotPresent', or 'LowerLayerDown'. | |
| .EXAMPLE | |
| Get-MACAddress | |
| .EXAMPLE | |
| Get-MACAddress -All | |
| .EXAMPLE | |
| Get-MACAddress -Status Down | |
| .NOTES | |
| Author: Tim West | |
| Created: 11/11/2025 | |
| Updated: 13/11/2025 | |
| Status: Production | |
| Version: 1.0 | |
| #> | |
| [CmdletBinding()] | |
| Param( | |
| [Parameter(Mandatory=$false)] | |
| [switch]$All, | |
| [Parameter(Mandatory=$false)] | |
| [ValidateSet('Up', 'Down', 'Disabled', 'Disconnected', 'NotPresent', 'LowerLayerDown')] | |
| [string]$Status = "Up" | |
| ) | |
| if($All){ | |
| return (Get-NetAdapter | Select-Object Name, MacAddress, Status) | |
| } | |
| else{ | |
| return (Get-NetAdapter | Where-Object {$_.Status -eq $Status} | Select-Object Name, MacAddress, Status).MacAddress | |
| } | |
| } | |
| function Get-MAC { | |
| # Alias Function Get-MAC to Get-MACAddress coz my/your fingers hurt from all the typing ;-) | |
| Get-MACAddress @PSBoundParameters | |
| } | |
| function Get-UpTime { | |
| <# | |
| .SYNOPSIS | |
| Gets system uptime in formatted string. | |
| .DESCRIPTION | |
| Returns the system uptime since last boot in days.hours:minutes:seconds format. | |
| .EXAMPLE | |
| Get-UpTime | |
| Returns something like "5.12:34:56" for 5 days, 12 hours, 34 minutes, 56 seconds uptime. | |
| .NOTES | |
| Author: Tim West | |
| Created: 13/11/2025 | |
| Updated: 13/11/2025 | |
| Status: Production | |
| Version: 1.0 | |
| #> | |
| $lastBootTime = (Get-CimInstance Win32_OperatingSystem).LastBootUpTime ; $lastBootTime | |
| $uptimeSpan = New-TimeSpan -Start $lastBootTime -End (Get-Date) | |
| Write-Host -f Green "Days.Hours:Mins:Secs" | |
| return $uptimeSpan.ToString("d\.hh\:mm\:ss") | |
| } | |
| function Get-DiskSpace { | |
| <# | |
| .SYNOPSIS | |
| Gets disk space information for all drives, doesn't look at mount points though | |
| .DESCRIPTION | |
| Returns disk space information for all drives, including free space and total space in GB. | |
| .PARAMETER FreeSpace | |
| If specified, only returns free space for each drive. | |
| .EXAMPLE | |
| Get-DiskSpace | |
| .EXAMPLE | |
| Get-DiskSpace -FreeSpaceOnly -Drives C,X | |
| .NOTES | |
| Author: Tim West | |
| Created: 13/11/2025 | |
| Updated: 13/11/2025 | |
| Status: Production | |
| Version: 1.0 | |
| #> | |
| [CmdletBinding()] | |
| param( | |
| [Parameter(Mandatory=$false)] | |
| [switch]$FreeSpaceOnly, | |
| [Parameter(Mandatory=$false)] | |
| [ValidateSet('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z')] | |
| [string[]]$Drives | |
| ) | |
| if ($Drives) { | |
| $drivesToProcess = Get-PSDrive -PSProvider FileSystem | Where-Object { $Drives -contains $_.Name } | |
| } else { | |
| $drivesToProcess = Get-PSDrive -PSProvider FileSystem | |
| } | |
| if ($drivesToProcess.Count -eq 0) { | |
| Write-Host "No drives found." -ForegroundColor Yellow | |
| return | |
| } | |
| $drivesToProcess | ForEach-Object { | |
| $drive = $_ | |
| $freeSpaceGB = [math]::Round($drive.Free / 1GB, 2) | |
| $totalSpaceGB = [math]::Round(($drive.Used + $drive.Free) / 1GB, 2) | |
| if ($freeSpaceGB -lt 5) { | |
| if($FreeSpaceOnly){ | |
| Write-Host "Drive: $($drive.Name) - Free Space: $freeSpaceGB GB" -ForegroundColor Red | |
| } | |
| else{ | |
| Write-Host "Drive: $($drive.Name) - Free Space: $freeSpaceGB GB, Total Space: $totalSpaceGB GB" -ForegroundColor Red | |
| } | |
| } | |
| elseif ($freeSpaceGB -lt 10) { | |
| if($FreeSpaceOnly){ | |
| Write-Host "Drive: $($drive.Name) - Free Space: $freeSpaceGB GB" -ForegroundColor Yellow | |
| } | |
| else { | |
| Write-Host "Drive: $($drive.Name) - Free Space: $freeSpaceGB GB, Total Space: $totalSpaceGB GB" -ForegroundColor Yellow | |
| } | |
| } | |
| else { | |
| if($FreeSpaceOnly){ | |
| Write-Host "Drive: $($drive.Name) - Free Space: $freeSpaceGB GB" -ForegroundColor Green | |
| } | |
| else { | |
| Write-Host "Drive: $($drive.Name) - Free Space: $freeSpaceGB GB, Total Space: $totalSpaceGB GB" -ForegroundColor Green | |
| } | |
| } | |
| } | |
| } | |
| function Get-MappedDrives { | |
| <# | |
| .SYNOPSIS | |
| Gets mapped network drives. | |
| .DESCRIPTION | |
| Returns a list of mapped network drives with their names and paths. | |
| .PARAMETER UseWMI | |
| If specified, uses WMI to retrieve mapped drives instead of PowerShell drives. | |
| .EXAMPLE | |
| Get-MappedDrives | |
| .EXAMPLE | |
| Get-MappedDrives -UseWMI | |
| .NOTES | |
| Author: Tim West | |
| Created: 13/11/2025 | |
| Status: Production | |
| Version: 1.0 | |
| #> | |
| [CmdletBinding()] | |
| param( | |
| [Parameter(Mandatory=$false)] | |
| [switch]$UseWMI | |
| ) | |
| if($UseWMI){ | |
| $mappedDrives = Get-WmiObject -Class Win32_NetworkConnection | Select-Object Name, RemoteName | |
| if ($mappedDrives) { | |
| $mappedDrives | ForEach-Object { | |
| return "Drive: $($_.Name) - Path: $($_.RemoteName)" | |
| } | |
| } else { | |
| Write-Host "No mapped drives found." | |
| } | |
| } else { | |
| $mappedDrives = Get-PSDrive -PSProvider FileSystem | Where-Object { | |
| $_.DisplayRoot -like "\\*" | |
| } | Select-Object Name, DisplayRoot | |
| if ($mappedDrives) { | |
| $mappedDrives | ForEach-Object { | |
| return "$($_.Name): $($_.DisplayRoot)" | |
| } | |
| } else { | |
| Write-Host "No mapped drives found." | |
| } | |
| } | |
| } | |
| function Test-Gateway { | |
| <# | |
| .SYNOPSIS | |
| Tests connectivity to the default gateway. | |
| .DESCRIPTION | |
| Pings the default gateway to check if it is reachable. | |
| .EXAMPLE | |
| Test-Gateway | |
| .NOTES | |
| Author: Tim West | |
| Created: 13/11/2025 | |
| Updated: 13/11/2025 | |
| Status: Production | |
| Version: 1.0 | |
| .CHANGELOG | |
| - Initial creation of the function to test connectivity to the default gateway. | |
| #> | |
| [CmdletBinding()] | |
| param() | |
| $gateway = Get-Gateway | |
| if ($gateway) { | |
| Write-Host "Pinging default gateway: $gateway" | |
| $pingResult = Test-Connection -ComputerName $gateway -Count 1 -ErrorAction SilentlyContinue | |
| if ($pingResult) { | |
| Write-Host "Gateway is reachable." -ForegroundColor Green | |
| } else { | |
| Write-Host "Gateway is not reachable." -ForegroundColor Red | |
| } | |
| } else { | |
| Write-Host "No default gateway found." -ForegroundColor Yellow | |
| } | |
| } | |
| function Test-GW { | |
| # Alias Function Test-GW to Test-Gateway coz my/your fingers hurt from all the typing plus one of us is lazy ;-) | |
| Test-Gateway @PSBoundParameters | |
| } | |
| function Get-FreeSpace { | |
| [CmdletBinding()] | |
| param( | |
| [Parameter(Mandatory = $false, Position = 0, ValueFromPipeline = $true)] | |
| [string]$DriveLetter | |
| ) | |
| $ENV:COMPUTERNAME | |
| if($DriveLetter){ | |
| Get-PSDrive | Where-Object { $_.Provider -like "*FileSystem" -and $_.Name -eq $DriveLetter } | Select-Object Name, | |
| @{Name="Free(GB)"; Expression = { [math]::Round(($_.Free / 1GB), 1) }}, | |
| @{Name="Used(GB)"; Expression = { [math]::Round(($_.Used / 1GB), 1) }}, Root | |
| } | |
| else{ | |
| Get-PSDrive | Where-Object { $_.Provider -like "*FileSystem" } | Select-Object Name, | |
| @{Name="Free(GB)"; Expression = { [math]::Round(($_.Free / 1GB), 1) }}, | |
| @{Name="Used(GB)"; Expression = { [math]::Round(($_.Used / 1GB), 1) }}, Root | |
| } | |
| } | |
| function Get-Proxy { | |
| netsh winhttp show proxy | |
| } | |
| function Show-Proxy { | |
| Get-Proxy @PSBoundParameters | |
| } | |
| function Get-Routes { | |
| <# | |
| .SYNOPSIS | |
| Gets the system's routing table. | |
| .DESCRIPTION | |
| Returns the system's routing table, displaying destination prefixes, next hops, interface indices, and metrics. | |
| .PARAMETER ShowIPv6 | |
| Optionally includes IPv6 routes if specified. | |
| .EXAMPLE | |
| Get-Routes | |
| .NOTES | |
| Author: Tim West | |
| Created: 22/01/2026 | |
| Updated: 22/01/2026 | |
| Status: Production | |
| Version: 1.0.1 | |
| #> | |
| [CmdletBinding()] | |
| param( | |
| [switch]$ShowIPv6 = $false, | |
| [string]$FindString | |
| ) | |
| if(-not ($ShowIPv6)){ | |
| if($FindString){ | |
| return (Get-NetRoute | Select-Object DestinationPrefix, NextHop, InterfaceIndex, RouteMetric, ifMetric | Where-Object {$_.DestinationPrefix -notlike "*:*" -and $_.DestinationPrefix -like "*$FindString*"} | Sort-Object RouteMetric | Format-Table -AutoSize) | |
| Write-Host -f Green "`nOr Old School Route Print:" | |
| cmd /c route print | Select-String -notmatch ":" | Select-String -pattern $FindString | |
| } | |
| else{ | |
| Write-Host -f Green "Not Showing IPv6. If required use -ShowIPv6" | |
| return (Get-NetRoute | Select-Object DestinationPrefix, NextHop, InterfaceIndex, RouteMetric, ifMetric | Where-Object {$_.DestinationPrefix -notlike "*:*"} | Sort-Object RouteMetric | Format-Table -AutoSize) | |
| Write-Host -f Green "`nOr Old School Route Print:" | |
| cmd /c route print | Select-String -notmatch ":" | |
| } | |
| } | |
| else{ | |
| if($FindString){ | |
| return (Get-NetRoute | Select-Object DestinationPrefix, NextHop, InterfaceIndex, RouteMetric, ifMetric | Where-Object {$_.DestinationPrefix -like "*$FindString*"} | Sort-Object RouteMetric | Format-Table -AutoSize) | |
| Write-Host -f Green "`nOr Old School Route Print:" | |
| cmd /c route print | Select-String -notmatch ":" | Select-String -pattern $FindString | |
| } | |
| else{ | |
| return (Get-NetRoute | Select-Object DestinationPrefix, NextHop, InterfaceIndex, RouteMetric, ifMetric | Sort-Object RouteMetric | Format-Table -AutoSize) | |
| Write-Host -f Green "`nOr Old School Route Print:" | |
| cmd /c route print | |
| } | |
| } | |
| } | |
| function touch { | |
| param ( | |
| [Parameter(Mandatory = $true)] | |
| [string]$FilePath | |
| ) | |
| if (Test-Path -Path $FilePath) { | |
| # Update the last write time to the current time | |
| (Get-Item -Path $FilePath).LastWriteTime = Get-Date | |
| } else { | |
| # Create an empty file | |
| New-Item -Path $FilePath -ItemType File | Out-Null | |
| } | |
| } | |
| function Get-ExternalIP{ | |
| [Cmdletbinding()] | |
| Param( | |
| [string]$URI = "https://api.ipify.org" | |
| ) | |
| $MyPublicIP = (Invoke-RestMethod -Uri $URI) | |
| return $MyPublicIP | |
| } | |
| function Get-NetBIOS { | |
| <# | |
| .SYNOPSIS | |
| Gets the current NETBIOS over TCP/IP setting for network adapters. | |
| .DESCRIPTION | |
| Returns the current NETBIOS over TCP/IP setting for network adapters on the system. | |
| Get-NetworkAdapter is unreliable in some NIC Driver versions, so WMI is used instead. | |
| .EXAMPLE | |
| Get-NETBIOS | |
| .NOTES | |
| Author: Tim West | |
| Created: 30/01/2026 | |
| Updated: 30/01/2026 | |
| Status: Production | |
| Version: 1.0.1 | |
| .CHANGELOG | |
| 1.0.0 - Initial creation of the function to retrieve NETBIOS over TCP/IP settings with filtering options. | |
| 1.0.1 - Changed to use Get-WmiObject for better compatibility with various NIC drivers. | |
| #> | |
| [Cmdletbinding()] | |
| param() | |
| Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object { $_.IPEnabled -eq $true } | Select-Object Description, TcpipNetbiosOptions | |
| } | |
| function Set-NetBIOS { | |
| <# | |
| .SYNOPSIS | |
| Sets the NETBIOS over TCP/IP setting for network adapters. Default is disable. | |
| .DESCRIPTION | |
| Enables or disables NETBIOS over TCP/IP for network adapters on the system. | |
| Using Set-NetworkAdapter is unreliable in some NIC Driver versions, so WMI is used instead. | |
| .PARAMETER Disabled | |
| If specified as $true, disables NETBIOS over TCP/IP. If specified as $false, enables NETBIOS over TCP/IP. | |
| .EXAMPLE | |
| Set-NetBIOS | |
| .EXAMPLE | |
| Set-NetBIOS -Disabled $false | |
| .NOTES | |
| Author: Tim West | |
| Created: 30/01/2026 | |
| Updated: 30/01/2026 | |
| Status: Production | |
| Version: 1.0.1 | |
| .CHANGELOG | |
| 1.0.0 - Initial creation of the function to set NETBIOS over TCP/IP settings with filtering options. | |
| 1.0.1 - Changed to use Get-WmiObject for better compatibility with various NIC drivers. | |
| #> | |
| [Cmdletbinding()] | |
| param ( | |
| [bool]$Disabled = $true | |
| ) | |
| if($Disabled-eq $true){ | |
| Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object { $_.IPEnabled -eq $true } | ForEach-Object { | |
| $_.SetTcpipNetbios(2) | |
| } | |
| } | |
| else{ | |
| Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object { $_.IPEnabled -eq $true } | ForEach-Object { | |
| $_.SetTcpipNetbios(1) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment