In the previous tip we introduced the Get-NetTCPConnection cmdlet as a better alternative to the network utility netstat.exe on Windows systems, and with a couple of tricks, you can even resolve IP addresses and process IDs. However, this slows down the command considerably because DNS lookup may take…
In the previous tip we introduced the Get-NetTCPConnection cmdlet as a better alternative to the netstat.exe network utility on Windows systems. It can list open ports and connections, and we left off with an example that lists all connections to HTTPS (port 443):
PS> Get-NetTCPConnection -RemotePort…
On Windows systems, netstat.exe is a useful utility to check for open ports and listeners. However, the tool returns text only, has cryptic arguments, and isn’t available cross-platform.
On Windows systems, you can use a new PowerShell cmdlet named Get-NetTCPConnection which mimics much of the…
PowerShell 7 comes with a new cmdlet called Get-Uptime. It returns a timespan object with the time that has passed since the last reboot:
PS> Get-Uptime Days : 9 Hours : 23 Minutes : 21 Seconds : 14 Milliseconds : 0 Ticks : 8616740000000…
By concatenating type conversions, you can easily create a list of letters:
PS> [Char[]](65..90) A B C D ...
From this list, you can generate a list of drive letters that are in use:
PS> [Char[]](65..90) | Where-Object { Test-Path "${_}:\" } C D
Likewise, to find free (unused…
There are many different types of web services, and PowerShell can access many of them using Invoke-RestMethod. Here is a quick intro to get you started.
In its most simple form, a web service is just a web page with structured data on it. You can use the very same URL in your browser to view the data…
When a function calls itself, this is called “recursion”. You can see this technique often when a script wants to traverse part of the filesystem: a function processes folder content, and when it encounters a subfolder, it calls itself.
Recursion can be powerful but it’s very hard to debug…
In the previous tip we explained why accessing local group members will not always work with built-in cmdlets like Get-LocalGroupMember, and ways to work around it using the old (but still functional) ADSI interface.
If you’d like to build solutions on top of this, you may be wondering how local accounts…
Fortunately, PowerShell 5 and better comes with cmdlets like Get-LocalGroupMember which list the members of local groups. Unfortunately, these cmdlets have a flaw: if the group contains one or more orphaned members, the cmdlet fails to list any group member.
Orphaned group members could be users or groups…
Occasionally, PowerShell scripts need to access or use the built-in Administrator account or the built-in Administrators group. Unfortunately, their names are localized, so their names can change based on the language of your Windows operating system.
They do use constant (well-known) SIDs (security…