Functioning of Azure Active Directory Module for Windows PowerShell - powershell

I have been trying to install the Azure Active Directory Module for Windows for Powershell. So far I have not been able to find a combination of the Sign-In Assistant and Powershell module versions that allows me to create a connection in a Powershell session. My measure for success has been to run the Connect-MsolService cmdlet to create such a connection. I have tried it both from the command line and in a script. The (few) forum and blogs posts that reference this functionality have been very contradictory.
I am using the same credentials that I use to log into manage.windowsazure.com.
As to the specifics I have the following configuration:
Windows Server 2012R2
Powershell version 4.0 ($PSVersionTable.PSVersion)
Microsoft Online Services Sign-In Assistant version 7.250.4556.0
Windows Azure Active Directory Module for Windows Azure version
1.0.8362. The version number is based on the command (get-item C:\Windows\System32\WindowsPowerShell\v1.0\Modules\MSOnline\Microsoft.Online.Administration.Automation.PSModule.dll).VersionInfo.FileVersion
My questions are as follows:
What versions work on Windows Server 2012R2?
Is there a specific .Net version that I might be missing?
Am I looking at it wrong? For example is the cmdlet
Connect-MsolService not the metric to be using? Is there another way
that I might verify that I have a connection?
My understanding is that the Powershell cmdlets, as well as all the other methods for managing Azure, are based on the REST API's. Would that be a better way to go? Of course I would not be able to dynamically enter commands, but I would be able to validate credentials etc.

