Sunday, September 17, 2023

PowerShell/Azure Graph API: Improving the Online Documentation (Open Source Contribution)

Microsoft provides an excellent example of how to create a report of Azure App Registrations with expiring secrets and certificates (see: Export app registrations with expiring secrets and certificates). This script uses Microsoft's Graph PowerShell SDK module which is installed as follows:

Install-Module PowerShellGet

In Microsoft's sample the following PowerShell snippet is included in two separate locations in the code:


Obviously, that code could be more simply written as:


I logged into Github.com, edited Microsoft's example, and created a pull request. Withing 24 Hours it was approved and my change as adopted meaning the online documentation was updated to include my change:







Friday, August 25, 2023

Docker: Error Message "Windows Containers are not supported on your version of windows"

On a Windows host where Docker is configured to use Windows (versus Linux) contains the following error message, "Windows Containers are not supported on your version of windows", can be encountered. There are multiple reasons for this error message but one of the most common is that it is only possible to run Windows containers on Windows Pro or Windows Enterprise edition. Docker cannot run Windows containers on Windows Home or Windows Education edition.

Docker's setup instructions for Windows can be found at Install Docker Desktop on Windows. A the top of this web page, under System Requirements is the following (as of August 23, 2023):


There is nothing in the above documentation stating that Windows Home and Education only support Linux containers. There is nothing in the above documentation stating that in order to supports both Linux and Windows containers Windows Pro or Windows Enterprise is required.

Note: I have submitted a Pull Request to Docker's documentation repo (Docker docs)  requesting the text be changed to include the sentences "Home and Education editions support only Linux containers. Pro and Enterprise editions support Windows containers and Linux containers." alongside the Windows 11 and Windows 10 system requirements.

Dockers Windows install documentation (Install Docker Desktop on Windows) does include a note well below the "System requirements" tab that presents which editions of Windows are required in order to run Windows containers:




Monday, August 14, 2023

Windows 10: Install Windows Terminal Without Windows Store

I was handed a laptop for a project that was Windows 10. Windows Terminal was not installed. On Windows 11 22H2, Windows Terminal is the default "command line experience" (see Windows Terminal is now the Default in Windows 11). Microsoft recommends installing Window Terminal using the Windows Store (see Windows Terminal). The laptop I was given was a corporate laptop and Windows Store was unavailable.

It is possible to download and install Windows Terminal from Windows Terminal Releases. Below are assets for Windows Terminal v1.17.11461.0:


The easiest way to install is to just download and invoke the MSIX bundle.


Sunday, August 13, 2023

PowerShell (failure): New-TemporaryFile Cannot Create a New Filename without Creating a File

In PowerShell the standard way to create a temporary filename is to invoke the System.IO namespace's Path class's GetTempFileName method. To be clear, only a filename is retrieved and no actual file is created. An example of GetTempFileName being invoked by PowerShell is as follows:

[string] $tempFilenameFromCsharp = ` 
               [System.IO.Path]::GetTempFileName() 

The results of the code above will vary because the filename is randomly generated and the method uses a user's environment variable, $env:TEMP. An example of the value assigned to $tempFilenameFromCsharp when the code snippet above being invoked is as follows:

C:\Users\jann\AppData\Local\Temp\tmpCF88.tmp

The New-TemporaryFile PowerShell cmdlet creatse a new temporary file and returns a corresponding instance of the System.IO.FileInfo class whihc include information such as the name of the file created.

My theory that I felt had a 20% chance of working: Invoke New-TemporaryFile with the -WhatIf command-line option and instead of creating a temporary file, the comdlet will return the name of the temporary file that would have been created.

For those that need a reminder, the WhatIf command-line option is defined as follows (see: WhatIf Switch):


My attempt to use New-TemporaryFile to create filename without creating a file was as follows:

[System.IO.FileInfo] $tempFilenameFromPowerShell = `
                         New-TemporaryFile -WhatIf -ErrorAction Stop

The output from invoking the above command is follows:


The following code tests if the $tempFilenameFromPowerShell variable is assigned to $null:


Since $tempFilenameFromPowerShell is set to $null so New-TemporaryFile combined with -WhatIf does not create a new filename. 

