Latest Posts
  • Power Tips: Reading Installed Software (Part 2)

    In the previous tip we illustrated how powerful Get-ItemProperty is and that you can create an entire software inventory with just one line of code by reading multiple registry locations.

    Today, let’s add two important pieces of information to our software inventory: the scope (was a software installed…

    • 22 Dec 2020
  • Power Tips: Reading Installed Software (Part 1)

    The Get-ItemProperty cmdlet can read registry values in a much more powerful way than most users know. The cmdlet supports multiple registry paths, and it supports wildcards. This way, it takes only a one-liner to read all installed software (plus their uninstall strings) from four registry keys:

    # list…
    • 18 Dec 2020
  • Power Tips: Keeping Windows (and PowerShell) Running

    Depending on your Windows PC energy settings, your machine may go into standby or hibernate after some time even though you might be still running a lengthy script.

    One way to ensure that Windows keeps running while your script is busy is to use the “presentation mode”. There is a tool you can use to…

    • 16 Dec 2020
  • Power Tips: Reading Event Logs (Part 4)

    In the previous tip we encouraged you to deprecate the Get-EventLog cmdlet and instead start using Get-WinEvent – because the latter is more powerful, and because the former is no longer supported in PowerShell 7.

    Querying events via Get-WinEvent requires a hash table as you have seen in the previous…

    • 14 Dec 2020
  • Power Tips: Reading Event Logs (Part 3)

    In the previous tip we encouraged you to deprecate the Get-EventLog cmdlet and instead start using Get-WinEvent – because the latter is more powerful, and because the former is no longer supported in PowerShell 7.

    One of the advantages of Get-WinEvent over Get-EventLog is its ability to read all…

    • 10 Dec 2020
  • Power Tips: Reading Event Logs (Part 2)

    In the previous tip we encouraged you to deprecate the Get-EventLog cmdlet and instead start using Get-WinEvent – because the latter is more powerful, and because the former is no longer supported in PowerShell 7.

    Let’s practice once more how to translate a Get-EventLog statement to Get-WinEvent…

    • 8 Dec 2020
  • Power Tips: Reading Event Logs (Part 1)

    In Windows, there are a number of event logs like “System” and “Application”, and in Windows PowerShell, it is simple to retrieve event entries from these logs using Get-EventLog. This one-liner returns the latest five error events from your System event log:

     
    PS> Get-EventL…
    • 4 Dec 2020
  • Power Tips: Reading Last Logged-On User and Other Registry Values

    Reading some registry values with PowerShell is typically a snap: simply use Get-ItemProperty. This snippet of code reads the Windows operating system details, for example:

    $Path = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
    
    Get-ItemProperty -Path $Path |
    Select-Object -Property 
    • 2 Dec 2020
  • Power Tips: Constant Functions

    In PowerShell, you can write-protect functions. When you do, a function cannot be changed, overwritten or removed anymore during a running PowerShell session. While there may be no apparent use case for this, here is the technique:

    $code = 
    {
        param
        (
            [string]
            [Parameter(Manda…
    • 30 Nov 2020
  • Power Tips: Suppressing Errors

    With cmdlets, suppressing errors seems easy: simply add the –ErrorAction Ignore parameter.

    However, it turns out that this doesn’t suppress all errors. It only suppresses errors that the cmdlet chose to handle. Especially security-related exceptions still show.

    If you want to suppress all…

    • 26 Nov 2020