Latest Posts
  • Power Tips: Simple Built-In Password Generator

    There is a hidden gem in the .NET System.Web assembly which lets you create random passwords of any length in no time:

    # total password length
    $Length = 10
    
    # number of non-alpha-chars
    $NonChar = 3
    
    Add-Type -AssemblyName 'System.Web'
    $password = [System.Web.Security.Membership]::GeneratePas…
  • Power Tips: Creating Dummy Test Files

    If you need to test file system load, test failover clusters, or need large dummy files otherwise, rather than creating new files and slowly filling them with random data, try this:

    $filepath = "$env:temp\testfile.txt"
    $sizeBytes = 5.75MB
    
    $file = [System.IO.File]::Create($filepath)
    $file.
  • Power Tips: Reading HTTP Headers from Websites

    When you navigate to a web page, your browser silently receives meta information inside the HTTP header which is typically invisible.

    To display the HTTP header information for any website, try this:

    # replace URL with any web page you like:
    $url = 'www.tagesschau.de'
    (Invoke-WebRequest -Met…
  • Power Tips: Using FTP: Uploading File (Part 4)

    PowerShell does not come with cmdlets to download and upload data via FTP. However, you can use .NET for this.

    To upload a file from your local drive to an FTP server, try the code below:

    $localFile = "C:\test.txt"
    
    $username='testuser'
    $password='[email protected]'
    
    [System.Uri]$ur…
  • Power Tips: Using FTP: Downloading Binary File (Part 3)

    PowerShell does not come with cmdlets to download and upload data via FTP. However, you can use .NET for this.

    To download a file from an FTP server in binary mode, try the code below which also illustrates how you can authenticate with explicit credentials:

    $username='testuser'
    $password='…
  • Power Tips: Using FTP: Downloading File (Part 2)

    PowerShell does not come with cmdlets to download and upload data via FTP. However, you can use .NET for this.

    To download a file from an FTP server, try using this code:

    $localFile = "C:\test.txt"
    
    $username='testuser'
    $password='[email protected]'
    
    [System.Uri]$uri = "ftp://${username…
  • Power Tips: Using FTP: Listing Folders (Part 1)

    PowerShell does not come with cmdlets to download and upload data via FTP. However, you can use .NET for this.

    To display the contents of an FTP folder, try using this code:

    $username='testuser'
    $password='[email protected]'
    $ftp='ftp://192.168.1.123'
    $subfolder='/'
    
    [System.U…
  • Power Tips: Discovering Public IP Address

    Using a web service, it is almost trivial to determine your public IP address and information about your ISP:

     
    PS> Invoke-RestMethod -Uri https://ipinfo.io
    
    
    ip       : 84.165.49.158
    hostname : p54a5319e.dip0.t-ipconnect.de
    city     : Hannover
    region   : Lower Saxony
    country  : DE
    loc      : 52.3705…
  • Power Tips: Displaying Warning Dialog (Part 2)

    In the previous tip we created new shortcut files, and you have seen how the CreateShortcut() method provides methods to control almost any detail of a shortcut. Here’s the code again that creates a PowerShell shortcut on your Desktop:

    Now here is a trick that may help you always display the dialog…

  • Power Tips: Displaying Warning Dialog (Part 1)

    Here is a quick code sample that displays a popup warning dialog:

    Add-Type -AssemblyName  System.Windows.Forms
    $message = 'Your system will shutdown soon!'
    $title = 'Alert'
    
    [System.Windows.Forms.MessageBox]::Show($message, $title, [System.Windows.Forms.MessageBoxButtons]::OKCancel,