Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions Sync-Groups/Activate-Mfa.ps1
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
Copy link
Member

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 AzureAD Modul??

Copy link
Member

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 MSOnline Modul? dann braucht es hier nichtmal AzureAD

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{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$_.name wird nie zugegriffen, GetEnumerator() ist damit unnötig...
$_.name könnte aber ausgegeben werden, um anzuzeigen, welche Gruppe gerade verarbeitet wird

$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)
Copy link
Member

Choose a reason for hiding this comment

The 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"

}

}
11 changes: 8 additions & 3 deletions Sync-Groups/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The 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:
Expand Down
11 changes: 1 addition & 10 deletions Sync-Groups/Sync-Groups-Admins.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,7 @@ if (!$credentials) {
}

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"
}

Connect-ExchangeOnline -Credential $credentials -ShowBanner:$false | Out-Null


# Alle Gruppen initalisieren
Expand Down
10 changes: 1 addition & 9 deletions Sync-Groups/Sync-Groups.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,7 @@ if (!$credentials) {

Connect-AzureAD -Credential $credentials | Out-Null
Connect-MicrosoftTeams -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"
}
Connect-ExchangeOnline -Credential $credentials -ShowBanner:$false | Out-Null

<##
# a null-safe wrapper around Compare-Object
Expand Down