Powershell core on Mac / Linux

A quick tip on my experiments around Powershell Core in Mac / Linux

I am specifically messing around with the Azure AD + Microsoft teams functionality.

Tips to follow:

  1. az command within powershell will point to the az installed on the base linux and not the powershell az command. keep in mind this is critical specially if your tool makes a call to az command

  2. Following repositories and modules were required to get a functional replacement of windows powershell environment

# Standard AZ Module 

Install-Module Az


# Register an alterantive Repository
Register-PackageSource -Trusted -ProviderName 'PowerShellGet' -Name 'Posh Test Gallery' -Location 'https://www.poshtestgallery.com/api/v2/'


Install-Module Microsoftteams


Install-Module -Name 'AzureAD.Standard.Preview' -Force -Scope CurrentUser -SkipPublisherCheck -AllowClobber 

  1. Loading modules at the start
mkdir ~/.config/powershell/
subl $profile

This will open the file $profile
add Import-Module Statements in it

Write-Output "Loading Modules"
Import-Module Az
Import-Module MicrosoftTeams
Import-Module AzureAD.Standard.Preview
Write-Output "Loading Done"
  1. Debugging tips
  • echo works as usual

  • add this at the start of your script

$ErrorActionPreference = "Stop"

This will stop processing if any error is occured

  • Check if a specific variable has a value or not
$abc=
if ($abc -ne $null)
{
    echo "Lets move onwards"
}
Else
{
    echo "Error"
    Exit
}
  1. Multiple features are not available in Powershell core
  2. If we need to pass credentials multiple time we generally end up using Get-Credentials

This feature is not available so effectively if you want to run azure or teams automation you need to be prior connected as connection happens via auth url with a auth code

  1. PasswordProfile which is generally an object of Microsoft.Open.AzureAD.Model.PasswordProfile is not directly available and hence we installed the module AzureAD.Standard.Preview otherwise we get an error message that
New-Object: Cannot find type [Microsoft.Open.AzureAD.Model.PasswordProfile]: verify that the assembly containing this type is loaded.

however on hindside the function which needs password profile in powershell core is limited to only securestring password values and hence this is not required to be loaded at all.

Note: Article originally published on now defunct : https://til.anantshri.info/post/powershell_mac_linux/

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top