Not every idea we try works.

Saturday, July 29, 2023

PowerShell: azcopy Working Around the New Version Available Information Message

One of the most optimal ways to upload and download blobs to/from Azure storage containers is the azcopy utility (see azcopy). This utility can be used from the command-line or can be included in a PowerShell script such as the following:

[string] $azCopyPath = 'C:\bin\azcopy.exe'
[string] $blobSasUrl = 'put your own storage URL plus SAS token here'

& $azCopyPath list $blobSasUrl 

The above example is one of cases where azcopy is not used to upload or download files/folders/blobs. The "azcopy list" command will list the blobs for a given storage URL (see azcopy list).

The output from the above command is as follows:

INFO: azcopy.10_19_0.exe 10.19.0: A newer version 10.20.0 is available to download

INFO: a.txt;  Content Length: 1.20 KiB
INFO: b.txt;  Content Length: 1.20 KiB
INFO: c.txt;  Content Length: 1.20 KiB
INFO: d.txt;  Content Length: 1.20 KiB

The desired output is as follows (sans the upgrade available message):



The azcopy utility creates a message on the  information data stream that an upgrade is available. The output from azcopy list is also provided on the information data stream. There is no way to suppress the "newer version is available to download" message.

The following PowerShell code uses "Select-Object -Skip" (see Select-Object) to remove the upgrade informational message and returns only the data retrieved by azcopy list:

[string] $upgradeAvialableSuffix = 'is available to download'

function Get-AzCopyList {
    param(
        [Parameter(Mandatory=$true)]
        [string] $azCopyFilePath,
        [Parameter(Mandatory=$true)]
        [string] $blobUrlWithSasToken
        )

    [string[]] $results = & $azCopyPath list $blobSasUrl 

    # always return an array
    if (($null -eq $results) -or (0 -eq $results.Length)) {
        return ,[string[]]::new(0)
    }

    [int] $index = 0

    if ($results[0].EndsWith($upgradeAvialableSuffix)) {
        [bool] $endMarkerFound = $false

        foreach ($result in $results) {
            $index++
            if (0 -eq $result.Length) {
                $endMarkerFound = $true
                break
            }
        }

        if ($false -eq $endMarkerFound) {
            throw "Upgrade message not delineated from results $($result[0])"
        }
    }

    return $results | Select-Object -Skip $index 
}

[string] $azCopyPath = 'C:\bin\azcopy.exe'
[string] $blobSasUrl = 'put your own storage URL plus SAS token here'
[string[]] $results = Get-AzCopyList $azCopyPath $blobSasUrl

$results

The output from above code is:
INFO: a.txt;  Content Length: 1.20 KiB
INFO: b.txt;  Content Length: 1.20 KiB
INFO: c.txt;  Content Length: 1.20 KiB
INFO: d.txt;  Content Length: 1.20 KiB



Tuesday, July 4, 2023

Docker/Windows: Installation Requirement "BIOS-level Hardware Virtualization"

Installing/running Docker on Windows requires that WSL be installed (see Install Docker Desktop on Windows). According the aforementioned write up, WSL has the following hardware requirements:


While running Windows it is possible to check if hardware virtualization is enabled at the BIOS level. To check if this is enabled, launch Task Manager (Ctrl-Alt-Delete) and from Task Manager select the Performance blade:


Notice in the lower right corner there is a box high added to the screenshot showing Virtualization Enabled.

Wednesday, June 7, 2023

PowerShell: Installing the latest version of Pester

Before installing the latest version of Pester, uninstall the legacy version of Pester (Pester 3.x) which is installed with most modern versions of Windows (see PowerShell: Uninstalling Pester 3.0). On a machine with PowerShell 5.0 or later install, the latest version of Pester can be installed as follows without running as administrator:

Install-Module -Name Pester

Once install verify that version of Pester is the most recent:

(Get-Module -ListAvailable Pester).Version

An example of installing Pester is as follows (not that a user is prompted to accept the modules being installed):

E:\Users\Jann\PowerShellRepos> Install-Module -Name Pester

Untrusted repository

You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository

cmdlet. Are you sure you want to install the modules from 'PSGallery'?

[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): A