Friday, February 17, 2023

Some remarks with PowerShell Core and Azure / PowerBI

All my scripts are under Windows and for automation what means that authentication to Azure is made using a Service Principal, a Register App. 
I'm working from a VM, so I want to use a certificate for Authentication. 

Working with a Proxy
Most people nowadays work behind an enterprise proxy. 
pwsh makes the live more easy behind a proxy - it gets all configuration from IE, so you can even use a pac file - but also implement some diferences. 
With older PowerShell versions, a common configuration was:

$proxyUri = "http://MyProxyUrl:MyProxyPort"
[System.Net.WebRequest]::DefaultWebProxy = new-object System.Net.WebProxy ($proxyUri, $true) 

With PowerShell core this is now: 

$proxyUri = "http://MyProxyUrl:MyProxyPort" 
[System.Net.Http.HttpClient]::DefaultProxy = New-Object System.Net.WebProxy( $proxyUri ) 

PowerShell AzureAD 
It's almost impossible to use a certificate to authenticate with AzureAD module. It works fine under an user, but installing the certificate as computer level normally it will not work. I give up to use AzureAD module because of this error: 
"Connect-AzureAD Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly

I had no luck finding a workaround for this problem..

PowerShell Microsoft. Graph 
Shifting to Microsoft. Graph was almost transparent. Only permissions are now with a different setup in Azure. Make sure that permissions are assigned to application:

 

Parameter -Scope is not available for Service Principals, so all permission configuration is on Azure. 
After connection the available permissions can be listed using:

 (Get-MgContext).scopes
User.Read.All

 

No comments:

Post a Comment