The joys of software – PowerShell remoting edition

I was happily scripting in PowerShell and the script appeared to work. It remoted to a server, got that state of a few services, if they were running, how much memory they used, etc.

It used – very simplified

$Session = New-PSSession -ComputerName $server
Invoke-Command -Session $Session -ScriptBlock {#Remote code}

So after testing on a single server, I let it lose on all the production servers.  It worked for about 40% of them – the rest did not give a hoot about the script content.

Why?  No idea at the time.  So – what was the differences between the servers? They all had PowerShell 7.x installed, but some where 2016+ while others where 2012R2.  

Changing the remote script to simply retrieve the most current PS version config that the WinRM would provide. 

function Get-PSConfigs { 
    param (
        [String] $server
    )
    Write-Host "--- $server --------------------------------------------------------------"
    $Session = New-PSSession -ComputerName $server
    if ($Session) {
        try {
            Invoke-Command -Session $Session -ArgumentList $server -ScriptBlock {
                Param ([string]$LocName)
                Get-PSSessionConfiguration | sort PSVersion -Descending | Select-Object -first 1
            }
        }
        finally {
            Remove-PSSession -Id $Session.Id
        }
    }
}

This revealed that all the servers that failed only offered PS version 4, and of those that worked, they only reported PS version 5.1.  Why!?  PS 7 was installed! Why didn’t the script run on PS 7?

So, after RTFM a lot, and experimenting a little, it turned out that to enable a configuration for remoting to PS 7, you have to start PWSH 7 with Administrator rights and run “Enable-PSRemoting”.

Only then will you have a PowerShell.7 configuration that you can use with New-PSSession.

function Get-PSSevenResults { 
    param (
        [string] $server
    )
    $Session = New-PSSession -ComputerName $server -ConfigurationName PowerShell.7 
    if ($Session) {
        try {
            Invoke-Command -Session $Session -ArgumentList $server -ScriptBlock {
                Param ([string]$ServerName)
                # remote executed code here
            }
        }
        finally {
            Remove-PSSession -Id $Session.Id
        }
    } 
}

Various error checking/handling removed for clarity

Fun fact – RDPing to 80+ servers, finding pwsh 7, starting it as admin, and running Enable-PSRemoting, is not really much fun at all.

Visual Studio 2022 will be 64-bit 

“Visual Studio 2022 will be a 64-bit application, no longer limited to ~4gb of memory in the main devenv.exe process,” said Amanda Silver, a program management exec in the Developer Division in an April 19 blog post introducing VS 2022. “With a 64-bit Visual Studio on Windows, you can open, edit, run, and debug even the biggest and most complex solutions without running out of memory.”

Source: Visual Studio 2022: Faster, Leaner and 64-bit (More Memory!) — Visual Studio Magazine

TypeScript Handbook Rewrite

Team engineer Orta Therox said

“In the last year, the TypeScript team has heavily focused on ramping up the scale, modernity and scope of our documentation. One of the most critical sections of our documentation is the handbook, a guided tour through the sort of TypeScript code you’ll see in most codebases. We want the handbook to feel like the first recommendation you give for learning TypeScript.”

Source: TypeScript Handbook Revamped as Primary Learning Resource — Visual Studio Magazine

Command Line Parser on .NET5

If you are used to command-line apps, passing arguments to other apps is a very common task. Yes, you can manually parse those values, but once you have multiple parameters it can be a very error-prone code (which is mostly boilerplate anyway). This seems like a problem that someone else might have fixed already, right? So of course we can find a NuGet library that helps us parse these arguments.

TL;DR: https://github.com/commandlineparser/commandline/wiki

Source: Command Line Parser on .NET5 | Windows Dev

Getting Ready for .NET 6 and .NET MAUI

David Ortinau (@davidortinau) writes:

With .NET 6 previews starting right around the corner, it is time to start getting excited for the new .NET Multi-platform App UI (MAUI) that was announced at BUILD 2020. This year of .NET has a lot of amazing things for client application developers.

.NET MAUI is the evolution of Xamarin.Forms, a cross-platform mobile first framework for Android, iOS, and UWP. Building upon 7 years of experience supporting customers from independent developers to some of the world’s largest companies, we are improving the core of the product, speeding up UI rendering, investing in consistent design systems, and extending from mobile to desktop.

Source: The New .NET Multi-platform App UI | Xamarin Blog