Latest Posts
  • Power Tips: Testing Well Formed URLs

    PowerShell is API-based so often, you don’t need to dive into regular expressions and text patterns. Instead, there is a multitude of specialized testing methods accessible in the .NET Framework. The hard part is rather to find and know them, not so much to run them and perform the tests.

    For example…

  • Power Tips: Running on Windows PowerShell – Or Not? (Part 2)

    In the previous tip we featured a backward-compatible one-liner that can tell whether your script is running in the classic Windows PowerShell environment or on the new PowerShell 7 portable shell.

    If you do use the new platform-neutral PowerShell 7, then there is a new type called [Management.Automation…

  • Power Tips: Running on Windows PowerShell – Or Not? (Part 1)

    PowerShell can run on various platforms these days, and in the previous tip we explained how you find out the operating system that your scripts are running on.

    If the operating system is Windows, you still don’t know whether your script is run by the built-in Windows PowerShell or by the new portable…

  • Power Tips: Determining Your Platform

    PowerShell today is cross-platform so even though you may still use Windows PowerShell on Windows servers, your scripts may well end up running on different operating systems.

    If your script wants to know the platform it is running on, in a backward-compatible way, try these lines:

    $RunOnWindows = (
  • Power Tips: Escaping Individual Characters

    In previous tips we explained how you can escape entire string sequences. If you just need to escape an individual character, use HexEscape() like so:

     
    PS> [Uri]::HexEscape('a')
    %61 
     

    This method actually retrieves the ASCII code and converts it to hexadecimal.

    Actually, there is even the…

  • Power Tips: Safely Escaping Data Strings

    Typically you use methods like EscapeUriString() to safely escape string data that you want to append to URLs (as pointed out in our previous tip).

    However, this can cause severe headaches because EscapeUriString() is specifically designed to escape a full URL including the domain part, not just your…

  • Power Tips: Escaping Strings in URLs

    When adding string information to URLs, i.e. to construct requests for calling REST web services, it is important to escape special characters. The type [Uri] comes with methods to escape and unescaped string for use in URLs:

    $Text = 'SOS Save me please!'
    $Escaped = [Uri]::EscapeUriString($T…
  • Power Tips: Dynamically Composed IntelliSense

    When designing PowerShell functions, you can improve usability tremendously by adding clever argument completion IntelliSense.

    To compose argument IntelliSense completion, you can equip each parameter of your function with a piece of PowerShell code that dynamically composes the IntelliSense list. Of…

  • Power Tips: Auto-Logon After Windows-Reboot

    If your automation script needs to restart the machine, and you want to auto-logon after the reboot, here is a quick script that saves the logon credentials to the Windows registry:

    # ask for logon credentials:
    $cred = Get-Credential -Message 'Logon automatically'
    $password = $cred.GetNetwor…
  • Power Tips: Automating Lenovo Driver Downloads (Part 2)

    In the previous example we illustrated how you can scrape Lenovo driver information from the web. In this example, some of the information returned was raw numeric information: the number “3” represented “Reboot required”, for example.

    In this tip we’d like to show how you can…