AlexFilipin / ConditionalAccess

MIT License
266 stars 71 forks source link

Select-MgProfile: The term 'Select-MgProfile' is not recognized as a name of a cmdlet, function, script file, or executable program. #40

Closed pfiene closed 1 month ago

pfiene commented 1 year ago

Working in cloudshell. Get the above error message and drop in to the catch in line 131 of deploy-Policies.ps1

region connect

Import-Module -Name Microsoft.Graph.Authentication Import-Module -Name Microsoft.Graph.Groups Import-Module -Name Microsoft.Graph.Identity.SignIns

if($Endpoint -eq "Beta"){ Select-MgProfile -Name "beta" }elseif($Endpoint -eq "V1"){ Select-MgProfile -Name "v1.0" }else{ Select-MgProfile -Name "beta" } try{Disconnect-MgGraph -ErrorAction SilentlyContinue}catch{} Connect-MgGraph -Scopes "Application.Read.All","Group.ReadWrite.All","Policy.Read.All","Policy.ReadWrite.ConditionalAccess" -TenantId "XXXXXXXXX" -ErrorAction Stop

endregion

Added tenantID to avoid conditional access probe from home tenant - but doesnot help as expected. So i am rooted there

The problem is that the script code is deprecated.

It does a manual Import-Module -Name Microsoft.Graph.Authentication asking in the next line Get-Command -Module Microsoft.Graph.Authentication -Name Select-MgProfile gets a command not recognized

Addendum:

Solved the prob with forcefully removing younger versions of the module Authentication. That Powershell does not give any information without setting Set-PSDebug -Trace 1, if an install-Module command worked or not - it simply comes always back with no comment. And deinstalling is no option, because clean removal of dependend modules does not work properly. Even if the files are gone with remove-Module - force it still believed the module was still there - only detaching and restarting cloudshell did the trick. Not helpful.

Set-PSRepository PSGallery -InstallationPolicy Trusted Install-Module -Name Microsoft.Graph.Authentication -RequiredVersion 1.10.0 Install-Module -Name Microsoft.Graph.Identity.SignIns -RequiredVersion 1.10.0 Install-Module -Name Microsoft.Graph.Groups -RequiredVersion 1.10.0

And detaching and restarting the cloud shell. The shell container is somehow not able to load modules dynamically.

Timsto commented 1 month ago

i think the issue is fixed with the version 2