All articles

  1. ipconfig /all in PowerShell

    Quick and dirty one, I was looking for an alternative to ipconfig /all that worked with invoke-command. This works on IPv4 and IPv6 and includes both tunnel and cluster adapters. This does not work on Server 2008 R2 even with WMF 5+.

    Get-NetIPAddress
    

    More Info:

  2. Reversing Strings in Python and PowerShell

    Reversing a string is super easy in Python and a little more complicated in PowerShell. Both of them have multiple ways to do it, all basically similar. The only trade-offs appear to be obvious: do you care about the overhead of a function call, line count, verbosity, etc. Personally, I'd …

  3. Rebuild the PowerShell Virtual Directory in Exchange

    If you're a dumb-ass like me who tends to make changes faster than he thinks them through, you may have screwed up the PowerShell virtual directory in Exchange and want (or need) to rebuild it and set things back to default. You should absolutely, under no circumstances, do this from …

  4. PowerShell Background Jobs

    PowerShell background jobs are a simple and powerful tool and can be used with almost any Powershell or regular cmd commands. The most important cmdlets for using background jobs are Start-Job, Get-Job, and Remove-Job. Jobs have to be removed after completion or they will remain in a completed state.

    Start-Job …
  5. PowerShell Cleanup Subfolders

    Want to delete a bunch of empty subfolders? Or maybe move all the files first? In PowerShell it's super easy.

    # Move all files in subfolders of source to destination
    Get-ChildItem -Path source -Recurse -File | Move-Item -Destination destination
    # Delete all empty folders in source
    Get-ChildItem -Path source -Recurse -Directory | Remove-Item
    

    Note …

  6. Download Files With PowerShell

    This blog post on the topic is phenomenal, but I'll briefly summarize it. Theres three method to download a file with PowerShell: Invoke-WebRequest, System.Net.WebClient, and Start-BitsTransfer. All have pros and cons; Invoke-WebRequest is built-in and very simple but requires Internet Explorer and is very slow, System.Net.WebClient …

  7. Get Installed Programs in PowerShell

    This is something is something that can be done multiple ways, none of which are straightforward and all with their own drawbacks. This leads me to believe it must be some sort of legacy issue. In my experience the easiest way to do it while also ensuring you get all …

  8. Formatting Output in PowerShell

    There's five useful commands when it comes to controlling your output in PowerShell (in my experience): Out-File, Export-Csv, Format-Table aka ft, Format-List aka fl, and Out-Null. These are all pretty self explanatory. Out-File saves your output to a regular text file (and does not translate it from a PowerShell object …

  9. touch Command in PowerShell

    Unix/Linux has a very convenient command for making an empty file at the specified path called touch. PowerShell can imitate this by using New-Item.

    New-Item -ItemType file <filename>
    
    # Example: creating the PowerShell profile. -Force is required to make the full path.
    New-Item -ItemType file $profile -Force
    

    New-Item can also …

  10. Check Disk in PowerShell

    I use check disk as one of my basic troubleshooting tools. Here's the new PowerShell commands that serve the same purpose with the advantage of all PowerShell features. My favorite part of this command is that it's much faster than the original.

    # chkdsk /f
    Repair-Volume -DriveLetter H -Scan
    
    # chkdsk /scan …
  11. DISM Image Repair in PowerShell

    DISM has saved many an online image (i.e the one running on my PC) the past few years. Here's those commands in a much easier to remember PowerShell format.

    # Dism.exe /Image:<...> /Cleanup-Image /ScanHealth
    Repair-WindowsImage -ScanHealth
    
    # Dism.exe /Image:<...> /Cleanup-Image /RestoreHealth
    Repair-WindowsImage -RestoreHealth
    

    More Info:

  12. Help, Your PowerShell Command Isn't Working!

    This is a living document where I try to help common issues running the PowerShell commands and scripts I post.

    The term <cmdlet> is not recognized as the name of a cmdlet... etc.
    

    This can be caused by two issues, either you have not imported the appropriate module (i.e …

  13. PowerShell Remoting

    When it comes to remoting in PowerShell, there's two main options: Invoke-Command (good) and Enter-PSSession (bad, but necessary sometimes). The difference is that Invoke-Command will do as the name says, invoke the command for you and return the output. Enter-PSSession will change the context of your PowerShell to that of …