r/PowerShell • u/TheLazyAdministrator • Feb 05 '19
PowerShell Function to Connect to All Office 365 Services With Support for MFA
https://www.thelazyadministrator.com/2019/02/05/powershell-function-to-connect-to-all-office-365-services-with-support-for-mfa/4
u/KaliUK Feb 05 '19
Is there anything Azure MFA needs in order to be setup? We have it setup but it’s not sending the code. Would I use these scripts, or are they just to enable/connect to powershell sessions?
1
u/TheLazyAdministrator Feb 05 '19
do you have the proper module for MFA? Its downloaded from your tenant. LMK
1
u/KaliUK Feb 05 '19
Yes, I installed the Azure NPS extension, and NPS setup, but it’s not requesting verification when I go to RDWEB.
1
u/TheLazyAdministrator Feb 05 '19
? I’m confused a bit on any reference to NPS or RDS. Can you expand a bit
2
u/800oz_gorilla Feb 05 '19
I think you're not understanding.
The MFA extension that you put on an NPS server allows you to take internal authentication requests (like Radius, dot1x Wifi, etc) and redirect it to Azure for MFA approval once it passes the internal checks (group membership, password, client ip address, etc). This allows you to get around having to build your own MFA server and maintain it. Simply turn it on in the cloud for the user and point your NPS server to it.
This extension doesn't apply to OP's post. OP is talking about connecting a powershell module to O365's cloud services for administration, and his account is MFA enabled there. So rather than open a new powershell window for each O365 service, he wrote a script that connects to all of them. The MFA piece gets thrown into this by Microsoft being stupid and not updating powershell to sense MFA and use it if enabled. There's a separate command you have to run/import in order for powershell to use modern authentication (mfa) instead of traditional. So he put that in his script as well.
As far as your issue, I have limited understanding of NPS, but I've set it up for Wifi access. You have to make sure you have your client's properly identified (client meaning the device you're trying to remote into), your connection request policy and your network policies all set up. And if you're trying to do a range of client IPs, you need to use regular expressions to properly identify the range.
2
u/KaliUK Feb 06 '19
Yeah, I think your right, it’s outside the scope of the OP’s post. I’ll make a post somewhere with all the details and post the link here if you guys are interested.
2
u/efiggy Feb 06 '19
Very awesome! Would you consider adding an option to install modules if they're not available? Are those modules even in PSGallery? I can't remember now. In any case, great job and thanks for sharing!
4
u/TheLazyAdministrator Feb 06 '19
Yes working on that now. Most are available on the PSGallery. So it will need admin rights to install. The only one not available is the exchange MFA one.
2
3
u/Mkep Feb 05 '19
Oh it’s a miracle, I’ve been looking into doing this recently because that separate power shell console is annoying to have to launch m
12
u/a-rich Feb 05 '19 edited Feb 05 '19
Nice.
What about adding support for trusted locations?
I wrote a similar script for me and my team to connect to O365 services, but since we have trusted locations enabled with some of our static IPs, they dont have to go through MFA when in one of our offices.
The script calls http://ipinfo.io/json and checks against an array of IPs in the script, so there would be some user config required, but its minimal.
And when they're offsite the MFA option will kick in.