Blog - Post List
  • Power Tips: Getting Help for PowerShell

    Provided you have downloaded the PowerShell help files, there is an easy way to get help for all kinds of PowerShell topics.

    First, make sure you downloaded the help: launch PowerShell with Administrator privileges, and run this:

    Update-Help -UICulture en-us -Force

    Next, check out the “about”-topics you got:

    Get-Help about_*

    In the PowerShell ISE, all you’d need to do is click one of the about topics listed…

    • 14 Feb 2018
  • Power Tips: Exploiting Select-Object

    Select-Object is a basic cmdlet that most PowerShell users use frequently. However, it has some tricks that are not well known.

    In its most basic form, Select-Object selects the properties that are visible. If you don’t use Select-Object, then PowerShell determines which properties are shown, and how they are formatted:

    Get-ChildItem -Path c:\windows\system32 -Filter *.dll

    If you add Select-Object, you can determine…

    • 13 Feb 2018
  • Power Tips: Reading RunOnce Key

    The RunOnce key in the Windows Registry stores all auto-starting executables. It may be empty. To check for auto-starting applications, try this:

    $path = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce'
    $properties = Get-ItemProperty -Path $path 

    Again, this key may have no values. If it has, each auto-starting program has its own value with its own name. To read just the paths for auto-starting…

    • 12 Feb 2018
  • Power Tips: Creating Random Passwords

    Here is another small script to produce random passwords consisting of a defined number of capitals, letters, numbers, and special characters:

    $length = 10
    $length_small = $length - 3
    $numbers = '2,3,4,5,6,7,8,9' -split ','
    $large = 'A,B,C,D,E,F,G,H,K,L,M,N,P,R,S,T,U,V,W,X,Y,Z' -split ','
    $small = 'A,B,C,D,E,F,G,H,K,L,M,N,P,R,S,T,U,V,W,X,Y,Z'.ToLower() -split ','
    • 9 Feb 2018
  • Power Tips: Converting PowerShell to Batch

    Here is a fun PowerShell function called Convert-PowerShellToBatch. Provide it with the path to a PowerShell script, or pipe in the results from Get-ChildItem to batch-convert many scripts.

    The function creates a batch file per script. When you double-click the batch file, the PowerShell code executes.

    function Convert-PowerShellToBatch
    • 8 Feb 2018
  • Power Tips: Piping Files and Folders

    Let’s assume you want to create a function that accepts a file path. There are numerous tasks that can be done with files. You may want to copy files, archive them, turn them to hidden files, or whatever else comes to mind. We are not focused on what you do with files here. We want to look at how your PowerShell function can accept files from a user.

    So you’d come up with a function like this:

    function Process…
    • 7 Feb 2018
  • Power Tips: Simple WMI Browser

    WMI is a powerful information repository – if you know the names of WMI classes:

    Get-CimInstance -ClassName Win32_BIOS
    Get-CimInstance -ClassName Win32_Share
    Get-CimInstance -ClassName Win32_OperatingSystem

    If you want to explore WMI, then the following code may come handy. Find-WmiClass accepts a simple keyword such as “video”, “network”, “ipaddress”. It then retrieves all WMI classes that contain the keyword…

    • 6 Feb 2018
  • Power Tips: Finding Nested AD Group Memberships

    The following code finds all groups a given Active Directory user is member of (including nested group memberships). The code requires the ActiveDirectory module.

    #requires -Module ActiveDirectory
    function Get-NestedGroupMember
            $user = Get-ADUser -Identity $Identity
    • 5 Feb 2018
  • Power Tips: Checking Network Connections

    If your machine is connected to the internet (or VPN) via different network connections, depending on where you are, then the following two functions may be useful to you.

    Get-ActiveConnection lists the names of all network connections that currently have an IP address assigned. Test-ActiveConnection accepts a keyword and checks to see whether there are currently any active connections with the keyword in their name.

    • 2 Feb 2018
  • Power Tips: Removing Bloatware from Windows 10

    Windows 10 comes with all kinds of preinstalled apps and other features that may feel annoying to some. Richard Newton has created a PowerShell script designed to identify and remove many preinstalled features, and strengthen privacy settings. He describes his project at

    The source code can be found here:…

    • 1 Feb 2018
  • Power Tips: Managing FTP via PowerShell

    There are no built-in FTP commands in PowerShell, but you can easily download and install a free extension that provides the missing commands. Just run this line:

    PS> Install-Module -Name Posh-SSH -Scope CurrentUser

    If PowerShell cannot find the Install-Module command, then you are most likely not using the latest version of PowerShell (5.1). Please update your PowerShell installation, or add the Microsoft’s “PowerShellGet…

    • 31 Jan 2018
  • Power Tips: Formatting Numbers (Part 2)

    In the previous tip we introduced the Get-DisplayFileSize function which automatically converts bytes to readable numbers with units such as “KB” and “MB”.

    Using Select-Object, you can now produce folder listings with meaningful file sizes:

    $Length = @{
        Name = "Length"
        Expression = { 
        if ($_.PSIsContainer) { return }
        $Number = $_.Length
        $newNumber = $Number
    • 30 Jan 2018
  • Power Tips: Formatting Numbers (Part 1)

    The following Get-DisplayFileSize function takes any byte value and returns a nicely formatted size, using units like “MB”, “GB”, or “PB”:

    function Get-DisplayFileSize 
        $newNumber = $Number
        $unit = ',KB,MB,GB,TB,PB,EB,ZB' -split ','
        $i = $null
        while ($newNumber -ge 1KB -and $i -lt $unit.Length)
    • 29 Jan 2018
  • Power Tips: Filtering Files

    You may not have noticed this, but the -Filter parameter on Get-ChildItem (aka dir or ls) is not as specific as you think. The following line should only find PowerShell scripts, but in fact it finds a lot more:

    Get-ChildItem -Path $env:windir -Filter *.ps1 -Recurse -ErrorAction Silent |
      Group-Object -Property Extension -NoElement 

    Here is the result:

    Count Name                     
    ----- ----                   …
    • 26 Jan 2018
  • Power Tips: Using List View in a Grid View Window (Part 3)

    In the previous tip we introduced ConvertObject-ToHashTable which makes it easy to dump objects in a grid view window.

    The code below is an improved version that sorts properties alphabetically, and lets you decide how the columns should be called. By default, Out-GridView calls the columns “Property” and “Value”, but you can override the defaults and call them anything:

    function ConvertObject…
    • 25 Jan 2018
  • Power Tips: Using List View in a Grid View Window (Part 2)

    Out-GridView is a useful cmdlet to list many objects. It is not ideal when you just want to display a single object with all of its properties, because in this scenario there would only be one line. In the previous tip we explained how turning an object to a hash table can help. It effectively puts the grid view in “ListView” mode.

    Because this approach can be highly useful in many scenarios, here is a function…

    • 24 Jan 2018
  • Power Tips: Using List View in a Grid View Window (Part 1)

    One of the simplest hardware inventories is probably this line:

    $data = systeminfo.exe /FO CSV | ConvertFrom-Csv
    $data | Out-GridView

    A more modern approach uses the new cmdlet Get-ComputerInfo:

    $data = Get-ComputerInfo
    $data | Out-GridView

    One simple approach is a hash table that is created for you by Group-Object: group the original data by a property like “UserName”. Then, show the hash table keys in the grid view…

    • 23 Jan 2018
  • Power Tips: Efficiently Produce Comma-Separated Strings (Part 2)

    In the previous tip we showed how you can use the PowerShell command mode to easily create lists of quoted strings. This can be really useful for creating code, and saves a lot of typing.

    Here is a function that can help in everyday PowerShell coding life:

    function s+ { "'$($args -join "','")'" | Set-ClipBoard }

    Next time you need a list of quoted strings in your code, simply type…

    • 22 Jan 2018
  • Power Tips: Efficiently Produce Comma-Separated Strings

    Here is a super simple approach to create a list of quoted strings:

    & { "'$($args -join "','")'" } hello this is a test

    Here is the result:


    This approach effectively makes use of PowerShell’s “Command Mode” where literals are treated as arguments. You could even pipe this to Set-Clipboard and then paste…

    • 19 Jan 2018
  • Power Tips: Using a Grid View Window as a Selection Dialog (Part 2)

    In the previous tip we explained how you can use a hash table to show simple selection dialogs, yet when the user selects an item, return full rich objects.

    A hash table can basically use anything as a key. In the previous example, we used a string. It could as well be another object. This really leads you to a highly flexible approach for selection dialogs.

    Simply use Select-Object to select those properties that you…

    • 18 Jan 2018
  • Power Tips: Using a Grid View Window as a Selection Dialog (Part 1)

    How can a grid view window be used as a simple selection dialog?

    When you pipe objects to a grid view window, all object properties are shown. Often this works really well, and then just a line like this is needed:

    Get-Service | Out-GridView -Title "Select Service" -OutputMode Single

    Sometimes, especially when an object has tons of properties, it can be an overkill and confuse the user:

    Get-WmiObject -Clas…
    • 17 Jan 2018
  • Power Tips: Removing User Profiles Via Dialog (Part 2)

    In the previous tip we illustrated how a grid view window can display all available user profiles, lets you select one, and deletes it:

    #requires -RunAsAdministrator
    Get-WmiObject -ClassName Win32_UserProfile -Filter "Special=False AND Loaded=False" |
        Add-Member -MemberType ScriptProperty -Name UserName -Value { (New-Object System.Security.Principal.SecurityIdentifier($this.Sid)).Translate([System.Security…
    • 16 Jan 2018
  • Power Tips: Remove User Profiles Via Dialog

    We’ve received massive feedback on our tips dealing with user profile management, so we decided to add a couple of additional tips.

    In the previous tip we illustrated how WMI can delete user profiles. Some users recommended to use Remove-WmiObject instead of the internal WMI method Delete(). However, it turned out that Remove-WmiObject cannot delete user profile instances.

    The code below sums up all the details…

    • 15 Jan 2018
  • Power Tips: Find User Profiles

    We’ve received massive feedback on our tips dealing with user profile management, so we decided to add a couple of additional tips.

    Typically, every time a user logs on to a system, locally or remote, a user profile is created. So over time, there can exist a lot of orphaned user profiles. If you’d like to manage user profiles (including deleting unwanted ones), make sure you ignore special user profiles that are…

    • 12 Jan 2018
  • Power Tips: List User Profiles

    We've received a massive feedback on our tips dealing with user profile management, so we decided to add a couple of additional tips.

    WMI can easily enumerate all user profiles on a system but lists only the SID (security identifier), not the plain text user name.

    Get-CimInstance -ClassName Win32_UserProfile |

    To improve this, here is a simple chunk of code that converts SIDs to user names:

    $sid =
    • 11 Jan 2018