Are you trying to authenicate with an MSA account? Try connecting with a Global Admin AAD account (eg. globaladminuser#tenant.onmicrosoft.com).

Related

Do we need Active Directory Domain Controller to run any PowerShell commands?

I am trying to run a Powershell script which calls Get-ADUser command.
Something similar to this question Powershell Active Directory commands not working in Powershell session
But I am getting error Get-ADUser : Unable to find a default server with Active Directory Web Services running.
I have Imported the ActiveDirecotry Module and also run the Connect-AzureAD command.
Is it must to have the AD domain controller for running the Powershell commands?
Can we run Powershell commands like Get-ADUser just using the credentials of the Active Directory Admin?
Yes. The ActiveDirectory module cmdlets installed with RSAT Tools need to communicate with Active Directory infrastructure to retrieve information about the domain and objects stored within it.
This generally (if not wholly) encompasses other first-party PowerShell modules integrating with Active Directory services outside of ADDS as well; the services need to be communicable for the PowerShell modules to function correctly.
However, you have a fundamental misunderstanding of the differences between Active Directory and Azure AD. They are separate services and do not function the same way. At a high level:
Active Directory is the self-hosted on-prem directory services solution provided by Microsoft. This is the fully-functional AD you have known and loved since 1999.
Generally administered with the RSAT Tools feature and the ActiveDirectory PowerShell module it installs.
Azure AD is a completely separate managed-directory service available from Microsoft in Azure. It does not provide anywhere close to a 1:1 feature parity with on-prem Active Directory. That isn't to say it is a lesser product; it is simply a different product.
It is worth a mention that there are handy features available with Azure AD that you don't get with on-prem Active Directory. Generally administered via the Azure Portal, or the Az.* PowerShell modules available from the PowerShell Gallery.
You cannot use the ActiveDirectory module to manage Azure AD just as you cannot use the Az.* modules to manage on-prem Active Directory. You can have both modules installed on a single system of course, you just need to use the correct module with the correct service.

Connecting to Exchange Online with PowerShell and Modern Authentication (without any dependencies)

I want to connect to Exchange Online using PowerShell and modern authentication without depending on any modules or dll's.
There's a module available for modern authentication to Exchange Online that depends on the CreateEXOPSSession.ps1 and Microsoft.Exchange.Management.ExoPowerShellModule.dll, I have decompiled the latter and found that it generates an access token as such:
TokenInformation accessToken = TokenProviderFactory.Instance.CreateTokenProvider(new TokenProviderContext(authType, "a0c73c16-a7e3-4564-9a95-2bdf47383716", this.AzureADAuthorizationEndpointUri, acquireTokenEndpoint, this.UserPrincipalName, this.Credential, clientAppRedirectUri, (Action<string>) (s => this.WriteWarning(s)))).GetAccessToken();
I want to request the access token is the same way in PowerShell but I can't seem to get the right authentication context and method of retrieving the access token.
Any ideas?
You have to have an MSOL connection and create a remote session to EXO to use EXO cmdlets. There is no workaround for this.
The dependencies are there for a reason. The backend plumbing of MSOL / Azure / O365 expects what it expects, and skirting it will just lead you down a very frustrating/hair-pulling activity.
That token is an Azure AD as MA/ADAL requires that you have an Azure AD Premium license.
MA requires use of the ADAL API/DLL. This is like asking to programmatically connect to and use Exchange on-prem EAS/EWS services without using the API/DLL, that's not a thing either.
So, no matter how you look at this, there will be dependencies, as noted below. So, if you are serious about this effort, you need to really dig into what MA really is and how it's plumbing really works. Also, MFA must be already enabled for you and users, either in O365 and or the ADAL MFA settings in Azure.
Modern Authentication – What is it?
Modern Authentication brings Active Directory Authentication Library (ADAL)-based sign-in to Office client apps across platforms.
Microsoft identity platform authentication libraries
There is also an ADAL module on the MS PowerShellGallery.com.
Microsoft.ADAL.PowerShell 1.12
ADAL module for PowerShell
https://www.powershellgallery.com/packages/Microsoft.ADAL.PowerShell/1.12
Functions
Get-ADALAccessToken Clear-ADALAccessTokenCache
Examples are here:
Microsoft.ADAL.Powershell ```
####Example 1 This example acquire accesstoken by using RedirectUri from contoso.onmicrosoft.com Azure Active Directory for PowerBI
service. It will only prompt you to sign in for the first time, or
when cache is expired.
Get-ADALAccessToken -AuthorityName contoso.onmicrosoft.com `
-ClientId 8f710b23-d3ea-4dd3-8a0e-c5958a6bc16d `
-ResourceId https://analysis.windows.net/powerbi/api `
-RedirectUri "http://yourredirecturi.local"
See also:
Azure-AD-Authentication-with-PowerShell-and-ADAL
This is a set of really simple PowerShell scripts which allow you to get access tokens with Azure Active Directory using ADAL.
and this...
ADAL and PowerShell

Azure AD - Custom Application Roles via Powershell

I've been playing with RBAC in Azure AD, in particular custom application roles.
It all works well, but is a bit manual, i.e. downloading, editing and uploading the manifest and then assigning each user/group to one of these roles via the management portal.
Is there a way to do that via powershell or even code, say the Graph API?
If not, I presume it's a planned feature, so does anyone know a the likely ETA?
Right now this feature is not available via the AAD PowerShell Module, but it will find its way there eventually. We are working on releasing a new PowerShell module soon that sits atop ADAL which means we will soon be making cmdlets that directly target the Graph API.
For now, you can make direct queries using the Graph Client Library or pure REST calls. I believe an example of setting Application Roles should be available in this sample:
https://github.com/Azure-Samples/active-directory-dotnet-graphapi-console
I hope this helps!
Shawn Tabrizi
Before you can use Windows PowerShell to manage RBAC, you must have the following:
Windows PowerShell, Version 3.0 or 4.0. To find the version of Windows PowerShell, type:$PSVersionTable and verify that the value of PSVersion is 3.0 or 4.0.
Azure PowerShell version 0.8.8 or later.
To get detailed help for any cmdlet that you see in this tutorial, use the Get-Help cmdlet.
Get-Help <cmdlet-name> -Detailed
For example, to get help for the Add-AzureAccount cmdlet, type:
Get-Help Add-AzureAccount -Detailed
Since RBAC only works with Azure Resource Manager, the first thing to do is to switch to Azure Resource Manager mode, type:
PS C:\> Switch-AzureMode -Name AzureResourceManager
Here is the complete tutorial on
https://azure.microsoft.com/en-us/documentation/articles/role-based-access-control-powershell/

Different with Microsoft Azure AD Module PowerShell and Microsoft Azure Powershell

I try run command Set-MsolDomainAuthentication with Microsoft Azure Active Directory Module for Windows PowerShell. But i get exception, when try connect to my azure account(connect-msolservice). I type email and password, then i get:
I try find solution in Google, Azure Support but everything what i find is useless.
On my system, I have an application which is called Microsoft Azure PowerShelllink. In this app, i can connect with my azure account, through command Add-AzureAccount. But this time, i don't find analogue to Set-MsolDomainAuthentication.
This command exists in Azure PowerShell?
I can change Azure AD other way, like command Set-MsolDomainAuthentication? Maybe Azure Admin Panel? Or GraphApi?
I had a similar issue with Powershell. This exception i getting when I try logging credential from account MicrosoftLive. Powershell required account in your domain.
So:
Create a new user in a azure domain in role GlobalAdmin, change password this user, by logging in Office365, enter the PowerShell Credential this user.
Good luck.

How to control Azure VMs using Powershell

Hello I´m trying to automate AZURE VM management like Amazon EC2.
Is there any way to manage AZURE VM from Powershell like Amazon EC2 API ?.
I can´t find API easily documentation or how to do it.
Thanks in advance :)
Windows Azure Management Cmdlets lists a number of AzureVM cmdlets.
Add-AzureDataDisk : Adds a new data disk to a virtual machine object.
Add-AzureProvisioningConfig : Adds the provisioning configuration to a Windows Azure virtual machine.
Add-AzureEndpoint : Adds a new endpoint to a Windows Azure virtual machine
Export-AzureVM : Exports a Windows Azure virtual machine state to a file.
.....and tonnes more
Do these not cover what you need?
Windows Azure has a REST-based API for just about everything, including the management API. Additionally, the API has a corresponding set of Windows Azure PowerShell cmdlets that you can call, which essentially lets you automate your entire deployment via PowerShell.
The most recent version, 2.2.2, has the ability to persist subscription settings, obviating the need for repeating parameters such as subscription ID and certificate thumbprint. Michael Washam, Technical Evangelist, blogged about v2.2.2 here.