-
Notifications
You must be signed in to change notification settings - Fork 3
Activate mfa for group member #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| param( | ||
| [string]$DIR = (Get-Location) | ||
| ) | ||
|
|
||
| if ($DIR -match '.+?\\$') { | ||
| $DIR = $DIR.Substring(0, $DIR.Length-1) | ||
| } | ||
|
|
||
| if (Test-Path -Path "$DIR\password.txt") { | ||
| $username = "[email protected]" | ||
|
|
||
| $secPasswordText = Get-Content "$DIR\password.txt" | ||
| $secPassword = $secPasswordText | ConvertTo-SecureString | ||
|
|
||
| $credentials = New-Object System.Management.Automation.PSCredential ($username, $secPassword) | ||
| } | ||
|
|
||
| if (!$credentials) { | ||
| $credentials = Get-Credential | ||
| } | ||
|
|
||
|
|
||
| Connect-MsolService -Credential $credentials | Out-Null | ||
|
|
||
| Connect-AzureAD -Credential $credentials | Out-Null | ||
|
|
||
| # remove existing Exchange Remote Sessions if any | ||
| Get-PSSession | Where-Object {$_.ComputerName -eq "outlook.office365.com"} | Remove-PSSession | ||
|
|
||
| $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $credentials -Authentication Basic -AllowRedirection | ||
| Import-PSSession $session | ||
| if (!$?) { | ||
| throw "Failed to import Exchange Remote Session" | ||
| } | ||
|
|
||
| # Groups which require a mfa authentication | ||
| $mfaGroups = @{ | ||
|
|
||
| "Group name" = "Distribution Group Object-Id" | ||
|
|
||
| } | ||
|
|
||
| $mfaGroups.GetEnumerator() | ForEach-Object{ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| $groupId = $_.Value | ||
| $groupMember = Get-DistributionGroupMember -Identity $groupId | ||
|
|
||
|
|
||
| # Activate mfa for groups | ||
| foreach ($distUser in $groupMember) { | ||
|
|
||
| $adUser = Get-AzureADUser -ObjectId $distUser.ExternalDirectoryObjectId | ||
|
|
||
| $st = New-Object -TypeName Microsoft.Online.Administration.StrongAuthenticationRequirement | ||
| $st.RelyingParty = "*" | ||
| $st.State = "Enabled" | ||
| $sta = @($st) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kann das vor den Loop verschoben werden, oder muss das Objekt jedes mal neu erstellt werden? |
||
| Set-MsolUser -UserPrincipalName $adUser.UserPrincipalName -StrongAuthenticationRequirements $sta | ||
| Write-Host $adUser.displayname " 2 FA enabled" | ||
|
|
||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,14 +12,19 @@ ermöglicht das automatische Sicherstellen, dass in bestimmten (Teams-)Gruppen | |
| ausschließlich interne Accounts zugelassen sind. | ||
| Dadurch werden unsere internen IT-Policies technisch erzwungen. | ||
|
|
||
| ## Zusätzliche Abhängigkeit | ||
| Um dieses Skript ausführen zu können, muss erst eine weitere Abhängigkeit | ||
| durch einen entsprechenden PowerShell-Befehl installiert werden. | ||
| ## Zusätzliche Abhängigkeiten | ||
| Um diesee Skripte ausführen zu können, müssen erst weitere Abhängigkeiten | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Der Satz hat noch ein paar Typos / Grammatikfehler ;) |
||
| durch einen entsprechende PowerShell-Befehle installiert werden. | ||
|
|
||
| ### [Microsoft Teams Module](https://docs.microsoft.com/de-de/microsoftteams/teams-powershell-overview) | ||
| ```pwsh | ||
| Install-Module MicrosoftTeams | ||
| ``` | ||
| ### [Microsoft MSOnline Module](https://docs.microsoft.com/en-us/powershell/azure/active-directory/overview?view=azureadps-1.0&preserve_view=true) | ||
| ```pwsh | ||
| Install-Module MSOnline | ||
| ``` | ||
| **Achtung**: Microsoft empfiehlt selbst, das Modul nicht mehr zu benutzen, allerdings wurde bis heute keine Alternative vorstellt, mit welchem anderen Modul die MFA aktiviert werden kann. Sobald es eine Alternative gibt, wird das Skript angepasst. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Am besten mit verlinken: AzureAD/azure-activedirectory-powershell#12 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bitte maximale Zeilen länge in der Datei beachten |
||
|
|
||
| ## Konfiguration | ||
| Das Skript wird über zwei Variablen am Anfang konfiguriert: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Warum wird überhaupt die Exchange Shell benötigt? Die Gruppenmitglieder auslesen kann man doch auch schon mit dem
AzureADModul??There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bzw. sogar gleich mit dem
MSOnlineModul? dann braucht es hier nichtmalAzureAD