Enter Office 365 Shell Multi-Factor Authentication credentials inside Powershell - powershell

I've been trying to find a way to enter the username, password and token code for the Office 365 shell directly into the terminal and not have the normal secondary GUI window pop-up. Currently I have a basic script that logs in with:
Import-Module $((Get-ChildItem -Path $($env:LOCALAPPDATA + "\Apps\2.0\") -Filter Microsoft.Exchange.Management.ExoPowershellModule.dll -Recurse).FullName | Where-Object {$_ -notmatch "_none_"} | Select-Object -First 1)
Connect-MSOLService
Import-PSSession (New-ExoPSSession -UserPrincipalName USER#domain.tld) -AllowClobber -DisableNameChecking
Is it even possible to use strictly the TUI over the GUI for entering credentials?

Don't guess at how to do X or Y. It will just lead you down a very frustrated path. Always look to the help files and online docs.
What you are trying to do is a common practice, these days, and fully documented from Microsoft and many other web resources. There are specific module to assist with this use case.
Connect to Exchange Online PowerShell using multi-factor authentication
Connect to Exchange Online PowerShell by using MFA
1.On your local computer, open the Exchange Online Remote PowerShell Module ( Microsoft Corporation > Microsoft Exchange Online Remote
PowerShell Module).
2.The command that you need to run uses the following syntax:
Connect-EXOPSSession -UserPrincipalName <UPN> [-ConnectionUri <ConnectionUri> -AzureADAuthorizationEndPointUri <AzureADUri>]
Connect to Office 365 PowerShell
Step 2: Connect to Azure AD for your Office 365 subscription
> To connect to Azure AD for your Office 365 subscription with an
account name and password or with multi-factor authentication (MFA),
run one of these commands from a Windows PowerShell command prompt (it
does not have to be elevated).
Exchange Online PowerShell Module has been around since circa 2016 from the MFA PowerShell team
There is even a script from the gallery, that specifically for EXO using MFA.
Connect to Exchange Online PowerShell using multi-factor authentication (MFA)
If you want to use multi-factor authentication (MFA) to connect to
Exchange Online PowerShell, you can't use the instructions at regular
Connect to Exchange Online PowerShell to use remote PowerShell to
connect to Exchange Online.
Download : MFA.ps1

Related

How to connect to LDAP from Powershell in another server

I have to query my Active Directory from another windows server using PowerShell through LDAP. I got LDAP connection details, port number, login credential. However, after googling for hours I couldnt find a soultion to connect PowerShell to LDAP. I tried below cmdlet but all returned the error "the term ** is not recognised as the the name of a cmdlet".
New-AdfsLdapServerConnection
Test-LDAPConnection
Can someone please help. I want to connect to my LDAP and run a simple command like
Get-ADGroup -Filter 'Name -like "Sec-abc-xyz-123-U"'
later I want to write my full Powershell script and then use Task scheduler to automate my powershell script. Can someone please let me know how I could connect to LDAP?
As #Santiago Squarzon suggested, you need to install RSAT to use the AD PS Module

Connect-MsolService blank screen

I want to setup SSO between GSuite (as Identitiy provider "IdP") and Microsoft 365.
When I want to connect to Microsoft 365 through powershell, I use the following command:
Install-Module MSOnline
Import-Module MSOnline
$msolCred = get-credential
Connect-MsolService -credential $msolCred
When I run the last command, I'll receive the following empty Microsoft login screen:
I thought maybe it's because of onedrive and other windows 10 services, I have logged out everywhere but still doesn't work. If someone can guide me, it would be great.
I have solved the problem by decreasing security of internet options (from control panel) from high to medium.

Azure AD - How to automate access for a Global administrator role to a User role in order to "Access files" from User role OneDrives?

I am working on proofing out if there is a way to automate a Global administrator's Azure AD access for other User role accounts in the same tenant to grant access to OneDrive.
If you navigate to portal.office.com and then click on a user's name, that will bring up some settings for that user. The setting I am referring to is under the dropdown for OneDrive Settings, (see attached image).
Is there a way to automate this process via some PowerShell cmdlet?
Solved
I found an article that shows how to run PowerShell commands via the SharePoint Online Management Shell
Tutorial link has the section for Prerequisites for setup: Easy Manage Multiple Office 365 Tenants with Windows PowerShell
Actual PowerShell commands:
$site = Get-SPOSite -Identity https://mydemo-my.sharepoint.com/personal/sarad_mydemo_onmicrosoft_com
Set-SPOUser -Site $site.Url -LoginName admin#mydemo.onmicrosoft.com -IsSiteCollectionAdmin $true
Tutorial: How to Get Administrative Access to the OneDrive for Business Environment for a User

Need a msol command like set-mailbox -emailaddresspolicyenabled for hybrid server

We have office 365 and a hybrid server. It is set to sync 1 way from hybrid to o365.
We are wanting to run
Set-mailbox "$usertodisable#domain.com" -EmailAddressPolicyEnabled $true
on the hybrid server.
The problem is the hybrid server doesn't support/have the -mailbox commands. It has the -msol commands. I can not find an msol command that changes the emailaddresspolicyenabled. I also don't see a module to load for -mailbox.
We are running this command directly off the server itself. Any help would be great. Thank you and have a great day.
Use the Set-RemoteMailbox cmdlet to modify remote mailboxes. A remote mailbox is a mail user in Active Directory that's associated with a mailbox in the cloud-based service.
So what you are searching for seamed to be:
Set-RemoteMailbox -Identity "$usertodisable#domain.com" -EmailAddressPolicyEnabled $True

How to enable powershell on azure web role?

I want to remote PowerShell connection.
How to enable PowerShell on windows azure web role ?
...or, Is it possible ?
Thanks!
You will need to enable website diagnostic logging and then you can use Powershell CMDLets to save or get the latest parts of the log file. How to enable Diagnostics Logging for Azure Web Sites.
These are the cmdlets you'll need to use inside Powershell to get the log files from your website:
Get-AzureWebSiteLog -Name webappname -Tail
Save-AzureWebSiteLog -Name webappname