Latest Posts
  • Power Tips: Identifying Windows Type

    WMI returns a cryptic code number of every distinct Windows SKU:

     
    PS> Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -ExpandProperty OperatingSystemSKU
    48   
     

    To translate this number into a meaningful text, for example for reporting purposes, try this:

    $OperatingSystemSKU = @
    • 3 Jul 2020
  • Power Tips: Boot and Install Time for Operating System

    The WMI class Win32_OperatingSystem provides rich information about a number of datetime information, including the date of last boot-up and the installation time:

    $dateTimeProps = 'InstallDate', 'LastBootupTime', 'LocalDateTime', 'CurrentTimeZone', 'CountryCode'…
    • 1 Jul 2020
  • Power Tips: Changing Operating System Description

    Each Windows operating system has a description, and you can view (and change) this description with the following command:

     
    PS> control sysdm.cpl
     

    To do the same in an automated way via PowerShell, use this:

    # change operating system description
    # (requires admin privileges)
    $values = @{
        D…
    • 29 Jun 2020
  • Power Tips: Showing Object Data as Table in a Grid View Window

    Typically, when you output a single object to Out-GridView, you get one line, and every property surfaces as a column:

    Get-ComputerInfo | Select-Object -Property * | Out-GridView
    

    This makes it hard to view and filter for specific information. Simply convert an object to an ordered hash table to show…

    • 25 Jun 2020
  • Power Tips: Removing Empty Properties

    WMI and Get-CimInstance can provide you with a lot of useful information but the returned objects often contain a number of empty properties:

     
    PS> Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -Property 
     

    Also, properties aren’t necessarily sorted. You can fix both by identifying…

    • 23 Jun 2020
  • Power Tips: Using Assertions

    Often, your code needs to assert certain prerequisites. For example, you may want to ensure that a given folder exists, and use code like this:

    # path to download files to
    $OutPath = "$env:temp\SampleData"
    
    # does it already exist?
    $exists = Test-Path -Path $OutPath -PathType Container
    
    # no…
    • 19 Jun 2020
  • Power Tips: Wake On LAN

    There is no need for external “Wake On LAN” tools. If you want to wake up a network machine, simply tell PowerShell the MAC address of the target machine. Here is a function that composes the magic packet and wakes the machine(s):

    function Invoke-WakeOnLan
    {
      param
      (
        # one or more…
    • 17 Jun 2020
  • Power Tips: Converting Hex Numbers

    PowerShell can interactively convert hexadecimal numbers when you prefix “0x”:

     
    PS> 0xAB0f
    43791 
     

    If the hex number is stored in a string, you can invoke the conversion by applying a type to the expression:

     
    PS> $a = 'ab0f'
    
    PS> [int]"0x$a"
    43791 
     



    Twitter This Tip! ReTweet…

    • 15 Jun 2020
  • Power Tips: Auto-Learning Argument Completion

    Argument completion is awesome for a user because valid arguments are always suggested. Many built-in PowerShell commands come with argument completion. You can see this in action when you enter:

     
    PS> Get-EventLog -LogName  
     

    Enter a space after -LogName to trigger automatic argument completion in…

    • 11 Jun 2020
  • Power Tips: Adding Argument Completion (Part 2)

    In the previous tip we talked about the new [ArgumentCompletions()] attribute that was added to PowerShell 7, and how you can use it to add sophisticated argument completion to your function parameters.

    Unfortunately, this attribute isn’t available in Windows PowerShell, so by using it, your code is…

    • 9 Jun 2020