juvchan juvchan - 1 year ago 84
Powershell Question

How to get Azure PowerShell modules versions listing running in a Azure Function?

I have created a Timer Trigger Azure Function using PowerShell as the programming langauge.

I want to know what are the Azure PowerShell modules and their respective versions available in the Azure Function PowerShell environment. I try to use the PowerShell code below to get what I want.

Get-Module -ListAvailable -Name *Azure*

The returned result is as below without the versions.
enter image description here

So the question is what should/could I do in the Azure Function to get the Azure PowerShell modules and versions?

Note: The same PowerShell code running on local Windows PowerShell is able to list the Azure PowerShell modules name, version and other details.

Answer Source

As you're just this code and relying on the output being written to the log; it will use the default output view for a the type that's defined for the host; and here resulting in a ToString() on the name.

When you're running the cmdlet on your client (from powershell or ISE) it will use whatever output view is defined for that type on your host; resulting in the output being processed differently (types and formatting).

You could e.g. select to format your own custom output to list the information you'd like.


Get-Module -ListAvailable -Name *Azure*|ForEach-Object { "Name={0};Version={1};" -f $_.Name , $_.Version}

It will output the name and the version in the output log, separated with ;. If you'd want extra information you could add it in the string format function or add more complex outputs in the Foreach.

If you're interested in how output and default formatting works, I'd recommend this MSDN article