Latest Posts
  • Power Tips: A Better NetStat (Part 3)

    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…

    • 19 Jan 2021
  • Power Tips: A Better NetStat (Part 2)

    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…
    • 15 Jan 2021
  • Power Tips: A Better NetStat (Part 1)

    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…

    • 13 Jan 2021
  • Power Tips: Controlling Uptime

    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…
    • 11 Jan 2021
  • Power Tips: Finding Unused (or Used) Drive Letters

    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…

    • 7 Jan 2021
  • Power Tips: Understanding REST Web Services in PowerShell

    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…

    • 5 Jan 2021
  • Power Tips: A Better Recursion

    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…

    • 1 Jan 2021
  • Power Tips: Managing Local Group Members (Part 2)

    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…

    • 30 Dec 2020
  • Power Tips: Managing Local Group Members (Part 1)

    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…

    • 28 Dec 2020
  • Power Tips: Identifying Name of Local Administrator Account

    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…

    • 24 Dec 2020