├── .gitattributes
├── .gitignore
├── AzureAD
├── AddUserToAzureADRole.ps1
├── BulkAddLicenceConditional.ps1
├── BulkAddLicences.ps1
├── BulkAddUserToAzureADRoles.ps1
├── BulkDisableGuestAccounts.ps1
├── BulkEnableGuestAccounts.ps1
├── BulkRemoveGuestsWithUnacceptedInvites.ps1
├── BulkRemoveLicences.ps1
├── BulkReplaceLicences.ps1
├── FixOnlineUserUPN.ps1
├── GetADGUIDFromAzureAD.ps1
├── GetAllAndUnacceptedGuestsToCSV.ps1
├── GetAzureADAssignedRoles.ps1
├── GetLicencesAllUsers.ps1
├── GetLicencesForUserList.ps1
├── GetUsersFromPlanID.ps1
├── InviteGuestAndAddToGroup.ps1
└── RemoveAllLicencesFromUserList.ps1
├── Exchange
├── CheckMailboxStatsAccessAndPermissions.ps1
├── FindUsersWithMismatchedDomains.ps1
├── GetAllForwardingRules.ps1
├── GrantCalendarDelegateAccess.ps1
└── LockdownMailbox.ps1
├── ExchangeWithAADConnect
├── BulkRemoveProxyAddressesRemote.ps1
├── CompareRemoteMailboxesToO365.ps1
├── DisableRemoteMailUser.ps1
├── GetMailboxesBasedOnPrimarySMTP.ps1
└── README.md
├── ExchangeWithMFA
├── AddGuestsToGAL.ps1
├── AddRoomCalendarEditors.ps1
├── BlockEmailForwardingToSpecificDomains.ps1
├── BulkRemoveProxyAddresses.ps1
├── EnableExchangeModernAuth.ps1
├── EnableMailboxAuditing.ps1
├── FindUsersWithMismatchedDomains.ps1
├── GetDistributionGroupsAndMembers.ps1
├── GetMailboxPermissionsForList.ps1
├── GetSharedMailboxPermissions.ps1
├── README.md
├── ResetCalendarDefaultPermissions.ps1
├── SetupForwardingForListOfUSers.ps1
└── SetupRoomMailbox.ps1
├── Intune
└── ScheduledBitlockerKeyBackup.ps1
├── LICENSE
├── MSOnline
├── ADGUIDToImmutableID.ps1
├── BulkAddLicenceConditional.ps1
├── BulkAddLicences.ps1
├── BulkChangeMFASetting.ps1
├── BulkChangeOnlineUserUPN.ps1
├── BulkDisableMFA.ps1
├── BulkEnableMFA.ps1
├── BulkRemoveLicence.ps1
├── BulkReplaceLicence.ps1
├── ChangeOnlineUserUPN.ps1
├── CompletelyDeleteAUser.ps1
├── FixDuplicateSyncObject.ps1
└── ImmutableIDToADGUID.ps1
├── OneDrive
├── GetOneDriveQuotas.ps1
├── IncreaseOneDriveQuota.ps1
├── IncreaseOneDriveQuotaAll.ps1
├── OneDriveForBusinessAddAdmin.ps1
├── OneDriveForBusinessRemoveAdmin.ps1
└── ResetOneDriveQuotas.ps1
├── README.md
├── SharePoint
├── CheckAllSitesForUser.ps1
└── GetSiteDetails.ps1
└── SkypeForBusiness
├── BulkEnableAudioConferencing.ps1
├── EnableAudioConferencingForList.ps1
├── EnableSkypeModernAuth.ps1
├── ExportAll3rdPartyConferencing.ps1
├── Remove3rdPartyConferencing.ps1
├── RemoveACPForUserList.ps1
└── UpdateAudioConferencingForList.ps1
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Ignore Mac system files
2 | ._*
3 | .AppleDB
4 | .AppleDesktop
5 | .AppleDouble
6 | .DS_Store
7 | .LSOverride
8 |
9 | # Ignore Windows system files
10 | *.tmp
11 | ehthumbs.db
12 | ehthumbs_vista.db
13 | Thumbs.db
14 |
--------------------------------------------------------------------------------
/AzureAD/AddUserToAzureADRole.ps1:
--------------------------------------------------------------------------------
1 | # Script to add user to an AzureAD role
2 |
3 | <#
4 | You can find a list of available roles in the following Microsoft article
5 | https://docs.microsoft.com/en-us/azure/active-directory/active-directory-assign-admin-roles-azure-portal
6 | Double check using Get-AzureADDirectoryRole as they don't always have the same name in PowerShell as the GUI
7 |
8 | Built from the code example on the following Mircosoft page
9 | https://docs.microsoft.com/en-us/powershell/module/azuread/add-azureaddirectoryrolemember?view=azureadps-2.0
10 | #>
11 |
12 |
13 | # User UPN to assign role to
14 | $roleUser = ''
15 |
16 | # Role Name to Assign
17 | $roleName = ''
18 |
19 |
20 | # Import AzureAD module and Connect
21 | Import-Module AzureAD
22 | Connect-AzureAD
23 |
24 | # Fetch user to assign to role
25 | $roleMember = Get-AzureADUser -ObjectId $roleUser
26 |
27 | # Fetch role instance
28 | $role = Get-AzureADDirectoryRole | Where-Object {$_.displayName -eq $roleName}
29 |
30 | # If role instance does not exist, instantiate it based on the role template
31 | if (!($role)) {
32 | # Instantiate an instance of the role template
33 | $roleTemplate = Get-AzureADDirectoryRoleTemplate | Where-Object {$_.displayName -eq $roleName}
34 | Enable-AzureADDirectoryRole -RoleTemplateId $roleTemplate.ObjectId
35 |
36 | # Fetch role instance again
37 | $role = Get-AzureADDirectoryRole | Where-Object {$_.displayName -eq $roleName}
38 | }
39 |
40 | # Add user to role
41 | Add-AzureADDirectoryRoleMember -ObjectId $role.ObjectId -RefObjectId $roleMember.ObjectId
42 |
43 | # Fetch role membership for role to confirm
44 | Get-AzureADDirectoryRoleMember -ObjectId $role.ObjectId | Get-AzureADUser
45 |
--------------------------------------------------------------------------------
/AzureAD/BulkAddLicenceConditional.ps1:
--------------------------------------------------------------------------------
1 | # Bulk add a new licence to users on the basis of what licence they currently have.
2 | #
3 | # An updated version of my previous MSOL script, now using AzureAD.
4 | # This is useful for something like adding Office 365 ATP to everyone who currently has E3, for example.
5 | #
6 | # List of available SKUs can be obtained with (Get-AzureADSubscribedSku).SkuPartNumber
7 | #
8 |
9 | # What licence do the users currently have?
10 | $existingLicence = 'ENTERPRISEPACK'
11 |
12 | # What licence are we adding?
13 | $licenceToAdd = 'ATP_ENTERPRISE'
14 |
15 | # Import AzureAD module and connect
16 | Import-Module AzureAD
17 | Connect-AzureAD
18 |
19 | # Get all available licence skus
20 | $allSkus = Get-AzureADSubscribedSku
21 |
22 | # Get sku ID for existing licence
23 | $existingSkuID = ($allSkus | Where-Object {$_.SkuPartNumber -eq $existingLicence}).SkuId
24 |
25 | # Get sku ID for new licence
26 | $newSkuID = ($allSkus | Where-Object {$_.SkuPartNumber -eq $licenceToAdd}).SkuId
27 |
28 | # Find everyone who has the existing licence but not the licence we're adding
29 | $users = Get-AzureADUser -All $true | Where-Object {$_.AssignedLicenses.SkuId -match $existingSkuID -and !($_.AssignedLicenses.SkuId -match $newSkuID)}
30 |
31 | # Create a new licence object for the licence we're adding
32 | $newLicense = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense
33 | $newLicense.SkuId = $newSkuID
34 |
35 | # Create a new assigned licenses object and add the licence we're adding to add licenses
36 | $newLicenses = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses
37 | $newLicenses.AddLicenses = $newLicense
38 |
39 | # Add the new licence to each user in the list
40 | foreach ($user in $users) {
41 | Set-AzureADUserLicense -ObjectId $user.UserPrincipalName -AssignedLicenses $newLicenses
42 | }
43 |
44 | # Disconnect from AzureAD
45 | Disconnect-AzureAD
46 |
--------------------------------------------------------------------------------
/AzureAD/BulkAddLicences.ps1:
--------------------------------------------------------------------------------
1 | # Bulk add additional licences to a list of users.
2 | #
3 | # An updated version of my previous MSOL script, now using AzureAD.
4 | #
5 | # List of available SKUs can be obtained with (Get-AzureADSubscribedSku).SkuPartNumber
6 | #
7 |
8 | # Where is the list of user UPN's?
9 | $userListPath = 'C:\Temp\UserList.txt'
10 |
11 | # What licences are we adding?
12 | $licencesToAdd = @('ENTERPRISEPACK','ATP_ENTERPRISE','EMSPREMIUM')
13 |
14 | # Import AzureAD module and connect
15 | Import-Module AzureAD
16 | Connect-AzureAD
17 |
18 | # Import list of users from file
19 | $userList = Get-Content -Path $userListPath | Sort-Object
20 |
21 | # Get all available licence skus
22 | $newSkuIDs = (Get-AzureADSubscribedSku | Where-Object {$_.SkuPartNumber -in $licencesToAdd}).SkuId
23 |
24 | # Create a licenses object
25 | $licenses = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses
26 |
27 | # Add the licences to add to the licences object
28 | foreach ($newSkuID in $newSkuIDs) {
29 | $newLicense = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense
30 | $newLicense.SkuId = $newSkuID
31 | $licenses.AddLicenses += $newLicense
32 | }
33 |
34 | # Add the licenses
35 | foreach ($username in $userList) {
36 | try {
37 | $user = Get-AzureADUser -ObjectId $username -ErrorAction Stop
38 | if ($user.AccountEnabled -eq $true) {
39 | Set-AzureADUserLicense -ObjectId $user.UserPrincipalName -AssignedLicenses $licenses -ErrorAction Stop
40 | Write-Output -InputObject ('Licence(s) added for user account ' + $user.UserPrincipalName + '.')
41 | }
42 | else {
43 | Write-Output -InputObject ('User account ' + $user.UserPrincipalName + ' is disabled.')
44 | }
45 | }
46 | catch {
47 | Write-Output -InputObject ('There was a problem updating licences for user account ' + $user.UserPrincipalName + '.')
48 | Write-Output -InputObject $Error[0]
49 | }
50 | }
51 |
52 | # Disconnect from AzureAD
53 | Disconnect-AzureAD
54 |
--------------------------------------------------------------------------------
/AzureAD/BulkAddUserToAzureADRoles.ps1:
--------------------------------------------------------------------------------
1 | # Script to add multiple users to multiple AzureAD roles
2 |
3 | <#
4 | You can find a list of available roles in the following Microsoft article
5 | https://docs.microsoft.com/en-us/azure/active-directory/active-directory-assign-admin-roles-azure-portal
6 | Double check using Get-AzureADDirectoryRole as they don't always have the same name in PowerShell as the GUI
7 |
8 | Built from the code example on the following Mircosoft page
9 | https://docs.microsoft.com/en-us/powershell/module/azuread/add-azureaddirectoryrolemember?view=azureadps-2.0
10 | #>
11 |
12 |
13 | # User UPNs to assign roles to
14 | $roleUsers = @('')
15 |
16 | # Role Names to Assign
17 | $roleNames = @('')
18 |
19 |
20 | # Import AzureAD module and Connect
21 | Import-Module AzureAD
22 | Connect-AzureAD
23 |
24 | # Run through the list of users
25 | foreach ($roleUser in $roleUsers) {
26 | # Fetch user to assign to role
27 | $roleMember = Get-AzureADUser -ObjectId $roleUser
28 |
29 | # Run through the list of roles
30 | foreach ($roleName in $roleNames) {
31 | # Fetch User Account Administrator role instance
32 | $role = Get-AzureADDirectoryRole | Where-Object { $_.displayName -eq $roleName }
33 |
34 | # If role instance does not exist, instantiate it based on the role template
35 | if (!($role)) {
36 | # Instantiate an instance of the role template
37 | $roleTemplate = Get-AzureADDirectoryRoleTemplate | Where-Object { $_.displayName -eq $roleName }
38 | Enable-AzureADDirectoryRole -RoleTemplateId $roleTemplate.ObjectId
39 |
40 | # Fetch User Account Administrator role instance again
41 | $role = Get-AzureADDirectoryRole | Where-Object { $_.displayName -eq $roleName }
42 | }
43 |
44 | # Get existing users with the role assigned
45 | $existingRoleUsers = (Get-AzureADDirectoryRoleMember -ObjectId $role.ObjectId).UserPrincipalName
46 |
47 | # Assign role to new user if not already in the list
48 | if ($roleMember.UserPrincipalName -notin $existingRoleUsers) {
49 | Add-AzureADDirectoryRoleMember -ObjectId $role.ObjectId -RefObjectId $roleMember.ObjectId -ErrorAction Stop
50 | }
51 | }
52 | }
53 |
54 | # Uncomment to fetch role membership for each role to confirm
55 | #foreach ($roleName in $roleNames) {
56 | # Write-Output -InputObject ('Members for role: ' + $roleName)
57 | # Get-AzureADDirectoryRoleMember -ObjectId $role.ObjectId | Get-AzureADUser | Where-Object {$_.UserPrincipalName -in $roleUsers} | Format-List -Property DisplayName,UserPrincipalName
58 | #}
59 |
--------------------------------------------------------------------------------
/AzureAD/BulkDisableGuestAccounts.ps1:
--------------------------------------------------------------------------------
1 | # Script to bulk disable guest accounts in Azure AD, either all or for a specific domain
2 | #
3 |
4 | # Are we disabling for a specific guest domain? Leave blank for all guests.
5 | $guestDomain = ''
6 |
7 | # Install the AzureAD module, uncomment if required
8 | #Install-Module -Name AzureAD
9 |
10 | # Import the AzureAD module and connect to Azure AD
11 | Import-Module -Name AzureAD
12 | Connect-AzureAD
13 |
14 | # Get a list of all guests from Azure AD either matching the domain or all guests
15 | if ($guestDomain -ne '') {
16 | $guestAccounts = Get-AzureADUser -All $true | Where-Object { $_.AccountEnabled -eq $true -and $_.UserType -eq 'Guest' -and $_.Mail -like ('*' + $guestDomain) }
17 | }
18 | else {
19 | $guestAccounts = Get-AzureADUser -All $true | Where-Object { $_.AccountEnabled -eq $true -and $_.UserType -eq 'Guest' }
20 | }
21 |
22 | # Disable the guest accounts
23 | try {
24 | $guestAccounts | Set-AzureADUser -AccountEnabled $false -ErrorAction Stop
25 | Write-Output -InputObject ('The specified guest accounts have been disabled.')
26 | }
27 | catch {
28 | Write-Output -InputObject ('Failed - The specified guest accounts have not been disabled.')
29 | }
30 |
--------------------------------------------------------------------------------
/AzureAD/BulkEnableGuestAccounts.ps1:
--------------------------------------------------------------------------------
1 | # Script to bulk enable guest accounts in Azure AD, either all or for a specific domain
2 | #
3 |
4 | # Are we disabling for a specific guest domain? Leave blank for all guests.
5 | $guestDomain = ''
6 |
7 | # Install the AzureAD module, uncomment if required
8 | #Install-Module -Name AzureAD
9 |
10 | # Import the AzureAD module and connect to Azure AD
11 | Import-Module -Name AzureAD
12 | Connect-AzureAD
13 |
14 | # Get a list of all guests from Azure AD either matching the domain or all guests
15 | if ($guestDomain -ne '') {
16 | $guestAccounts = Get-AzureADUser -All $true | Where-Object { $_.AccountEnabled -eq $false -and $_.UserType -eq 'Guest' -and $_.Mail -like ('*' + $guestDomain) }
17 | }
18 | else {
19 | $guestAccounts = Get-AzureADUser -All $true | Where-Object { $_.AccountEnabled -eq $false -and $_.UserType -eq 'Guest' }
20 | }
21 |
22 | # Enable the guest accounts
23 | $guestAccounts | Set-AzureADUser -AccountEnabled $true
24 | Write-Output -InputObject ('The specified guest accounts have been disabled.')
25 |
--------------------------------------------------------------------------------
/AzureAD/BulkRemoveGuestsWithUnacceptedInvites.ps1:
--------------------------------------------------------------------------------
1 | # Find all guests with unaccepted invites over a specific time period and remove them
2 | #
3 |
4 | # How many days are we allowing for invites to be accepted? (This can be 0 for all)
5 | $cutOffDays = 30
6 |
7 | # Install the AzureAD module, uncomment if required
8 | #Install-Module -Name AzureAD
9 |
10 | # Import the AzureAD module and connect to Azure AD
11 | Import-Module -Name AzureAD
12 | Connect-AzureAD
13 |
14 | # Get the cut off date
15 | $cutOffDate = (Get-Date).AddDays(-$cutOffDays)
16 |
17 | # Get a list of all guests with unaccepted invites older than the specificed timeframe
18 | $unacceptedGuests = Get-AzureADUser -All $true | Where-Object { $_.UserType -eq 'Guest' -and $_.UserState -eq 'PendingAcceptance' -and $_.RefreshTokensValidFromDateTime -lt $cutOffDate }
19 |
20 | # Remove the guest accounts
21 | $unacceptedGuests | Remove-AzureADUser
22 |
--------------------------------------------------------------------------------
/AzureAD/BulkRemoveLicences.ps1:
--------------------------------------------------------------------------------
1 | # Bulk remove licences to a list of users.
2 | #
3 | # List of available SKUs can be obtained with (Get-AzureADSubscribedSku).SkuPartNumber
4 | #
5 |
6 | # Where is the list of user UPN's?
7 | $userListPath = 'C:\Temp\UserList.txt'
8 |
9 | # What licences are we removing?
10 | $licencesToRemove = @('ENTERPRISEPACK','ATP_ENTERPRISE','EMSPREMIUM')
11 |
12 | # Import AzureAD module and connect
13 | Import-Module AzureAD
14 | Connect-AzureAD
15 |
16 | # Import list of users from file
17 | $userList = Get-Content -Path $userListPath | Sort-Object
18 |
19 | # Create a licenses object
20 | $licenses = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses
21 |
22 | # Get SkuIDs for licence(s) to be removed
23 | $licenses.RemoveLicenses = (Get-AzureADSubscribedSku | Where-Object {$_.SkuPartNumber -in $licencesToRemove}).SkuId
24 |
25 | # Remove the licenses
26 | foreach ($username in $userList) {
27 | try {
28 | $user = Get-AzureADUser -ObjectId $username -ErrorAction Stop
29 | if ($user.AccountEnabled -eq $true) {
30 | Set-AzureADUserLicense -ObjectId $user.UserPrincipalName -AssignedLicenses $licenses
31 | Write-Output -InputObject ('Licence(s) removed from user account ' + $user.UserPrincipalName + '.')
32 | }
33 | else {
34 | Write-Output -InputObject ('User account ' + $user.UserPrincipalName + ' is disabled.')
35 | }
36 | }
37 | catch {
38 | Write-Output -InputObject ('There was a problem updating licences for user account ' + $user.UserPrincipalName + '.')
39 | Write-Output -InputObject $Error[0]
40 | }
41 | }
42 |
43 | # Disconnect from AzureAD
44 | Disconnect-AzureAD
45 |
--------------------------------------------------------------------------------
/AzureAD/BulkReplaceLicences.ps1:
--------------------------------------------------------------------------------
1 | # Bulk replace licences to a list of users.
2 | #
3 | # List of available SKUs can be obtained with (Get-AzureADSubscribedSku).SkuPartNumber
4 | #
5 |
6 | # Where is the list of user UPN's?
7 | $userListPath = 'C:\Temp\UserList.txt'
8 |
9 | # What licences are we adding?
10 | $licencesToAdd = @('EMSPREMIUM')
11 |
12 | # What licences are we removing?
13 | $licencesToRemove = @('EMS','AAD_PREMIUM_P2')
14 |
15 | # Import AzureAD module and connect
16 | Import-Module AzureAD
17 | Connect-AzureAD
18 |
19 | # Import list of users from file
20 | $userList = Get-Content -Path $userListPath | Sort-Object
21 |
22 | $userList = @('OAndrewsAdmin@sis.tv')
23 |
24 | # Get all available licence skus
25 | $newSkuIDs = (Get-AzureADSubscribedSku | Where-Object {$_.SkuPartNumber -in $licencesToAdd}).SkuId
26 |
27 | # Create a licenses object
28 | $licenses = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses
29 |
30 | # Add the licences to add to the licences object
31 | foreach ($newSkuID in $newSkuIDs) {
32 | $newLicense = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense
33 | $newLicense.SkuId = $newSkuID
34 | $licenses.AddLicenses += $newLicense
35 | }
36 |
37 | # Add the licences we want to remove to the $licenses object
38 | $licenses.RemoveLicenses = (Get-AzureADSubscribedSku | Where-Object {$_.SkuPartNumber -in $licencesToRemove}).SkuID
39 |
40 | # Replace the licenses
41 | foreach ($username in $userList) {
42 | try {
43 | $user = Get-AzureADUser -ObjectId $username -ErrorAction Stop
44 | if ($user.AccountEnabled -eq $true) {
45 | Set-AzureADUserLicense -ObjectId $user.UserPrincipalName -AssignedLicenses $licenses
46 | Write-Output -InputObject ('Licences updated for user account ' + $user.UserPrincipalName + '.')
47 | }
48 | else {
49 | Write-Output -InputObject ('User account ' + $user.UserPrincipalName + ' is disabled.')
50 | }
51 | }
52 | catch {
53 | Write-Output -InputObject ('There was a problem updating licences for user account ' + $user.UserPrincipalName + '.')
54 | Write-Output -InputObject $Error[0]
55 | }
56 | }
57 |
58 | # Disconnect from AzureAD
59 | Disconnect-AzureAD
60 |
--------------------------------------------------------------------------------
/AzureAD/FixOnlineUserUPN.ps1:
--------------------------------------------------------------------------------
1 | # Update Online User UPN - when AD sync doesn't do it.
2 |
3 | # Import the Azure AD module and connect
4 | Import-Module AzureAD
5 | Connect-AzureAD
6 |
7 | # Whose UPN are we changing?
8 | $oldUPN = Read-Host -Prompt 'Enter user''s old UPN in the format username@domain'
9 |
10 | # What are we changing it to?
11 | $newUPN = Read-Host -Prompt 'Enter user''s new UPN in the format username@domain'
12 |
13 | # Update the UPN in AzureAD
14 | Set-AzureADUser -ObjectId $oldUPN -UserPrincipalName $newUPN
15 |
--------------------------------------------------------------------------------
/AzureAD/GetADGUIDFromAzureAD.ps1:
--------------------------------------------------------------------------------
1 | # Import the Azure AD module and connect
2 | Import-Module AzureAD
3 | Connect-AzureAD
4 |
5 | # Whose ID are we getting?
6 | $userUPN = Read-Host -Prompt 'Enter user''s UPN in the format username@domain'
7 |
8 | # Convert 365 ImmutableID to AD GUID
9 | $immutableID = (Get-AzureADUser -ObjectId $userUPN).ImmutableID
10 | [GUID][System.Convert]::FromBase64String($immutableID)
11 |
--------------------------------------------------------------------------------
/AzureAD/GetAllAndUnacceptedGuestsToCSV.ps1:
--------------------------------------------------------------------------------
1 | # A simple script to get a list of all guest users from Azure AD along with a list of those who haven't accepted their invite within a set period
2 | #
3 |
4 | # How many days are we allowing for invites to be accepted?
5 | $cutOffDays = 30
6 |
7 | # Install the AzureAD module, uncomment if required
8 | #Install-Module -Name AzureAD
9 |
10 | # Import the AzureAD module and connect to Azure AD
11 | Import-Module -Name AzureAD
12 | Connect-AzureAD
13 |
14 | # Get the cut off date
15 | $cutOffDate = (Get-Date).AddDays(-$cutOffDays)
16 |
17 | # Get a list of all guests from Azure AD and output it to CSV
18 | $allGuests = Get-AzureADUser -All $true | Where-Object { $_.UserType -eq 'Guest' }
19 | $allGuests | Select-Object DisplayName, Mail, MailNickName, RefreshTokensValidFromDateTime, UserState, UserStateChangedOn | Export-CSV -Path 'C:\Temp\AzureAD_AllGuests.csv'
20 |
21 | # Filter guests list to those who haven't accepted their invite after the set period, and output the list to CSV
22 | $oldUnacceptedInvites = $allGuests | Where-Object { $_.UserState -eq 'PendingAcceptance' -and $_.RefreshTokensValidFromDateTime -lt $cutOffDate }
23 | $oldUnacceptedInvites | Select-Object DisplayName, Mail, MailNickName, RefreshTokensValidFromDateTime, UserState | Export-CSV -Path 'C:\Temp\AzureAD_Guests_StalePendingAcceptance.csv' -NoTypeInformation
24 |
--------------------------------------------------------------------------------
/AzureAD/GetAzureADAssignedRoles.ps1:
--------------------------------------------------------------------------------
1 | # Script to get all Azure AD roles assigned to all users
2 | #
3 |
4 | # Output file
5 | $outputFile = 'C:\Temp\AzureADAllAssignedRoles.csv'
6 |
7 | # Import the module and connect to AzureAD
8 | Import-Module -Name AzureAD
9 | Connect-AzureAD
10 |
11 | # Get all Azure AD role definitions, excluding the default User role
12 | $roleDefinitions = Get-AzureADMSRoleDefinition | Where-Object { $_.Id -ne 'a0b1b346-4d3e-4e8b-98f8-753987be4970' }
13 |
14 | # Prime the output array
15 | $allAssignedRoles = @()
16 |
17 | # Set progress index to 0
18 | $i = 0
19 |
20 | # Run through all the role definitions
21 | foreach ($roleDefinition in $roleDefinitions) {
22 | # Show a progress bar
23 | Write-Progress -Activity 'Checking users assigned to...' -Status $roleDefinition.DisplayName -PercentComplete ((++$i / $roleDefinitions.Count) * 100)
24 |
25 | # Get assignments for the role definition
26 | $roleAssignments = Get-AzureADMSRoleAssignment -All $true -Filter "roleDefinitionId eq '$($roleDefinition.Id)'"
27 |
28 | # If there are role assignments then find out who they are
29 | if ($roleAssignments) {
30 | # Get Azure AD objects for the list of assignments
31 | $azureAdObjects = Get-AzureADObjectByObjectId -ObjectIds $roleAssignments.PrincipalId
32 |
33 | # Add a new object for each Azure AD object to our output array
34 | foreach ($azureAdObject in $azureAdObjects) {
35 | $allAssignedRoles += [PSCustomObject]@{
36 | 'DisplayName' = $azureAdObject.DisplayName;
37 | 'UserPrincipalName' = $azureAdObject.UserPrincipalName;
38 | 'RoleName' = $roleDefinition.DisplayName;
39 | }
40 | }
41 | }
42 | }
43 |
44 | # Output sorted list of all roles to CSV
45 | $allAssignedRoles | Sort-Object -Property DisplayName | Export-Csv -NoTypeInformation -Path $outputFile
46 |
47 | # Disconnect from Azure
48 | Disconnect-AzureAD
49 |
--------------------------------------------------------------------------------
/AzureAD/GetLicencesAllUsers.ps1:
--------------------------------------------------------------------------------
1 | # Retrieve licences for all users and export to CSV.
2 | #
3 |
4 | # Output file path and name
5 | $outputFilePath = 'C:\Temp\'
6 | $outputFileName = 'AllUserLicences.csv'
7 |
8 | # Import AzureAD module and connect
9 | Import-Module AzureAD
10 | Connect-AzureAD
11 |
12 | # Get all available licence details
13 | $allSkus = Get-AzureADSubscribedSku
14 |
15 | # Import list of users from file
16 | $users = Get-AzureADUser -All $true
17 |
18 | # Get Licences for each user and find out what they are from the list
19 | $allUserLicences = @()
20 | foreach ($user in $users) {
21 | $assignedLicences = @()
22 | foreach ($license in $user.AssignedLicenses.SkuID) {
23 | $assignedLicences += ($allSkus | Where-Object { $_.SkuID -eq $license }).SkuPartNumber
24 | }
25 | $userLicences = [PSCustomObject]@{
26 | 'UserName' = $user.UserPrincipalName
27 | 'AssignedLicences' = (($assignedLicences | Sort-Object) -join ';')
28 | }
29 | $allUserLicences += $userLicences
30 | }
31 |
32 | # Export list to CSV file
33 | $outputFile = $outputFilePath + $outputFileName
34 | $allUserLicences | Export-Csv -Path $outputFile -NoTypeInformation
35 |
--------------------------------------------------------------------------------
/AzureAD/GetLicencesForUserList.ps1:
--------------------------------------------------------------------------------
1 | # Retrieve licences for a list of users and export them to a CSV file.
2 | #
3 |
4 | # Where is the list of user UPN's?
5 | $userListPath = 'C:\Temp\UserList.txt'
6 |
7 | # Import AzureAD module and connect
8 | Import-Module AzureAD
9 | Connect-AzureAD
10 |
11 | # Get all available licence details
12 | $allSkus = Get-AzureADSubscribedSku
13 |
14 | # Import list of users from file
15 | $users = Get-Content -Path $userListPath | Sort-Object
16 |
17 | # Get Licences for user and find out what they are from the list
18 | $allUserLicences = @()
19 | foreach ($user in $users) {
20 | $assignedLicences = @()
21 | try {
22 | $userDetails = Get-AzureADUser -ObjectId $user -ErrorAction Stop
23 | foreach ($license in $userDetails.AssignedLicenses.SkuID) {
24 | $assignedLicences += ($allSkus | Where-Object { $_.SkuID -eq $license }).SkuPartNumber
25 | }
26 | }
27 | catch {
28 | $assignedLicences = 'User not found.'
29 | }
30 | $userLicences = [PSCustomObject]@{
31 | 'UserName' = $user
32 | 'AssignedLicences' = (($assignedLicences | Sort-Object) -join ';')
33 | }
34 | $allUserLicences += $userLicences
35 | }
36 |
37 | # Export list to CSV file
38 | $allUserLicences | Export-Csv -Path 'C:\Temp\UserLicences.csv' -NoTypeInformation
39 |
--------------------------------------------------------------------------------
/AzureAD/GetUsersFromPlanID.ps1:
--------------------------------------------------------------------------------
1 | # Some example scripts for finding users with specific plans assigned
2 | #
3 | # A full list of subscription and plan ID's is available from:
4 | # https://docs.microsoft.com/en-us/azure/active-directory/users-groups-roles/licensing-service-plan-reference
5 | #
6 | # Here I'm using the following plan IDs.
7 | #
8 | # OFFICESUBSCRIPTION (43de0ff5-c92c-492b-9116-175376d08c38)
9 | # PROJECT_CLIENT_SUBSCRIPTION (fafd7243-e5c1-4a3a-9e40-495efcb1d3c3)
10 | # VISIO_CLIENT_SUBSCRIPTION (663a804f-1c30-4ff0-9915-9db84f0d1cea)
11 | #
12 |
13 | # Plan ID's to check for
14 | $planID1 = '43de0ff5-c92c-492b-9116-175376d08c38'
15 | $planID2 = 'fafd7243-e5c1-4a3a-9e40-495efcb1d3c3'
16 | $planID3 = '663a804f-1c30-4ff0-9915-9db84f0d1cea'
17 |
18 | # Import the AzureAD module and connect
19 | Import-Module AzureAD
20 | Connect-AzureAD
21 |
22 | # Get all users from AzureAD
23 | $allUsers = Get-AzureADUser -All $true
24 |
25 | # Create variables to put the users in to
26 | $planID1Users = @()
27 | $planID2Users = @()
28 | $planID3Users = @()
29 |
30 | # Check through the users and check what plans are assigned and enabled
31 | foreach ($user in $allUsers) {
32 | foreach ($assignedPlan in $user.AssignedPlans) {
33 | # Find all users of plan 1 and add to the related variable
34 | if ($assignedPlan.ServicePlanId -eq $planID1 -and $assignedPlan.CapabilityStatus -eq 'Enabled') {
35 | $planID1Users += $user
36 | }
37 | # Find all users of plan 2 and add to the related variable
38 | if ($assignedPlan.ServicePlanId -eq $planID2 -and $assignedPlan.CapabilityStatus -eq 'Enabled') {
39 | $planID2Users += $user
40 | }
41 | # Find all users of plan 3 and add to the related variable
42 | if ($assignedPlan.ServicePlanId -eq $planID3 -and $assignedPlan.CapabilityStatus -eq 'Enabled') {
43 | $planID3Users += $user
44 | }
45 | }
46 | }
47 |
48 | # Create variables to put the users in to
49 | $plan1OnlyUsers = @()
50 | $planID1and2Users = @()
51 | $planID1and3Users = @()
52 | $planID12and3Users = @()
53 |
54 | # Using plan 1 as the master list, check which other licences are assigned
55 | foreach ($planID1User in $planID1Users) {
56 | # Find users who are only in the plan 1 list
57 | if ($planID1User -notin $planID2Users -and $planID1User -notin $planID3Users) {
58 | $plan1OnlyUsers += $planID1User
59 | }
60 | # Find users who are the plan 1 and plan 2 list
61 | if ($planID1User -in $planID2Users) {
62 | $planID1and2Users += $planID1User
63 | }
64 | # Find users who are in the plan 1 and plan 3 list
65 | if ($planID1User -in $planID3Users) {
66 | $planID1and3Users += $planID1User
67 | }
68 | # Find users who are in all three lists
69 | if ($planID1User -in $planID2Users -and $planID1User -in $planID3Users) {
70 | $planID12and3Users += $planID1User
71 | }
72 | }
73 |
74 | # How many people in each list?
75 | $plan1OnlyUsers.Count
76 | $planID1and2Users.Count
77 | $planID1and3Users.Count
78 | $planID12and3Users.Count
79 |
80 | # Who are those people?
81 | $plan1OnlyUsers
82 | $planID1and2Users
83 | $planID1and3Users
84 | $planID12and3Users
85 |
--------------------------------------------------------------------------------
/AzureAD/InviteGuestAndAddToGroup.ps1:
--------------------------------------------------------------------------------
1 | # Script to invite a list of guest users to AzureAD and add them to a group
2 | #
3 | # Useful for bulk adding guests to a SharePoint or Teams group
4 | #
5 | # Uses a CSV file containing columns for FirstName,LastName,DisplayName,ExternalEmailAddress
6 | #
7 |
8 | # Where is our list of people?
9 | $contactsFile = 'C:\Temp\ExternalContacts.csv'
10 |
11 | # What group are we added them to?
12 | $groupName = 'Test Group'
13 |
14 | # Import the AzureAD module and connect
15 | Import-Module AzureAD
16 | Connect-AzureAD
17 |
18 | # Import the list of people
19 | $contactsList = Import-Csv -Path $contactsFile
20 |
21 | # Find the group ID for our group
22 | $groupID = (Get-AzureADGroup -All $true | Where-Object {$_.DisplayName -eq $groupName}).ObjectId
23 |
24 | # Run through the list sending the guest invite and adding them to the group, unless their email address is already used somewhere
25 | foreach ($externalUser in $contactsList) {
26 | $getExisting = Get-AzureADUser -SearchString $externalUser.ExternalEmailAddress
27 |
28 | if ($getExisting.Count -eq 0) {
29 | $newUser = New-AzureADMSInvitation -InvitedUserDisplayName $externalUser.DisplayName -InvitedUserEmailAddress $externalUser.ExternalEmailAddress -SendInvitationMessage $true -InviteRedirectUrl "https://myapps.microsoft.com"
30 | Add-AzureADGroupMember -ObjectId $groupID -RefObjectId $newUser.InvitedUser.Id
31 | Write-Output -InputObject ('Guest ' + $externalUser.ExternalEmailAddress + ' created and added to group.')
32 | }
33 | else {
34 | Write-Output -InputObject ('Object already exists with email address ' + $externalUser.ExternalEmailAddress + '.')
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/AzureAD/RemoveAllLicencesFromUserList.ps1:
--------------------------------------------------------------------------------
1 | # Remove all licences from a list of users
2 | #
3 | # Removing licences with this module doesn't work in the way that Microsoft's documentation states.
4 | # I'm assuming this is a bug, so the code below works at time of creation but may stop working in the future.
5 | #
6 |
7 | # Where is the list of user UPN's?
8 | $userListPath = 'C:\Temp\UserList.txt'
9 |
10 | # Import AzureAD module and connect
11 | Import-Module AzureAD
12 | Connect-AzureAD
13 |
14 | # Import list of users from file
15 | $userList = Get-Content -Path $userListPath | Sort-Object
16 |
17 | # Remove all the licences
18 | foreach ($username in $userList) {
19 | try {
20 | $user = Get-AzureADUser -ObjectId $username -ErrorAction Stop
21 | if ($user.AccountEnabled -eq $true) {
22 | if(($user.AssignedLicenses.SkuId).Count -ge 1) {
23 | $licenses = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses
24 | $licenses.RemoveLicenses = (Get-AzureADSubscribedSku | Where-Object {$_.SkuId -in $user.AssignedLicenses.SkuId}).SkuId
25 | Set-AzureADUserLicense -ObjectId $user.UserPrincipalName -AssignedLicenses $licenses
26 | Write-Output -InputObject ('All licences removed from user account ' + $username + '.')
27 | }
28 | else {
29 | Write-Output -InputObject ('User account ' + $username + ' has no licences assigned.')
30 | }
31 | }
32 | else {
33 | Write-Output -InputObject ('User account ' + $username + ' is disabled.')
34 | }
35 | }
36 | catch {
37 | Write-Output -InputObject ('User account ' + $username + ' does not exist.')
38 | }
39 | }
40 |
41 | # Disconnect from AzureAD
42 | Disconnect-AzureAD
43 |
--------------------------------------------------------------------------------
/Exchange/CheckMailboxStatsAccessAndPermissions.ps1:
--------------------------------------------------------------------------------
1 | # Script to get details for a list of mailboxes and save that out to a CSV file
2 | #
3 |
4 | # File containing the list of mailboxes
5 | $inputFile = ''
6 |
7 | # File to save the results to
8 | $outputFile = 'C:\Temp\MailboxStats.csv'
9 |
10 | # Establish a session to Exchange Online
11 | Import-Module -Name ExchangeOnlineManagement
12 | Connect-ExchangeOnline
13 |
14 | # Check output folder exists and create it if it doesn't
15 | $outputPath = (Split-Path -Path $outputFile)
16 | if (!(Test-Path -Path $outputPath)) { New-Item -Path $outputFolder -ItemType Directory }
17 |
18 | # If output file already exists, delete it.
19 | if (Test-Path -Path $outputFile) { Remove-Item -Path $outputFile }
20 |
21 | # Get the list of mailboxes from the file, or if input file is blank get all mailboxes
22 | if ($inputFile) {
23 | $mailboxes = Get-Content -Path $inputFile
24 | }
25 | else {
26 | $mailboxes = (Get-Mailbox -ResultSize unlimited).UserPrincipalName
27 | }
28 |
29 | # Initialise the results table
30 | $mailboxesTable = @()
31 |
32 | # Iterate through the mailboxes and show a progress bar as we go.
33 | foreach ($mailbox in $mailboxes) {
34 | Write-Progress -Activity 'Checking..' -status $mailbox -percentComplete ($mailboxes.IndexOf($mailbox) / $mailboxes.Count * 100)
35 |
36 | # Get the statistics for the mailbox.
37 | $mailboxStats = ''
38 | $mailboxStats = Get-MailboxStatistics -Identity $mailbox
39 |
40 | # If mailboxStats is blank then mailbox doesn't exist, so that entry can be skipped. For all others get the mailbox permissions and build the output table.
41 | if ($mailboxStats) {
42 | # Get permit permissions for users where the username has an @ in it, this filters out all the system permissions.
43 | $usersWithPermissions = Get-MailboxPermission -Identity $mailbox | Where-Object { $_.User -like '*@*' -and $_.IsInherited -eq $false }
44 |
45 | $otherUserAccess = @()
46 | foreach ($userWithPermissions in $usersWithPermissions) {
47 | $otherUserAccess += $userWithPermissions.User + ' (' + ($userWithPermissions.AccessRights -split ',' -replace ' ','' -join '; ') + ')'
48 | }
49 |
50 | $mailboxesTable += [PSCustomObject]@{
51 | 'MailboxUPN' = $mailbox;
52 | 'MailboxType' = $mailboxStats.MailboxTypeDetail;
53 | 'ItemCount' = $mailboxStats.ItemCount;
54 | 'TotalItemSize' = $mailboxStats.TotalItemSize;
55 | 'LastLogonTime' = $mailboxStats.LastLogonTime;
56 | 'OtherUserAccess' = $otherUserAccess -join '; ';
57 | }
58 | }
59 | }
60 |
61 | # Output the final table of results to a file.
62 | $mailboxesTable | Sort-Object -Property 'MailboxUPN' | Export-Csv -Path $outputFile -NoTypeInformation
63 |
64 | # End the Exchange Online session
65 | Disconnect-ExchangeOnline
66 |
--------------------------------------------------------------------------------
/Exchange/FindUsersWithMismatchedDomains.ps1:
--------------------------------------------------------------------------------
1 | # Find mailboxes where UPN domain doesn't match email domain
2 | #
3 |
4 | # Establish a session to Exchange Online
5 | Import-Module -Name ExchangeOnlineManagement
6 | Connect-ExchangeOnline
7 |
8 | # Get list of mailboxes with a different mail domain to UPN domain
9 | $mismatchedMailboxes = Get-Mailbox -ResultSize Unlimited | Where-Object { $_.UserPrincipalName.Split('@')[1] -ne $_.PrimarySmtpAddress.Split('@')[1] }
10 |
11 | # Output as table
12 | $mismatchedMailboxes | Format-Table -Property Name, UserPrincipalName, PrimarySmtpAddress, RecipientTypeDetails -AutoSize
13 |
14 | # Disconnect from Exchange Online
15 | Disconnect-ExchangeOnline
16 |
--------------------------------------------------------------------------------
/Exchange/GetAllForwardingRules.ps1:
--------------------------------------------------------------------------------
1 | # Script to get all client forwarding rules, smtp forwarding rules and delegates on mailboxes
2 | #
3 | # This builds on top of a script from https://github.com/OfficeDev/O365-InvestigationTooling
4 | #
5 |
6 | # Establish a session to Exchange Online
7 | Import-Module -Name ExchangeOnlineManagement
8 | Connect-ExchangeOnline
9 |
10 | # Get All mailboxes
11 | $allUsers = Get-Mailbox -ResultSize Unlimited | Select-Object DisplayName,UserPrincipalName,ForwardingAddress,ForwardingSMTPAddress,DeliverToMailboxandForward
12 |
13 | $userInboxRules = @()
14 | $userDelegates = @()
15 |
16 | # Run through the mailboxes getting rules and delegate settings
17 | foreach ($user in $allUsers) {
18 | Write-Progress -Activity "Checking inbox rules for..." -status $user.UserPrincipalName -percentComplete ($allUsers.IndexOf($user) / $allUsers.Count * 100)
19 | $userInboxRules += Get-InboxRule -Mailbox $user.UserPrincipalName | `
20 | Select-Object MailboxOwnerId,Name,Description,Enabled,Priority,ForwardTo,ForwardAsAttachmentTo,RedirectTo,DeleteMessage | `
21 | Where-Object {($_.ForwardTo -ne $null) -or ($_.ForwardAsAttachmentTo -ne $null) -or ($_.RedirectsTo -ne $null)}
22 | $userDelegates += Get-MailboxPermission -Identity $user.UserPrincipalName | Where-Object {($_.IsInherited -ne "True") -and ($_.User -notlike "*SELF*")}
23 | }
24 |
25 | # Get all SMTP forwarding rules for all mailboxes
26 | $smtpForwarding = $allUsers | Select-Object DisplayName,ForwardingAddress,ForwardingSMTPAddress,DeliverToMailboxandForward | Where-Object {$_.ForwardingSMTPAddress -ne $null}
27 |
28 | # Output results to CSV files
29 | $userInboxRules | Export-Csv MailForwardingRulesToExternalDomains.csv -NoTypeInformation
30 | $smtpForwarding | Export-Csv Mailboxsmtpforwarding.csv -NoTypeInformation
31 | $userDelegates | Export-Csv MailboxDelegatePermissions.csv -NoTypeInformation
32 |
33 | # Disconnect from Exchange Online
34 | Disconnect-ExchangeOnline
35 |
--------------------------------------------------------------------------------
/Exchange/GrantCalendarDelegateAccess.ps1:
--------------------------------------------------------------------------------
1 | # Script to grant access rights on mailboxes
2 | #
3 |
4 | # Mailboxes to grant rights on
5 | $grantRightsOnMailboxes = @('','')
6 |
7 | # Users to grant rights to
8 | $grantRightsToUsers = @('','')
9 |
10 | # Rights to grant
11 | $accessRights = 'Editor'
12 |
13 | # Establish a session to Exchange Online
14 | Import-Module -Name ExchangeOnlineManagement
15 | Connect-ExchangeOnline
16 |
17 | # Apply the permissions
18 | foreach ($grantRightsToUser in $grantRightsToUsers ) {
19 | foreach ($grantRightsOnMailbox in $grantRightsOnMailboxes) {
20 | $calendarIdentity = $grantRightsOnMailbox + ':\Calendar'
21 | $existingPermissions = Get-MailboxFolderPermission -Identity $calendarIdentity -User $grantRightsToUser -ErrorAction SilentlyContinue
22 | if (!($existingPermissions)) {
23 | Add-MailboxFolderPermission -Identity $calendarIdentity -User $grantRightsToUser -AccessRights $accessRights
24 | }
25 | else {
26 | Set-MailboxFolderPermission -Identity $calendarIdentity -User $grantRightsToUser -AccessRights $accessRights
27 | }
28 | }
29 | }
30 |
31 | # Disconnect from Exchange Online
32 | Disconnect-ExchangeOnline
33 |
--------------------------------------------------------------------------------
/Exchange/LockdownMailbox.ps1:
--------------------------------------------------------------------------------
1 | # Enable mailbox auditing and disable PowerShell remoting on individual mailboxes
2 | #
3 | # Working on this as a one stop for hardening Exchange Online accounts
4 | #
5 |
6 | # UPN of New User
7 | $newUPN = ''
8 |
9 | # Is the user an administrator?
10 | $isAnAdmin = $false
11 |
12 | # Establish a session to Exchange Online
13 | Import-Module -Name ExchangeOnlineManagement
14 | Connect-ExchangeOnline
15 |
16 | # Set Auditing parameters
17 | $params = @{
18 | 'AuditEnabled' = $true
19 | 'AuditLogAgeLimit' = '180'
20 | 'AuditAdmin' = @('Update','MoveToDeletedItems','SoftDelete','HardDelete','SendAs','SendOnBehalf','Create','UpdateFolderPermission')
21 | 'AuditDelegate' = @('Update','SoftDelete','HardDelete','SendAs','Create','UpdateFolderPermissions','MoveToDeletedItems','SendOnBehalf')
22 | 'AuditOwner' = @('UpdateFolderPermission','MailboxLogin','Create','SoftDelete','HardDelete','Update','MoveToDeletedItems')
23 | }
24 |
25 | # Enable Auditing
26 | Get-Mailbox -Identity $newUPN | Set-Mailbox @params
27 |
28 | # Disable PowerShell Remoting for non-Admin staff
29 | if ($isAnAdmin) {
30 | Set-User -Identity $newUPN -RemotePowerShellEnabled $true
31 | }
32 | else {
33 | Set-User -Identity $newUPN -RemotePowerShellEnabled $false
34 | }
35 |
36 | # Disconnect from Exchange Online
37 | Disconnect-ExchangeOnline
38 |
--------------------------------------------------------------------------------
/ExchangeWithAADConnect/BulkRemoveProxyAddressesRemote.ps1:
--------------------------------------------------------------------------------
1 | # Script to bulk remove email proxy addresses from Exchange users in a synced environment using an on-prem Exchange management server
2 | #
3 |
4 | # What is the FQDN of the on-prem Exchange server?
5 | $exchangeServerFQDN = ''
6 |
7 | # Which domains are we removing?
8 | $domainsToRemove = @('','')
9 |
10 | # Create Exchange connection Uri from FQDN
11 | $exchangeConnectionUri = 'http://' + $exchangeServerFQDN +'/PowerShell/'
12 |
13 | # Establish a session to Exchange
14 | $userCredential = Get-Credential
15 | $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $exchangeConnectionUri -Authentication Kerberos -Credential $userCredential
16 | Import-PSSession $session -DisableNameChecking
17 |
18 | ### Check if address policies are using this domain ###
19 |
20 | # Initialise a hastable to store our results in
21 | $addressPolicies = @()
22 |
23 | # Get all address policies from Exchange
24 | $allAddressPolicies = Get-EmailAddressPolicy
25 |
26 | # Run through the domains checking if the domain to be removed is in the address policies
27 | foreach ($domainToRemove in $domainsToRemove) {
28 | $emailAddressTemplate = 'SMTP:@' + $domainToRemove
29 | $addressPolicies += $allAddressPolicies | Where-Object {$_.EnabledEmailAddressTemplates -contains $emailAddressTemplate}
30 | }
31 |
32 | # If domain found in address policies then list them and ask if we want to contiue removing the proxy domain
33 | if ($addressPolicies.Count -gt 0) {
34 | Write-Output -InputObject ('The following address policies are using the domain to be removed:')
35 | $addressPolicies | Format-Table
36 | $continue = ''
37 | while ($continue -notmatch '[YyNn]') {
38 | $continue = Read-Host -Prompt 'Do you want to continue running the script? (Y/N)'
39 | }
40 | if ($continue -match '[Nn]') {
41 | Write-Output -InputObject ('Terminating script.')
42 | break
43 | }
44 | else {
45 | Write-Output -InputObject ('Continuing with script.')
46 | }
47 | }
48 |
49 | ###
50 |
51 | ### Remove the domain from mailboxes ###
52 |
53 | # Get All Mailboxes
54 | $allMailboxes = Get-RemoteMailbox -ResultSize Unlimited | Sort-Object -Property alias
55 |
56 | # Remove alias from each mailbox
57 | foreach ($mailbox in $allMailboxes) {
58 | $redundantAddresses = @()
59 | foreach ($domainToRemove in $domainsToRemove) {
60 | $redundantAddresses += (($mailbox.EmailAddresses -split ',' | Where-Object {$_ -match $domainToRemove}) -replace 'smtp:','')
61 | }
62 | if ($redundantAddresses.Count -gt 0) {
63 | Write-Output -InputObject ('Removing addresses ' + $redundantAddresses + ' from maibox ' + $mailbox.Name)
64 | Set-RemoteMailbox -Identity $mailbox.Identity -EmailAddresses @{remove=$redundantAddresses} -Confirm:$false
65 | }
66 | }
67 |
68 | ###
69 |
70 | ### Remove the domain from contacts ###
71 |
72 | # Get all the contacts
73 | $allContacts = Get-MailContact -ResultSize Unlimited | Sort-Object -Property alias
74 |
75 | # Remove alias from each contact
76 | foreach ($contact in $allContacts) {
77 | $redundantAddresses = @()
78 | foreach ($domainToRemove in $domainsToRemove) {
79 | $redundantAddresses += (($contact.EmailAddresses -split ',' | Where-Object {$_ -like ('*' + $domainToRemove + '*')}) -replace 'smtp:','')
80 | }
81 | if ($redundantAddresses.Count -gt 0) {
82 | Write-Output -InputObject ('Removing addresses ' + $redundantAddresses + ' from contact ' + $contact.Name)
83 | Set-MailContact -Identity $contact.Identity -EmailAddresses @{remove=$redundantAddresses} -Confirm:$false -ForceUpgrade:$true
84 | }
85 | }
86 |
87 | ###
88 |
89 | ### Remove the domain from groups ###
90 |
91 | # Get all the groups (this includes email enabled security groups)
92 | $allGroups = Get-DistributionGroup -ResultSize Unlimited | Sort-Object -Property alias
93 |
94 | # Remove alias from each group
95 | foreach ($group in $allGroups) {
96 | $redundantAddresses = @()
97 | foreach ($domainToRemove in $domainsToRemove) {
98 | $redundantAddresses += (($group.EmailAddresses -split ',' | Where-Object {$_ -like ('*' + $domainToRemove + '*')}) -replace 'smtp:','')
99 | }
100 | if ($redundantAddresses.Count -gt 0) {
101 | Write-Output -InputObject ('Removing addresses ' + $redundantAddresses + ' from group ' + $group.Name)
102 | Set-DistributionGroup -Identity $group.Identity -EmailAddresses @{remove=$redundantAddresses} -Confirm:$false
103 | }
104 | }
105 |
106 | ###
107 |
108 | ### Public folders don't feature here because in this scenario they're cloud only ###
109 |
110 | # End the Exchange Session
111 | Remove-PSSession -Session $session
112 |
--------------------------------------------------------------------------------
/ExchangeWithAADConnect/CompareRemoteMailboxesToO365.ps1:
--------------------------------------------------------------------------------
1 | # Find mailboxes for synced accounts, where the mailbox exists in Exchange Online but doesn't exist on-prem as a remote mailbox.
2 | #
3 | # Like the other stuff in this folder, it's a bit of a niche scenario.
4 | # We're looking for mailboxes which were created in on-prem AD and then licenced in the cloud without a remote mailbox being created on the on-prem Exchange server, so that we can remote mail enable them correctly.
5 | #
6 | # This is a bit complicated as it requires connected to two Exchange environments at once, so uses command prefixes for one of them.
7 | #
8 |
9 | # What is the FQDN of the on-prem Exchange server?
10 | $exchangeServerFQDN = ''
11 |
12 | # What is your remote routing address? E.g.: @domain.mail.onmicrosoft.com
13 | $remoteRoutingSuffix = '@domain.mail.onmicrosoft.com'
14 |
15 | # Find and load the new ExO "module"
16 | $exoModulePath = (Get-ChildItem -Path $env:userprofile -Filter CreateExoPSSession.ps1 -Recurse -Force -ErrorAction SilentlyContinue).DirectoryName[-1]
17 | . "$exoModulePath\CreateExoPSSession.ps1"
18 |
19 | # Establish a session to Exchange Online
20 | Connect-EXOPSSession
21 |
22 | # Create Exchange on-prem connection Uri from FQDN
23 | $exchangeConnectionUri = 'http://' + $exchangeServerFQDN +'/PowerShell/'
24 |
25 | # Establish a session to Exchange on-prem and add the OnPrem prefix to all commands
26 | $userCredential = Get-Credential
27 | $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $exchangeConnectionUri -Authentication Kerberos -Credential $userCredential
28 | Import-PSSession $session -DisableNameChecking -Prefix OnPrem
29 |
30 | # Get list of mailboxes from Exchange online for synced users
31 | $allOnlineMailboxes = Get-Mailbox -ResultSize Unlimited | Where-Object {$_.IsDirSynced -eq $true -and $_.Name -notlike 'DiscoverySearchMailbox*'}
32 |
33 | # Get list of remote mailboxes from on-prem server
34 | $allOnPremMailboxes = Get-OnPremRemoteMailbox -ResultSize Unlimited
35 |
36 | # Compare the two lists and add those missing from the on-prem list to the $syncedMailboxMismatch hashtable
37 | $syncedMailboxMismatch = $allOnlineMailboxes | Where-Object {$allOnPremMailboxes.PrimarySmtpAddress -notcontains $_.PrimarySmtpAddress}
38 |
39 | # Find mailboxes where alias and username match
40 | $matchedUPNAliases = $syncedMailboxMismatch | Where-Object {$_.Alias -eq $_.UserPrincipalName.Split('@')[0]}
41 |
42 | # Find mailboxes where alias and username don't match
43 | $mismatchedUPNAliases = $syncedMailboxMismatch | Where-Object {$_.Alias -ne $_.UserPrincipalName.Split('@')[0]}
44 |
45 | # Fix the mailboxes where username and alias matched.
46 | foreach ($mailboxToRemoteEnable in $matchedUPNAliases) {
47 | $mailboxUsername = $mailboxToRemoteEnable.UserPrincipalName.Split('@')[0]
48 | $mailboxToFix = $mailboxToRemoteEnable.UserPrincipalName
49 | $remoteRoutingAddress = $mailboxUsername + $remoteRoutingSuffix
50 | Enable-OnPremRemoteMailbox -Identity $mailboxToFix -RemoteRoutingAddress $remoteRoutingAddress
51 | }
52 |
53 | # Write out the mailboxes that have been updated
54 | Write-Output -InputObject ('The following mailboxes have been remote mail enabled.')
55 | $matchedUPNAliases | Select-Object Name,Alias,UserPrincipalName,PrimarySmtpAddress
56 |
57 | # Write out the mailboxes that have been left due to a mismatch between username and alias
58 | Write-Output -InputObject ('The following mailboxes have not been changed because they have a mismatch between email alias and username.')
59 | $mismatchedUPNAliases | Select-Object Name,Alias,UserPrincipalName,PrimarySmtpAddress
60 |
61 | # End the Exchange Session
62 | Remove-PSSession -Session $session
63 |
--------------------------------------------------------------------------------
/ExchangeWithAADConnect/DisableRemoteMailUser.ps1:
--------------------------------------------------------------------------------
1 | # Disable a list of mail users
2 | #
3 |
4 | # What is the FQDN of the on-prem Exchange server?
5 | $exchangeServerFQDN = ''
6 |
7 | # What accounts are we disabling?
8 | $usersToDisable = @('','')
9 |
10 | # Create Exchange connection Uri from FQDN
11 | $exchangeConnectionUri = 'http://' + $exchangeServerFQDN +'/PowerShell/'
12 |
13 | # Establish a session to Exchange
14 | $userCredential = Get-Credential
15 | $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $exchangeConnectionUri -Authentication Kerberos -Credential $userCredential
16 | Import-PSSession $session -DisableNameChecking -AllowClobber
17 |
18 | # Get list of mailboxes
19 | foreach ($userToDisable in $usersToDisable) {
20 | Disable-RemoteMailbox -Identity $userToDisable -Confirm:$false
21 | }
22 |
23 | # End the Exchange Session
24 | Remove-PSSession -Session $session
25 |
--------------------------------------------------------------------------------
/ExchangeWithAADConnect/GetMailboxesBasedOnPrimarySMTP.ps1:
--------------------------------------------------------------------------------
1 | # Find mailboxes using a specific email domain and export list to CSV file
2 | #
3 |
4 | # What is the FQDN of the on-prem Exchange server?
5 | $exchangeServerFQDN = ''
6 |
7 | # Primary SMTP domain to search for
8 | $primarySMTP = ''
9 |
10 | # Where are we saving the output file?
11 | $outputFile = 'C:\Temp\Mailboxes.csv'
12 |
13 | # Create Exchange connection Uri from FQDN
14 | $exchangeConnectionUri = 'http://' + $exchangeServerFQDN +'/PowerShell/'
15 |
16 | # Establish a session to Exchange
17 | $userCredential = Get-Credential
18 | $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $exchangeConnectionUri -Authentication Kerberos -Credential $userCredential
19 | Import-PSSession $session -DisableNameChecking
20 |
21 | # Get list of mailboxes
22 | $allMailboxes = Get-RemoteMailbox -ResultSize Unlimited | Where-Object {($_.PrimarySmtpAddress.Split('@')[1] -eq $primarySMTP)}
23 |
24 | # Export results to CSV file
25 | $allMailboxes | Select-Object Name,Alias,UserPrincipalName,PrimarySmtpAddress,EmailAddresses | Export-Csv -Path $outputFile -NoTypeInformation
26 |
27 | # End the Exchange Session
28 | Remove-PSSession -Session $session
29 |
--------------------------------------------------------------------------------
/ExchangeWithAADConnect/README.md:
--------------------------------------------------------------------------------
1 | # Exchange Online with AzureAD Connect
2 |
3 | ## What is this?
4 |
5 | The scripts in this folder are for managing mailboxes in a synced environment, where you have an Exchange server on-prem purely for management purposes. This means all mailboxes are seen as "remote" mailboxes, so all the scripts use commands to that effect. These can easily be updated to a normal environment like on-prem only or cloud only just by removing the work "remote" from the commands. For example, Get-RemoteMailbox to just Get-Mailbox.
6 |
7 | ## Pre-requisites
8 |
9 | These scripts require you to have on-prem Active Directory with an on-prem Exchange server for management, and using AzureAD Connect to sync to AzureAD.
10 |
11 | It's pretty niche.
12 |
13 | ## Disclaimer
14 |
15 | All scripts are provided as is without warranty of any kind, use them at your own risk.
16 |
--------------------------------------------------------------------------------
/ExchangeWithMFA/AddGuestsToGAL.ps1:
--------------------------------------------------------------------------------
1 | # Bulk change guest accounts from a certain domain so that they show in the Global Address List
2 | #
3 | # Uses the new PowerShell "module" that support MFA.
4 | #
5 |
6 | # What domain are the guests email addresses from?
7 | $guestDomain = ''
8 |
9 | # Find and load the new ExO "module"
10 | $exoModulePath = (Get-ChildItem -Path $env:userprofile -Filter CreateExoPSSession.ps1 -Recurse -Force -ErrorAction SilentlyContinue).DirectoryName[-1]
11 | . "$exoModulePath\CreateExoPSSession.ps1"
12 |
13 | # Establish a session to Exchange Online
14 | Connect-EXOPSSession
15 |
16 | # Find all the relevant users and enable them to show in the address list
17 | Get-MailUser -ResultSize Unlimited | Where-Object {$_.RecipientTypeDetails -eq 'GuestMailUser' -and $_.EmailAddresses -match $guestDomain} | Set-MailUser -HiddenFromAddressListsEnabled $false
18 |
19 | # End the Exchange Session
20 | Get-PSSession | Where-Object {$_.ComputerName -eq 'outlook.office365.com'} | Remove-PSSession
21 |
--------------------------------------------------------------------------------
/ExchangeWithMFA/AddRoomCalendarEditors.ps1:
--------------------------------------------------------------------------------
1 | # Create a group and add it to all room mailboxes as an editor
2 | #
3 | # Uses the new PowerShell "module" that support MFA.
4 | #
5 |
6 | # What do you want the editors group to be called?
7 | $editorsGroup = 'Calendar Editors'
8 |
9 | # Who do you want to be in the group? This can be 1 or more people.
10 | $editorsMembers = @('','')
11 |
12 | # Find and load the new ExO "module"
13 | $exoModulePath = (Get-ChildItem -Path $env:userprofile -Filter CreateExoPSSession.ps1 -Recurse -Force -ErrorAction SilentlyContinue).DirectoryName[-1]
14 | . "$exoModulePath\CreateExoPSSession.ps1"
15 |
16 | # Establish a session to Exchange Online
17 | Connect-EXOPSSession
18 |
19 | # Get all room mailboxes in the organisation
20 | $roomMailboxes = (Get-Mailbox -RecipientTypeDetails RoomMailbox).Alias
21 |
22 | # If the editors group doesn't exist, create it.
23 | if (!(Get-DistributionGroup -Identity $editorsGroup -ErrorAction SilentlyContinue)) {
24 | New-DistributionGroup -Name $editorsGroup -Type Security
25 | }
26 |
27 | # Add members to the group
28 | $existingMembers = Get-DistributionGroupMember -Identity $editorsGroup
29 | foreach ($editorsMember in $editorsMembers) {
30 | if ($editorsMember -notin $existingMembers.Name) {
31 | Add-DistributionGroupMember -Identity $editorsGroup -Member $editorsMember
32 | }
33 | }
34 |
35 | # Add the permissions to the mailboxes
36 | foreach ($roomMailbox in $roomMailboxes) {
37 | $calendarFolder = $mailboxAlias + ':\calendar'
38 | Add-MailboxFolderPermission -Identity $calendarFolder -User $editorsGroup -AccessRights Editor
39 | }
40 |
41 | # End the Exchange Session
42 | Get-PSSession | Where-Object {$_.ComputerName -eq 'outlook.office365.com'} | Remove-PSSession
43 |
--------------------------------------------------------------------------------
/ExchangeWithMFA/BlockEmailForwardingToSpecificDomains.ps1:
--------------------------------------------------------------------------------
1 | # Create a rule to block email forwarding to specific domains.
2 | #
3 | # Uses the new PowerShell "module" that support MFA.
4 | #
5 |
6 | # What domains are we blocking?
7 | $domainListFile = 'C:\Temp\DomainList.txt'
8 |
9 | # What do we want to call the rule?
10 | $ruleName = 'Block Auto Forwarding to Specific Domains 4'
11 |
12 | # What reason do we want end users to see for the rejection?
13 | $rejectionReason = 'Auto forwarding messages to this email provider is not permitted.'
14 |
15 | # Find and load the new ExO "module"
16 | $exoModulePath = (Get-ChildItem -Path $env:userprofile -Filter CreateExoPSSession.ps1 -Recurse -Force -ErrorAction SilentlyContinue).DirectoryName[-1]
17 | . "$exoModulePath\CreateExoPSSession.ps1"
18 |
19 | # Establish a session to Exchange Online
20 | Connect-EXOPSSession
21 |
22 | # Get the domain list from the file
23 | $domainList = Get-Content -Path $domainListFile
24 |
25 | # Create a new rule
26 | $parameters = @{
27 | 'Name' = $ruleName;
28 | 'FromScope' = 'InOrganization';
29 | 'SenderAddressLocation' = 'Header'
30 | 'RecipientDomainIs' = $domainList;
31 | 'MessageTypeMatches' = 'AutoForward';
32 | 'RejectMessageEnhancedStatusCode' = '5.7.1'
33 | 'RejectMessageReasonText' = $rejectionReason;
34 | 'Priority' = 0;
35 | 'Mode' = 'Enforce'
36 | 'Enabled' = $true
37 | }
38 | New-TransportRule @parameters
39 |
40 | # End the Exchange Session
41 | Get-PSSession | Where-Object {$_.ComputerName -eq 'outlook.office365.com'} | Remove-PSSession
42 |
--------------------------------------------------------------------------------
/ExchangeWithMFA/BulkRemoveProxyAddresses.ps1:
--------------------------------------------------------------------------------
1 | # Script to bulk remove email proxy addresses from Exchange Online users
2 | #
3 |
4 | # Which domains are we removing?
5 | $domainsToRemove = @('','')
6 |
7 | # Find and load the new ExO "module"
8 | $exoModulePath = (Get-ChildItem -Path $env:userprofile -Filter CreateExoPSSession.ps1 -Recurse -Force -ErrorAction SilentlyContinue).DirectoryName[-1]
9 | . "$exoModulePath\CreateExoPSSession.ps1"
10 |
11 | # Establish a session to Exchange Online
12 | Connect-EXOPSSession
13 |
14 | ### Remove the domain from mailboxes ###
15 |
16 | # Get All Mailboxes
17 | $allMailboxes = Get-Mailbox -ResultSize Unlimited | Sort-Object -Property alias
18 |
19 | # Remove alias from each mailbox
20 | foreach ($mailbox in $allMailboxes) {
21 | $redundantAddresses = @()
22 | foreach ($domainToRemove in $domainsToRemove) {
23 | $redundantAddresses += (($mailbox.EmailAddresses -split ',' | Where-Object {$_ -like ('*' + $domainToRemove + '*')}) -replace 'smtp:','')
24 | }
25 | if ($redundantAddresses.Count -gt 0) {
26 | Write-Output -InputObject ('Removing addresses ' + $redundantAddresses + ' from maibox ' + $mailbox.Name)
27 | Set-Mailbox -Identity $mailbox.Identity -EmailAddresses @{remove=$redundantAddresses} -Confirm:$false
28 | }
29 | }
30 |
31 | ###
32 |
33 | ### Remove the domain from contacts ###
34 |
35 | # Get all the contacts
36 | $allContacts = Get-MailContact -ResultSize Unlimited | Sort-Object -Property alias
37 |
38 | # Remove alias from each contact
39 | foreach ($contact in $allContacts) {
40 | $redundantAddresses = @()
41 | foreach ($domainToRemove in $domainsToRemove) {
42 | $redundantAddresses += (($contact.EmailAddresses -split ',' | Where-Object {$_ -like ('*' + $domainToRemove + '*')}) -replace 'smtp:','')
43 | }
44 | if ($redundantAddresses.Count -gt 0) {
45 | Write-Output -InputObject ('Removing addresses ' + $redundantAddresses + ' from contact ' + $contact.Name)
46 | Set-MailContact -Identity $contact.Identity -EmailAddresses @{remove=$redundantAddresses} -Confirm:$false -ForceUpgrade:$true
47 | }
48 | }
49 |
50 | ###
51 |
52 | ### Remove the domain from groups ###
53 |
54 | # Get all the groups (this includes email enabled security groups)
55 | $allGroups = Get-DistributionGroup -ResultSize Unlimited | Sort-Object -Property alias
56 |
57 | # Remove alias from each group
58 | foreach ($group in $allGroups) {
59 | $redundantAddresses = @()
60 | foreach ($domainToRemove in $domainsToRemove) {
61 | $redundantAddresses += (($group.EmailAddresses -split ',' | Where-Object {$_ -like ('*' + $domainToRemove + '*')}) -replace 'smtp:','')
62 | }
63 | if ($redundantAddresses.Count -gt 0) {
64 | Write-Output -InputObject ('Removing addresses ' + $redundantAddresses + ' from group ' + $group.Name)
65 | Set-DistributionGroup -Identity $group.Identity -EmailAddresses @{remove=$redundantAddresses} -Confirm:$false
66 | }
67 | }
68 |
69 | ###
70 |
71 | ### Remove the domain from public folders ###
72 |
73 | # Get all the groups (this includes email enabled security groups)
74 | $allPublicFolders = Get-MailPublicFolder -ResultSize Unlimited | Sort-Object -Property alias
75 |
76 | # Remove alias from each public folder
77 | foreach ($publicFolder in $allPublicFolders) {
78 | $redundantAddresses = @()
79 | foreach ($domainToRemove in $domainsToRemove) {
80 | $redundantAddresses += (($publicFolder.EmailAddresses -split ',' | Where-Object {$_ -like ('*' + $domainToRemove + '*')}) -replace 'smtp:','')
81 | }
82 | if ($redundantAddresses.Count -gt 0) {
83 | Write-Output -InputObject ('Removing addresses ' + $redundantAddresses + ' from public folder ' + $publicFolder.Name)
84 | Set-MailPublicFolder -Identity $publicFolder.Identity -EmailAddresses @{remove=$redundantAddresses} -Confirm:$false
85 | }
86 | }
87 |
88 | ###
89 |
90 | # End the Exchange Session
91 | Get-PSSession | Where-Object {$_.ComputerName -eq 'outlook.office365.com'} | Remove-PSSession
92 |
--------------------------------------------------------------------------------
/ExchangeWithMFA/EnableExchangeModernAuth.ps1:
--------------------------------------------------------------------------------
1 | # Enable Modern Authentication in Exchange Online
2 | #
3 | # Uses the new PowerShell "module" that support MFA.
4 | #
5 |
6 | # Find and load the new ExO "module"
7 | $exoModulePath = (Get-ChildItem -Path $env:userprofile -Filter CreateExoPSSession.ps1 -Recurse -Force -ErrorAction SilentlyContinue).DirectoryName[-1]
8 | . "$exoModulePath\CreateExoPSSession.ps1"
9 |
10 | # Establish a session to Exchange Online
11 | Connect-EXOPSSession
12 |
13 | # Enable modern authentication
14 | Set-OrganizationConfig -OAuth2ClientProfileEnabled $true
15 |
16 | # Verify the setting has changed
17 | Get-OrganizationConfig | Format-Table -AutoSize Name,OAuth2ClientProfileEnabled
18 |
19 | # End the Exchange Session
20 | Get-PSSession | Where-Object {$_.ComputerName -eq 'outlook.office365.com'} | Remove-PSSession
21 |
--------------------------------------------------------------------------------
/ExchangeWithMFA/EnableMailboxAuditing.ps1:
--------------------------------------------------------------------------------
1 | # Enable mailbox auditing on mailboxes where auditing is not already enabled
2 | #
3 | # This is a rewrite of a script from https://github.com/OfficeDev/O365-InvestigationTooling
4 | #
5 |
6 | # Find and load the new ExO "module"
7 | $exoModulePath = (Get-ChildItem -Path $env:userprofile -Filter CreateExoPSSession.ps1 -Recurse -Force -ErrorAction SilentlyContinue).DirectoryName[-1]
8 | . "$exoModulePath\CreateExoPSSession.ps1"
9 |
10 | # Establish a session to Exchange Online
11 | Connect-EXOPSSession
12 |
13 | # Set Auditing parameters
14 | $params = @{
15 | 'AuditEnabled' = $true
16 | 'AuditLogAgeLimit' = '180'
17 | 'AuditAdmin' = @('Update','MoveToDeletedItems','SoftDelete','HardDelete','SendAs','SendOnBehalf','Create','UpdateFolderPermission')
18 | 'AuditDelegate' = @('Update','SoftDelete','HardDelete','SendAs','Create','UpdateFolderPermissions','MoveToDeletedItems','SendOnBehalf')
19 | 'AuditOwner' = @('UpdateFolderPermission','MailboxLogin','Create','SoftDelete','HardDelete','Update','MoveToDeletedItems')
20 | }
21 |
22 | # Enable Auditing
23 | Get-Mailbox -ResultSize Unlimited | Where-Object {$_.RecipientTypeDetails -match '(User|Shared|Room|Discovery)Mailbox' -and $_.AuditEnabled -eq $false} | Set-Mailbox @params
24 |
25 | # Check Auditing
26 | Get-Mailbox -ResultSize Unlimited | Where-Object {$_.RecipientTypeDetails -match '(User|Shared|Room|Discovery)Mailbox'} | Format-Table -AutoSize UserPrincipalName,RecipientTypeDetails,AuditEnabled,AuditLogAgeLimit
27 |
28 | # End the Exchange Session
29 | Get-PSSession | Where-Object {$_.ComputerName -eq 'outlook.office365.com'} | Remove-PSSession
30 |
--------------------------------------------------------------------------------
/ExchangeWithMFA/FindUsersWithMismatchedDomains.ps1:
--------------------------------------------------------------------------------
1 | # Find mailboxes where UPN domain doesn't match email domain
2 | #
3 |
4 | # Find and load the new ExO "module"
5 | $exoModulePath = (Get-ChildItem -Path $env:userprofile -Filter CreateExoPSSession.ps1 -Recurse -Force -ErrorAction SilentlyContinue).DirectoryName[-1]
6 | . "$exoModulePath\CreateExoPSSession.ps1"
7 |
8 | # Establish a session to Exchange Online
9 | Connect-EXOPSSession
10 |
11 | # Get list of mailboxes with a different mail domain to UPN domain
12 | Get-Mailbox -ResultSize Unlimited | Where-Object {$_.UserPrincipalName.Split('@')[1] -ne $_.PrimarySmtpAddress.Split('@')[1]} | Format-Table Name,UserPrincipalName,PrimarySmtpAddress,RecipientTypeDetails
13 |
14 | # End the Exchange Session
15 | Get-PSSession | Where-Object {$_.ComputerName -eq 'outlook.office365.com'} | Remove-PSSession
16 |
--------------------------------------------------------------------------------
/ExchangeWithMFA/GetDistributionGroupsAndMembers.ps1:
--------------------------------------------------------------------------------
1 | # Find shared mailboxes on the basis of their email domain and lists of who has access to them
2 | #
3 | # Uses the new PowerShell "module" that support MFA.
4 | #
5 |
6 | # Where to save the CSV files to
7 | $outputFile = 'C:\Temp\GroupDetails.csv'
8 |
9 | # Wildcard for groups to find
10 | $searchWildcard = '*@example.domain'
11 |
12 | # Find and load the new ExO "module"
13 | $exoModulePath = (Get-ChildItem -Path $env:userprofile -Filter CreateExoPSSession.ps1 -Recurse -Force -ErrorAction SilentlyContinue).DirectoryName[-1]
14 | . "$exoModulePath\CreateExoPSSession.ps1"
15 |
16 | # Establish a session to Exchange Online
17 | Connect-EXOPSSession
18 |
19 | # Get all the groups we're looking for
20 | $allGroups = Get-DistributionGroup | Where-Object {$_.PrimarySmtpAddress -like $searchWildcard}
21 |
22 | # Initialise the hash table to store results in
23 | $groupDetails = @()
24 |
25 | # Run through the groups getting the members and adding
26 | foreach ($group in $allGroups) {
27 | $groupMembers = (Get-DistributionGroupMember -Identity $group.Name).Alias -join '; '
28 | $groupDetails += [PSCustomObject]@{
29 | 'GroupName' = $group.Name;
30 | 'GroupEmail' = $group.PrimarySmtpAddress;
31 | 'GroupType' = $group.GroupType;
32 | 'GroupMembers' = $groupMembers
33 | }
34 | }
35 |
36 | # Export results to CSV file
37 | $groupDetails | Export-Csv -Path $outputFile -NoTypeInformation
38 |
39 | # End the Exchange Session
40 | Get-PSSession | Where-Object {$_.ComputerName -eq 'outlook.office365.com'} | Remove-PSSession
41 |
--------------------------------------------------------------------------------
/ExchangeWithMFA/GetMailboxPermissionsForList.ps1:
--------------------------------------------------------------------------------
1 | # Get the permissions and sendas rights for a list of mailboxes and output them to CSV
2 | #
3 | # Uses the new PowerShell "module" that support MFA.
4 | #
5 |
6 | # Where to save the CSV files to
7 | $outputPath = 'C:\Temp\MailboxPermissions\'
8 |
9 | # What mailboxes are we checking?
10 | $mailboxes = Get-Content -Path 'C:\Temp\Mailboxes.txt'
11 |
12 | # Find and load the new ExO "module"
13 | $exoModulePath = (Get-ChildItem -Path $env:userprofile -Filter CreateExoPSSession.ps1 -Recurse -Force -ErrorAction SilentlyContinue).DirectoryName[-1]
14 | . "$exoModulePath\CreateExoPSSession.ps1"
15 |
16 | # Establish a session to Exchange Online
17 | Connect-EXOPSSession
18 |
19 | # Get all non-inherited mailbox permissions excluding self and output to a CSV file named for each mailbox
20 | foreach ($mailbox in $mailboxes) {
21 | Write-Output -InputObject ('Getting permissions for mailbox ' + $mailbox)
22 | $mailboxPermissions = Get-MailboxPermission -Identity $mailbox | Where-Object {$_.IsInherited -eq $false -and $_.User -ne 'NT AUTHORITY\SELF'} | Select-Object Identity,User,AccessRights,Deny
23 | if ($mailboxPermissions.Count -gt 0) {
24 | $outputFile = $outputPath + 'MailboxPermissions_' + ($mailbox -replace '@','_') + '.csv'
25 | $mailboxPermissions | Export-CSV -Path $outputFile -NoTypeInformation
26 | }
27 | }
28 |
29 | # Get all non-inherited recipient permissions (sendas) excluding self and output to a CSV file named for each mailbox
30 | foreach ($mailbox in $mailboxes) {
31 | Write-Output -InputObject ('Getting permissions for recipient ' + $mailbox)
32 | $recipientPermissions = Get-RecipientPermission -Identity $mailbox | Where-Object {$_.IsInherited -eq $false -and $_.Trustee -ne 'NT AUTHORITY\SELF'} | Select-Object Identity,Trustee,AccessRights,AccessControlType
33 | if ($recipientPermissions.Count -gt 0) {
34 | $outputFile = $outputPath + 'RecipientPermissions_' + ($mailbox -replace '@','_') + '.csv'
35 | $recipientPermissions | Export-CSV -Path $outputFile -NoTypeInformation
36 | }
37 | }
38 |
39 | # End the Exchange Session
40 | Get-PSSession | Where-Object {$_.ComputerName -eq 'outlook.office365.com'} | Remove-PSSession
41 |
--------------------------------------------------------------------------------
/ExchangeWithMFA/GetSharedMailboxPermissions.ps1:
--------------------------------------------------------------------------------
1 | # Find shared mailboxes on the basis of their email domain and lists of who has access to them
2 | #
3 | # Uses the new PowerShell "module" that support MFA.
4 | #
5 |
6 | # Where to save the CSV files to
7 | $outputPath = 'C:\Temp\'
8 |
9 | # Wildcard for mailboxes to find
10 | $searchWildcard = '*'
11 |
12 | # Find and load the new ExO "module"
13 | $exoModulePath = (Get-ChildItem -Path $env:userprofile -Filter CreateExoPSSession.ps1 -Recurse -Force -ErrorAction SilentlyContinue).DirectoryName[-1]
14 | . "$exoModulePath\CreateExoPSSession.ps1"
15 |
16 | # Establish a session to Exchange Online
17 | Connect-EXOPSSession
18 |
19 | # Get all the mailboxes we're looking for
20 | $sharedMailboxes = Get-Mailbox -RecipientTypeDetails SharedMailbox -ResultSize Unlimited | Where-Object {$_.PrimarySmtpAddress -like $searchWildcard} | Select-Object Name,Alias,PrimarySmtpAddress,ProhibitSendQuota
21 |
22 | # Export list of mailboxes to CSV File
23 | $sharedMailboxes | Export-CSV -Path ($outputPath + 'Shared Mailboxes.csv') -NoTypeInformation
24 |
25 | # Get all non-inherited permissions excluding self and output to a CSV file named for each group
26 | foreach ($sharedMailbox in $sharedMailboxes) {
27 | $mailboxPermissions = Get-MailboxPermission -Identity $sharedMailbox.alias | Where-Object {$_.IsInherited -eq $false -and $_.User -ne 'NT AUTHORITY\SELF'} | Select-Object Identity,User,AccessRights,Deny
28 | $mailboxPermissions | Export-CSV -Path ($outputPath + $sharedMailbox.Name + '.csv') -NoTypeInformation
29 | }
30 |
31 | # End the Exchange Session
32 | Get-PSSession | Where-Object {$_.ComputerName -eq 'outlook.office365.com'} | Remove-PSSession
33 |
--------------------------------------------------------------------------------
/ExchangeWithMFA/README.md:
--------------------------------------------------------------------------------
1 | # Exchange Online with MFA Support
2 |
3 | ## What is this?
4 |
5 | Connecting to Exchange Online through a remote PowerShell session doesn't work when using multi factor authentication. You can (apparrently) get round that by creating an application password, but I've never got it to work and in my mind creating a password to bypass MFA somewhat defeates the point of enabling MFA in the first place.
6 |
7 | There now is a new "module" available which does support MFA, so this folder is where I'll be putting new scripts that support MFA or old scripts as I update them.
8 |
9 | ## Pre-requisites
10 |
11 | To connect using MFA you have to locally install a new module from Microsoft. Which for whatever reason isn't available from PSGallery, nor can it be simply downloaded. Instead it has to be installed from within the Exchange Online admin centre using one of those annoying ClickOnce installers that only work in MS's own web browsers.
12 |
13 | Microsoft have a document explaining the unnecessarily convulted install process here:
14 |
15 | [Connect to Exchange Online PowerShell using multi-factor authentication](https://docs.microsoft.com/en-us/powershell/exchange/exchange-online/connect-to-exchange-online-powershell/mfa-connect-to-exchange-online-powershell?view=exchange-ps)
16 |
17 | In addition, because this will be using a remote session it will require the script execution policy within PowerShell to be changed to RemoteSigned. This is done either globally with:
18 |
19 | `Set-ExecutionPolicy -ExecutionPolicy RemoteSigned`
20 |
21 | Or for the current user with:
22 |
23 | `Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser`
24 |
25 | ## Disclaimer
26 |
27 | All scripts are provided as is without warranty of any kind, use them at your own risk.
28 |
--------------------------------------------------------------------------------
/ExchangeWithMFA/ResetCalendarDefaultPermissions.ps1:
--------------------------------------------------------------------------------
1 | # Reset default calendar permissions to availability for a list of users.
2 | #
3 | # Uses the new PowerShell "module" that support MFA.
4 | #
5 |
6 | # File with list of users
7 | $userlistPath = 'C:\Temp\Userlist.txt'
8 |
9 | # Find and load the new ExO "module"
10 | $exoModulePath = (Get-ChildItem -Path $env:userprofile -Filter CreateExoPSSession.ps1 -Recurse -Force -ErrorAction SilentlyContinue).DirectoryName[-1]
11 | . "$exoModulePath\CreateExoPSSession.ps1"
12 |
13 | # Establish a session to Exchange Online
14 | Connect-EXOPSSession
15 |
16 | # Get list of users
17 | $userlist = Get-Content -Path $userlistPath
18 |
19 | # Get mailboxes for users in list
20 | $mailboxes = Get-Mailbox -ResultSize Unlimited | Where-Object {$_.Name -in $userlist} | Sort-Object -Property Name
21 |
22 | # Check the mailboxes and reset any which have default permissions of None to AvailabilityOnly
23 | foreach ($mailbox in $mailboxes) {
24 | $calendarPath = $mailbox.UserPrincipalName + ':\Calendar'
25 | $defaultPermissions = Get-MailboxFolderPermission -Identity $calendarPath -User 'Default'
26 | if ($defaultPermissions.AccessRights -eq 'None') {
27 | Set-MailboxFolderPermission -Identity $calendarPath -User 'Default' -AccessRights AvailabilityOnly
28 | }
29 | }
30 |
31 | # End the Exchange Session
32 | Get-PSSession | Where-Object {$_.ComputerName -eq 'outlook.office365.com'} | Remove-PSSession
33 |
--------------------------------------------------------------------------------
/ExchangeWithMFA/SetupForwardingForListOfUSers.ps1:
--------------------------------------------------------------------------------
1 | # A simple script to enable forwarding for a list of users from a CSV file
2 | #
3 | # The script is expecting the CSV file to have two columns called SourceAddress and DestinationAddress
4 | #
5 |
6 | # Get the list of users from a CSV file
7 | $userList = Import-Csv -Path 'C:\Temp\UserList.csv'
8 |
9 | # Find and load the new ExO "module"
10 | $exoModulePath = (Get-ChildItem -Path $env:userprofile -Filter CreateExoPSSession.ps1 -Recurse -Force -ErrorAction SilentlyContinue).DirectoryName[-1]
11 | . "$exoModulePath\CreateExoPSSession.ps1"
12 |
13 | # Establish a session to Exchange Online
14 | Connect-EXOPSSession
15 |
16 | # Get all non-inherited permissions excluding self and output to a CSV file named for each group
17 | foreach ($user in $userList) {
18 | Write-Output -InputObject ('Forwarding ' + $user.SourceAddress + ' to ' + $user.DestinationAddress)
19 | Set-Mailbox -Identity $user.SourceAddress -ForwardingSmtpAddress $user.DestinationAddress
20 | }
21 |
22 | # Pull back a list to check everything has worked correctly
23 | foreach ($user in $userList) {
24 | Get-Mailbox -Identity $user.SourceAddress | Select-Object UserPrincipalName,ForwardingSmtpAddress,DeliverToMailboxAndForward
25 | }
26 |
27 | # End the Exchange Session
28 | Get-PSSession | Where-Object {$_.ComputerName -eq 'outlook.office365.com'} | Remove-PSSession
29 |
--------------------------------------------------------------------------------
/ExchangeWithMFA/SetupRoomMailbox.ps1:
--------------------------------------------------------------------------------
1 | # Create and set up a room mailbox.
2 | #
3 | # Uses the new PowerShell "module" that support MFA.
4 | #
5 |
6 | # New room name and alias
7 | $displayName = ''
8 | $mailboxAlias = ''
9 |
10 | # How many people can the room take?
11 | $roomCapacity = ''
12 |
13 | # Do you want meeting requests to be auto accepted?
14 | $requestAutoAccept = $true
15 |
16 | # Do we want to add the room to a room list?
17 | $addToRoomList = $true
18 |
19 | # What is the room list called? (Will be created if it doesn't exist)
20 | $roomList = ''
21 |
22 | # Find and load the new ExO "module"
23 | $exoModulePath = (Get-ChildItem -Path $env:userprofile -Filter CreateExoPSSession.ps1 -Recurse -Force -ErrorAction SilentlyContinue).DirectoryName[-1]
24 | . "$exoModulePath\CreateExoPSSession.ps1"
25 |
26 | # Establish a session to Exchange Online
27 | Connect-EXOPSSession
28 |
29 | # Create the new room mailbox
30 | New-Mailbox -Room -Alias $mailboxAlias -Name $displayName -DisplayName $displayName -ResourceCapacity $roomCapacity
31 |
32 | # Wait for the meeting room mailbox to process
33 | Start-Sleep -Seconds 30
34 |
35 | # Set the mailbox calendar to auto accept meeting requests (assuming policies are met)
36 | if ($requestAutoAccept) {
37 | Set-CalendarProcessing $mailboxAlias -AutomateProcessing AutoAccept
38 | }
39 |
40 | # If we're adding the room to a room list, then do that.
41 | if ($addToRoomList) {
42 | # If the room list doesn't exist, create it.
43 | if (!(Get-DistributionGroup -Identity $roomList -ErrorAction SilentlyContinue)) {
44 | New-DistributionGroup -Name $roomList -RoomList
45 | }
46 |
47 | # Add the room to the list
48 | Add-DistributionGroupMember -Identity $roomList -Member $mailboxAlias
49 | }
50 |
51 | # End the Exchange Session
52 | Get-PSSession | Where-Object {$_.ComputerName -eq 'outlook.office365.com'} | Remove-PSSession
53 |
--------------------------------------------------------------------------------
/Intune/ScheduledBitlockerKeyBackup.ps1:
--------------------------------------------------------------------------------
1 | # ScheduledBitLockerKeyBackup.ps1
2 |
3 | <#
4 | Script intended for deployment through Intune:
5 | Creates a locally saved PS script to get the bitlocker key and save it to Azure.
6 | Then creates a scheduled task to run that script at every logon.
7 | #>
8 |
9 | # Name and description for the schedulled task to be created
10 | $taskName = 'Bitlocker Key Backup to AzureAD'
11 | $taskDescription = 'Retrieve Bitlocker key for system drive and store it in AzureAD'
12 |
13 | # Day, time and randomised delay for the task to be created
14 | $taskDay = 'Monday'
15 | $taskTime = '12:00:00'
16 | $taskDelay = '00:20:00'
17 |
18 | # Path to the folder for the files to be created
19 | $scriptFolder = 'C:\ProgramData\Intune\Scripts\'
20 |
21 | # Names of the files to be created
22 | $scriptFilename = 'BitlockerKeyBackup.ps1'
23 | $scriptLogFilename = 'BitlockerKeyBackup-LastRun.log'
24 | $deployLogFilename = 'BitlockerKeyBackup-Deployed.log'
25 |
26 | # Establish full paths to the files
27 | $scriptPath = $scriptFolder + $scriptFilename
28 | $logPath = $scriptFolder + $scriptLogFilename
29 | $deployLogPath = $scriptFolder + $deployLogFilename
30 |
31 | # If folder doesn't exist create it, else clean up files from last run
32 | if (!(Test-Path -Path $scriptFolder)) {
33 | New-Item -Path $scriptFolder -ItemType Directory
34 | }
35 | else {
36 | foreach ($filePath in @($scriptPath, $logPath, $deployLogPath)) {
37 | if (Test-Path -Path $filePath) {
38 | Remove-Item -Path $filePath
39 | }
40 | }
41 | }
42 |
43 | # Contents of the PS script file to be created on the target machine
44 | $scriptContents = @(
45 | '$logPath = ''' + $logPath + ''''
46 | 'try {'
47 | ' $recoveryPassword = ((Get-BitlockerVolume -MountPoint $env:SystemDrive -ErrorAction Stop).KeyProtector | Where-Object {$_.KeyProtectorType -eq "RecoveryPassword"})'
48 | ' $result = BackupToAAD-BitLockerKeyProtector $env:systemdrive -KeyProtectorId $recoveryPassword.KeyProtectorId -ErrorAction Stop'
49 | ' Out-File -InputObject $result -FilePath $logPath'
50 | '}'
51 | 'catch {'
52 | ' Out-File -InputObject $Error[0].Exception.Message -FilePath $logPath'
53 | '}'
54 | )
55 |
56 | # Create the script file
57 | Out-File -InputObject $scriptContents -FilePath $scriptPath
58 |
59 | # Set up the various parts of the scheduled task
60 | $taskArgument = '-ExecutionPolicy Bypass -Command ". ' + $scriptPath + '"'
61 | $taskAction = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument $taskArgument -WorkingDirectory $scriptFolder
62 | $taskTrigger = New-ScheduledTaskTrigger -Weekly -DaysOfWeek $taskDay -At $taskTime -RandomDelay $taskDelay
63 | $taskPrincipal = New-ScheduledTaskPrincipal -UserId 'SYSTEM' -LogonType 'ServiceAccount' -RunLevel 'Highest'
64 | $taskSettings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -Compatibility 'Win8' -Hidden -StartWhenAvailable
65 |
66 | # If the scheduled task already exists then remove it
67 | if (Get-ScheduledTask | Where-Object { $_.TaskName -eq $taskName }) {
68 | Unregister-ScheduledTask -TaskName $taskName -Confirm:$false
69 | }
70 |
71 | # Create the scheduled task and run it immediately
72 | $taskCreated = Register-ScheduledTask -Action $taskAction -Trigger $taskTrigger -TaskName $taskName -Description $taskDescription -Principal $taskPrincipal -Settings $taskSettings
73 | Start-ScheduledTask -TaskName $taskName
74 |
75 | # Create a log file for the deployment of the scheduled task
76 | Out-File -InputObject $taskCreated -FilePath $deployLogPath
77 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 | {one line to give the program's name and a brief idea of what it does.}
635 | Copyright (C) {year} {name of author}
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | {project} Copyright (C) {year} {fullname}
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/MSOnline/ADGUIDToImmutableID.ps1:
--------------------------------------------------------------------------------
1 | # Convert AD GUID to 365 ImmutableID
2 |
3 | $adGuid = Read-Host -Prompt 'Enter Active Directory GUID to convert to ImmutableID'
4 | [System.Convert]::ToBase64String($adGuid.tobytearray())
5 |
--------------------------------------------------------------------------------
/MSOnline/BulkAddLicenceConditional.ps1:
--------------------------------------------------------------------------------
1 | # Bulk add a new licence to users on the basis of what licence they currently have
2 | #
3 | # This is useful for something like adding Office 365 ATP to everyone who currently has E3, for example.
4 | #
5 |
6 | # What licence do the users currently have?
7 | $existingLicence = ''
8 |
9 | # What licence are we adding?
10 | $licenceToAdd = ''
11 |
12 | # Import MSOnline module and connect
13 | Import-Module MSOnline
14 | Connect-MsolService
15 |
16 | # Find everyone who has the existing
17 | $users = Get-MsolUser -All | Where-Object {($_.licenses).AccountSkuId -match $existingLicence -and !(($_.licenses).AccountSkuId -match $licenceToAdd)}
18 |
19 | # Add the new licence
20 | foreach ($user in $users) {
21 | Set-MSOLUserLicense -UserPrincipalName $user.UserPrincipalName –AddLicenses $licenceToAdd
22 | }
23 |
--------------------------------------------------------------------------------
/MSOnline/BulkAddLicences.ps1:
--------------------------------------------------------------------------------
1 | # Bulk add additional licences to a list of users where they already have a licence assigned.
2 | #
3 | # Only works where the user already has a licence assigned as assigning a licence to an unlicenced user is a different process.
4 | #
5 |
6 | # Where is the list of user UPN's?
7 | $userListPath = 'C:\Temp\UserList.txt'
8 |
9 | # What licences are we adding?
10 | # List of available SKUs can be obtained with (Get-MsolAccountSku).AccountSkuId
11 | $licencesToAdd = @('','')
12 |
13 | # Import MSOnline module and connect
14 | Import-Module MSOnline
15 | Connect-MsolService
16 |
17 | # Import list of users from file
18 | $users = Get-Content -Path $userListPath | Sort-Object
19 |
20 | # Add the new licence
21 | foreach ($user in $users) {
22 | $userDetails = Get-MSOLUser -UserPrincipalName $user
23 | foreach ($licenceToAdd in $licencesToAdd) {
24 | if ($userDetails.IsLicensed -eq $true) {
25 | if (!(($userDetails.licenses).AccountSkuId -match $licenceToAdd)) {
26 | Write-Output -InputObject ('Adding Licence ' + $licenceToAdd + ' to ' + $user + '.')
27 | Set-MSOLUserLicense -UserPrincipalName $user –AddLicenses $licenceToAdd
28 | }
29 | else {
30 | Write-Output -InputObject ('User ' + $user + ' already has ' + $licenceToAdd + ' licence assigned.')
31 | }
32 | }
33 | else {
34 | Write-Output -InputObject ('User ' + $user + ' has no existing licence assigned.')
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/MSOnline/BulkChangeMFASetting.ps1:
--------------------------------------------------------------------------------
1 | # Bulk enable or disable MFA for all users in a tenant
2 | #
3 |
4 | # Enable or disable MFA?
5 | $enableMFA = $true
6 |
7 | # Import MSOnline module and connect
8 | Import-Module MSOnline
9 | Connect-MsolService
10 |
11 | # Enable or disable MFA
12 | if ($enableMFA) {
13 | # Create an object containing the authentication requirements
14 | $authReq = New-Object -TypeName Microsoft.Online.Administration.StrongAuthenticationRequirement
15 |
16 | # Include all relying parties
17 | $authReq.RelyingParty = '*'
18 |
19 | # Set MFA state to enabled
20 | # Enabled allows connected apps to keep working until the user completes MFA set up.
21 | # This can also be set to enforced which would disconnect everything immediately.
22 | $authReq.State = 'Enabled'
23 |
24 | # Set the cut off date before which registered devices should require re-connecting with MFA.
25 | # Using the current date is recommended so that all previously connected devices have to be reconnected.
26 | $authReq.RememberDevicesNotIssuedBefore = (Get-Date)
27 |
28 | # Find all licenced users who do not currently have MFA enabled or enforced
29 | $usersToChange = Get-MsolUser | Where-Object {$_.StrongAuthenticationRequirements.State -notmatch 'Enabled|Enforced' -and $_.isLicensed -eq $true}
30 |
31 | # Enable MFA for those users
32 | $usersToChange | Set-MsolUser -StrongAuthenticationRequirements $authReq
33 | }
34 | else {
35 | # Find all licenced users who currently have MFA enabled or enforced
36 | $usersToChange = Get-MsolUser | Where-Object {$_.StrongAuthenticationRequirements.State -match 'Enabled|Enforced' -and $_.isLicensed -eq $true}
37 |
38 | # Disable MFA for those users
39 | $usersToChange | Set-MsolUser -StrongAuthenticationRequirements @()
40 | }
41 |
42 |
43 |
--------------------------------------------------------------------------------
/MSOnline/BulkChangeOnlineUserUPN.ps1:
--------------------------------------------------------------------------------
1 | # Bulk update Online User UPNs
2 | #
3 |
4 | # What domain are we replacing?
5 | $oldDomain = ''
6 |
7 | # What are we replacing it with?
8 | $newDomain = ''
9 |
10 | # Import the MSOnline module and connect
11 | Import-Module MSOnline
12 | Connect-MsolService
13 |
14 | # Get all users using that domain as their UPN
15 | $users = Get-MsolUser -All | Where-Object {$_.UserPrincipalName -match $oldDomain}
16 |
17 | # Run through the users replacing their UPN and keeping us updated on what's going on
18 | foreach ($user in $users) {
19 | $newUPN = $user.UserPrincipalName.Split('@')[0] + '@' + $newDomain
20 | Write-Output -InputObject ('Setting UPN for user ' + $user.UserPrincipalName + ' to ' + $newUPN)
21 | Set-MsolUserPrincipalName -UserPrincipalName $user.UserPrincipalName -NewUserPrincipalName $newUPN
22 | }
23 |
--------------------------------------------------------------------------------
/MSOnline/BulkDisableMFA.ps1:
--------------------------------------------------------------------------------
1 | # Disable MFA for all licenced users who currently have it enabled
2 | #
3 |
4 | # Import MSOnline module and connect
5 | Import-Module MSOnline
6 | Connect-MsolService
7 |
8 | # Find all licenced users who currently have MFA enabled or enforced
9 | $usersToChange = Get-MsolUser | Where-Object {$_.StrongAuthenticationRequirements.State -match 'Enabled|Enforced' -and $_.isLicensed -eq $true}
10 |
11 | # Disable MFA for those users
12 | $usersToChange | Set-MsolUser -StrongAuthenticationRequirements @()
13 |
--------------------------------------------------------------------------------
/MSOnline/BulkEnableMFA.ps1:
--------------------------------------------------------------------------------
1 | # Enable MFA for all licenced users who don't currently have it enabled
2 | #
3 |
4 | # Import MSOnline module and connect
5 | Import-Module MSOnline
6 | Connect-MsolService
7 |
8 | # Create an object containing the authentication requirements
9 | $authReq = New-Object -TypeName Microsoft.Online.Administration.StrongAuthenticationRequirement
10 |
11 | # Include all relying parties
12 | $authReq.RelyingParty = '*'
13 |
14 | # Set MFA state to enabled
15 | # Enabled allows connected apps to keep working until the user completes MFA set up.
16 | # This can also be set to enforced which would disconnect everything immediately.
17 | $authReq.State = 'Enabled'
18 |
19 | # Set the cut off date before which registered devices should require re-connecting with MFA
20 | $authReq.RememberDevicesNotIssuedBefore = (Get-Date)
21 |
22 | # Find all licenced users who do not currently have MFA enabled or enforced
23 | $usersToChange = Get-MsolUser | Where-Object {$_.StrongAuthenticationRequirements.State -notmatch 'Enabled|Enforced' -and $_.isLicensed -eq $true}
24 |
25 | # Enable MFA for those users
26 | $usersToChange | Set-MsolUser -StrongAuthenticationRequirements $authReq
27 |
--------------------------------------------------------------------------------
/MSOnline/BulkRemoveLicence.ps1:
--------------------------------------------------------------------------------
1 | # Bulk remove a licence from users
2 | #
3 |
4 | # What licence are we removing?
5 | $licenceToRemove = ''
6 |
7 | # Import MSOnline module and connect
8 | Import-Module MSOnline
9 | Connect-MsolService
10 |
11 | # Find everyone who has the licence to be removed
12 | $users = Get-MsolUser -All | Where-Object {($_.licenses).AccountSkuId -match $licenceToRemove}
13 |
14 | # Remove the licence
15 | foreach ($user in $users) {
16 | Set-MSOLUserLicense –user $user.UserPrincipalName –RemoveLicenses $licenceToRemove
17 | }
18 |
--------------------------------------------------------------------------------
/MSOnline/BulkReplaceLicence.ps1:
--------------------------------------------------------------------------------
1 | # Bulk replace a licence for all users who have the one being replaced.
2 | #
3 |
4 | # What licence are we removing?
5 | $licenceToRemove = ''
6 |
7 | # What licence are we adding?
8 | $licenceToAdd = ''
9 |
10 | # Import MSOnline module and connect
11 | Import-Module MSOnline
12 | Connect-MsolService
13 |
14 | # Find everyone who has the licence being replaced
15 | $users = Get-MsolUser -All | Where-Object {($_.licenses).AccountSkuId -match $licenceToRemove}
16 |
17 | # Remove the old licence and add the new one
18 | foreach ($user in $users) {
19 | Set-MSOLUserLicense –user $user.UserPrincipalName –RemoveLicenses $licenceToRemove
20 | Set-MSOLUserLicense –user $user.UserPrincipalName -AddLicenses $licenceToAdd
21 | }
22 |
--------------------------------------------------------------------------------
/MSOnline/ChangeOnlineUserUPN.ps1:
--------------------------------------------------------------------------------
1 | # Update Online User UPN - when AD sync doesn't do it.
2 |
3 | # Import the MSOL module and connect
4 | Import-Module MSOnline
5 | Connect-MsolService
6 |
7 | # Whose UPN are we changing?
8 | $oldUPN = Read-Host -Prompt 'Enter user''s old UPN in the format username@domain'
9 |
10 | # What are we changing it to?
11 | $newUPN = Read-Host -Prompt 'Enter user''s new UPN in the format username@domain'
12 |
13 | # Change the UPN
14 | if (Get-ADUser -Identity $newUPN.Split('@')[0]) {
15 | Set-MsolUserPrincipalName -UserPrincipalName $oldUPN -NewUserPrincipalName $newUPN
16 | }
17 |
--------------------------------------------------------------------------------
/MSOnline/CompletelyDeleteAUser.ps1:
--------------------------------------------------------------------------------
1 | # Delete a user and then delete the deleted user
2 |
3 | Import-Module MSOnline
4 | Connect-MsolService
5 |
6 | $upnToDelete = Read-Host -Prompt 'Enter UPN of user to delete in the format username@domain'
7 |
8 | Remove-MsolUser -UserPrincipalName $upnToDelete
9 | Remove-MsolUser -UserPrincipalName $upnToDelete -RemoveFromRecycleBin
10 |
--------------------------------------------------------------------------------
/MSOnline/FixDuplicateSyncObject.ps1:
--------------------------------------------------------------------------------
1 | # Remove a duplicate 365 account created by a faulty sync and reconnect
2 | # the orphaned 365 user to the AD account.
3 | #
4 |
5 | # Get correct and incorrect account details
6 | $adUsername = Read-Host -Prompt 'Enter username for AD account'
7 | $msolIncorrectUPN = Read-Host -Prompt 'Enter UPN for the duplicate object in MSOL'
8 |
9 | # Connect to MS Online
10 | Import-Module MSOnline
11 | Connect-MsolService
12 |
13 | # Get AD user account
14 | $adObject = Get-ADUser -Identity $adUsername
15 |
16 | # Get correct UPN from AD account
17 | $msolCorrectUPN = $adObject.UserPrincipalName
18 |
19 | #
20 | try {
21 | Get-MsolUser -UserPrincipalName $msolCorrectUPN -ErrorAction Stop
22 |
23 | Remove-MSOLuser -UserPrincipalName $msolIncorrectUPN
24 | Remove-MSOLuser -UserPrincipalName $msolIncorrectUPN -RemoveFromRecycleBin
25 |
26 | $adGuid = $adObject.ObjectGuid
27 | $immutableID = [System.Convert]::ToBase64String($adGuid.ToByteArray())
28 |
29 | Set-MSOLuser -UserPrincipalName $msolCorrectUPN -ImmutableID $immutableID
30 | }
31 | catch {
32 | Write-Host 'No account found in Azure AD matching the UPN for that AD account.'
33 | }
34 |
--------------------------------------------------------------------------------
/MSOnline/ImmutableIDToADGUID.ps1:
--------------------------------------------------------------------------------
1 | # Convert 365 ImmutableID to AD GUID
2 |
3 | $immutableID = Read-Host -Prompt 'Enter ImmutableID to convert to Active Directory GUID'
4 | [GUID][System.Convert]::FromBase64String($immutableID)
5 |
--------------------------------------------------------------------------------
/OneDrive/GetOneDriveQuotas.ps1:
--------------------------------------------------------------------------------
1 | # Retrive a list of all OneDrive for Business sites within the organisation
2 | #
3 | # Requires the Sharepoint Online PowerShell module to be installed
4 | #
5 |
6 | # The name of your Office 365 organization
7 | # This can be found in your Sharepoint URL before the '-my', eg: https://thecompany-my.sharepoint.com/
8 | $spoTenantName=''
9 |
10 | # Connect to Sharepoint Online
11 | Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
12 | Connect-SPOService -Url ('https://' + $spoTenantName + '-admin.sharepoint.com')
13 |
14 | # Create the common base URL for OneDrive for Business
15 | $spoBaseWildcard = 'https://' + $spoTenantName + '-my.sharepoint.com/personal/*'
16 |
17 | # Get a list of all 'personal' sites (e.g.: OneDrive for Business sites) within the tenant
18 | Get-SPOSite -Limit all -IncludePersonalSite $true | Where-Object {$_.Url -like $spoBaseWildcard} | Select-Object Owner,URL,StorageQuota | Format-Table -AutoSize
19 |
--------------------------------------------------------------------------------
/OneDrive/IncreaseOneDriveQuota.ps1:
--------------------------------------------------------------------------------
1 | # Increase the size of specific users' OneDrive for Business accounts
2 | #
3 | # Requires the Sharepoint Online PowerShell module to be installed
4 | #
5 |
6 | # The name of your Office 365 organization
7 | # This can be found in your Sharepoint URL before the '-my', eg: https://thecompany-my.sharepoint.com/
8 | $spoTenantName=''
9 |
10 | # The size you want to increase to in TB.
11 | $newSize = 1
12 |
13 | # The list of UPNs for the accounts you wich to add the secondary admin to (list can contain a single item if required)
14 | $userList = @('','')
15 |
16 | # Connect to Sharepoint Online
17 | Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
18 | Connect-SPOService -Url ('https://' + $spoTenantName + '-admin.sharepoint.com')
19 |
20 | # Create the base URL for OneDrive for Business
21 | $spoBaseURL = 'https://' + $spoTenantName + '-my.sharepoint.com/personal/'
22 |
23 | # Convert new size to bytes
24 | $newBytes = $newSize * 1048576
25 |
26 | # Increase size for each user in list
27 | foreach ($userUPN in $userList) {
28 | $spoURL = $spoBaseURL + ($userUPN.ToLower() -replace "[@.]", "_")
29 | try {
30 | $currentBytes = (Get-SPOSite -Identity $spoURL -ErrorAction:Stop).StorageQuota
31 | if ($currentBytes -gt $newBytes) {
32 | try {
33 | Set-SPOSite -Identity $spoURL -StorageQuota $newBytes -ErrorAction:Stop
34 | Write-Output -InputObject ('Updated OneDrive account limit for ' + $userUPN + ' to ' + $newSize + 'TB.')
35 | }
36 | catch {
37 | Write-Output -InputObject ('Failed to update OneDrive account limit for ' + $userUPN + '.')
38 | }
39 | }
40 | else {
41 | Write-Output -InputObject ('OneDrive account limit for ' + $userUPN + ' already equal to or higher than ' + $newSize + 'TB.')
42 | }
43 | }
44 | catch {
45 | Write-Output -InputObject ('No OneDrive account found for ' + $userUPN + '.')
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/OneDrive/IncreaseOneDriveQuotaAll.ps1:
--------------------------------------------------------------------------------
1 | # Increase the size of all users' OneDrive for Business accounts
2 | #
3 | # Requires the Sharepoint Online PowerShell module to be installed
4 | #
5 |
6 | # The name of your Office 365 organization
7 | # This can be found in your Sharepoint URL before the '-my', eg: https://thecompany-my.sharepoint.com/
8 | $spoTenantName=''
9 |
10 | # The size you want to increase to in TB.
11 | $newSize = 1
12 |
13 | # Connect to Sharepoint Online
14 | Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
15 | Connect-SPOService -Url ('https://' + $spoTenantName + '-admin.sharepoint.com')
16 |
17 | # Create the common base URL for OneDrive for Business
18 | $spoBaseWildcard = 'https://' + $spoTenantName + '-my.sharepoint.com/personal/*'
19 |
20 | # Convert new size to bytes
21 | $newBytes = $newSize * 1048576
22 |
23 | # Get a list of all personal sites within the tenant.
24 | $personalSites = Get-SPOSite -Limit all -IncludePersonalSite $true | Where-Object {$_.Url -like $spoBaseWildcard}
25 |
26 | # Increase size for each user in turn.
27 | foreach ($personalSite in $personalSites) {
28 | $spoURL = $personalSite.Url
29 | $userUPN = $personalSite.Owner
30 | $currentBytes = $personalSite.StorageQuota
31 |
32 | if ($currentBytes -lt $newBytes) {
33 | try {
34 | Set-SPOSite -Identity $spoURL -StorageQuota $newBytes -ErrorAction:Stop
35 | Write-Output -InputObject ('Updated OneDrive account limit for ' + $userUPN + ' to ' + $newSize + 'TB.')
36 | }
37 | catch {
38 | Write-Output -InputObject ('Failed to update OneDrive account limit for ' + $userUPN + '.')
39 | }
40 | }
41 | else {
42 | Write-Output -InputObject ('OneDrive account limit for ' + $userUPN + ' already equal to or higher than ' + $newSize + 'TB.')
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/OneDrive/OneDriveForBusinessAddAdmin.ps1:
--------------------------------------------------------------------------------
1 | # Add a collection administrator to your users' OneDrive for Business accounts
2 | #
3 | # Requires the Sharepoint Online PowerShell module to be installed
4 | #
5 |
6 | # The name of your Office 365 organization
7 | # This can be found in your Sharepoint URL before the '-my', eg: https://thecompany-my.sharepoint.com/
8 | $spoTenantName=''
9 |
10 | # The UPN of the account you wish to add as a secondary admin
11 | $secondaryAdminUPN = ''
12 |
13 | # The list of UPNs for the accounts you wich to add the secondary admin to
14 | $userList = @('','')
15 |
16 | # Connect to Sharepoint Online
17 | Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
18 | Connect-SPOService -Url ('https://' + $spoTenantName + '-admin.sharepoint.com')
19 |
20 | # Create the base URL for OneDrive for Business
21 | $spoBaseURL = 'https://' + $spoTenantName + '-my.sharepoint.com/personal/'
22 |
23 | # Add secondary admin to each user in the list
24 | foreach ($userUPN in $userList) {
25 | $spoURL = $spoBaseURL + ($userUPN.ToLower() -replace "[@.]", "_")
26 | Set-SPOUser -Site $spoURL -LoginName $secondaryAdminUPN -IsSiteCollectionAdmin $true -ErrorAction:Continue
27 | }
28 |
--------------------------------------------------------------------------------
/OneDrive/OneDriveForBusinessRemoveAdmin.ps1:
--------------------------------------------------------------------------------
1 | # Remove a collection administrator from your users' OneDrive for Business accounts
2 | #
3 | # Requires the Sharepoint Online PowerShell module to be installed
4 | #
5 |
6 | # The name of your Office 365 organization
7 | # This can be found in your Sharepoint URL before the '-my', eg: https://thecompany-my.sharepoint.com/
8 | $spoTenantName=''
9 |
10 | # The UPN of the account you wish to add as a secondary admin
11 | $secondaryAdminUPN = ''
12 |
13 | # The list of UPNs for the accounts you wich to add the secondary admin to
14 | $userList = @('','')
15 |
16 | # Connect to Sharepoint Online
17 | Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
18 | Connect-SPOService -Url ('https://' + $spoTenantName + '-admin.sharepoint.com')
19 |
20 | # Create the base URL for OneDrive for Business
21 | $spoBaseURL = 'https://' + $spoTenantName + '-my.sharepoint.com/personal/'
22 |
23 | # Add secondary admin to each user in the list
24 | foreach ($userUPN in $userList) {
25 | $spoURL = $spoBaseURL + ($userUPN.ToLower() -replace "[@.]", "_")
26 | Set-SPOUser -Site $spoURL -LoginName $secondaryAdminUPN -IsSiteCollectionAdmin $false -ErrorAction:Continue
27 | Remove-SPOUser -Site $spoURL -LoginName $secondaryAdminUPN
28 | }
29 |
--------------------------------------------------------------------------------
/OneDrive/ResetOneDriveQuotas.ps1:
--------------------------------------------------------------------------------
1 | # Retrive a list of all OneDrive for Business sites, check their size and reset it if it is less than the default
2 | #
3 | # Requires the Sharepoint Online PowerShell module to be installed
4 | #
5 |
6 | # The name of your Office 365 organization
7 | # This can be found in your Sharepoint URL before the '-my', eg: https://thecompany-my.sharepoint.com/
8 | $spoTenantName=''
9 |
10 | # Connect to Sharepoint Online
11 | Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
12 | Connect-SPOService -Url ('https://' + $spoTenantName + '-admin.sharepoint.com')
13 |
14 | # Create the common base URL for OneDrive for Business
15 | $spoBaseWildcard = 'https://' + $spoTenantName + '-my.sharepoint.com/personal/*'
16 |
17 | # Get the default quota for the tenant
18 | $defaultQuota = (Get-SPOTenant).OneDriveStorageQuota
19 |
20 | # Get a list of all 'personal' sites (e.g.: OneDrive for Business sites) within the tenant
21 | $usersToReset = Get-SPOSite -Limit all -IncludePersonalSite $true | Where-Object {$_.Url -like $spoBaseWildcard -and $_.StorageQuota -lt $defaultQuota}
22 |
23 | # Get a list of all 'personal' sites (e.g.: OneDrive for Business sites) within the tenant
24 | foreach ($userToReset in $usersToReset) {
25 | Write-Output -InputObject ('Resetting user ' + $userToReset.Owner)
26 | Set-SPOSite -Identity $userToReset.Url -StorageQuotaReset
27 | }
28 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Office 365
2 |
3 | **Scripting things in Office 365.**
4 |
5 | ## Pre-requisites
6 |
7 | Some Office 365 services require modules to be installed locally, whereas others use remote
8 | PowerShell sessions.
9 |
10 | Microsoft have instructions on how to install modules or connect to services here:
11 | [Connect PowerShell to Office 365 Services](https://support.office.com/en-us/article/Connect-PowerShell-to-Office-365-services-06a743bb-ceb6-49a9-a61d-db4ffdf54fa6)
12 |
13 | The SharePoint module can also now be installed directly from PSGallery using:
14 |
15 | `Install-Module -Name Microsoft.Online.SharePoint.PowerShell`
16 |
17 | In addition, the services which use remote sessions will require the script execution policy within
18 | PowerShell to be changed to RemoteSigned. This is done either globally with:
19 |
20 | `Set-ExecutionPolicy -ExecutionPolicy RemoteSigned`
21 |
22 | Or for the current user with:
23 |
24 | `Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser`
25 |
26 | ## Disclaimer
27 |
28 | All scripts are provided as is without warranty of any kind, use them at your own risk.
29 |
--------------------------------------------------------------------------------
/SharePoint/CheckAllSitesForUser.ps1:
--------------------------------------------------------------------------------
1 | # Script to go through all SPO sites and check if a user is assigned to them
2 | #
3 |
4 | # This is the name of your tenant, as shown in the URL when accessing SharePoint online
5 | # E.g.: https://.sharepoint.com/
6 | $spoTenantName = ''
7 |
8 | # Who are we looking for? (uses a wildcard like comparison)
9 | $loginNameLike = ''
10 |
11 | # Connect to Sharepoint Online
12 | Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
13 | Connect-SPOService -Url ('https://' + $spoTenantName + '-admin.sharepoint.com')
14 |
15 | # Get all SharePoint Online sites
16 | $allSpoSites = Get-SPOSite -Limit All
17 |
18 | # Run through the sites...
19 | foreach ($spoSite in $allSpoSites) {
20 | # Try to get a list of users for the current site - requires owner access to the site.
21 | try {
22 | $spoUsers = Get-SPOUser -Site $spoSite.Url -Limit All -ErrorAction:Stop | Where-Object {$_.LoginName -like $loginNameLike}
23 | $usersRetrived = $true
24 | }
25 | catch {
26 | $spoUsers = ''
27 | $usersRetrived = $false
28 | }
29 |
30 | # If the previous try didn't fail then work on the retrived list
31 | if ($usersRetrived) {
32 | # If the list isn't empty, then set the output message to the userlogin name and site URL.
33 | if ([string]$spoUsers.Count -gt 0) {
34 | foreach ($spoUser in $spoUsers) {
35 | $outputMessage = 'User ' + $spoUser.LoginName + ' found in site ' + $spoSite.Url
36 | }
37 | }
38 | # Else (if the list is empty) set the output message to reflect that the user wasn't found in that group.
39 | else {
40 | $outputMessage = 'User not found in site ' + $spoSite.Url
41 | }
42 | }
43 | # If users weren't retrived then set the output message to reflect that.
44 | else {
45 | $outputMessage = 'Unable to get users from site: ' + $spoSite.Url
46 | }
47 | # Finally write out the output message.
48 | Write-Output -InputObject $outputMessage
49 | }
50 |
--------------------------------------------------------------------------------
/SharePoint/GetSiteDetails.ps1:
--------------------------------------------------------------------------------
1 | # Script to go through all SPO sites and check if a user is assigned to them
2 | #
3 |
4 | # This is the name of your tenant, as shown in the URL when accessing SharePoint online
5 | # E.g.: https://.sharepoint.com/
6 | $spoTenantName = ''
7 |
8 | # Who are we looking for? (uses a wildcard like comparison)
9 | $siteNameLike = '*'
10 |
11 | # Connect to Sharepoint Online
12 | Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
13 | Connect-SPOService -Url ('https://' + $spoTenantName + '-admin.sharepoint.com')
14 |
15 | # Get all SharePoint Online sites
16 | $allSpoSites = Get-SPOSite -Limit All | Where-Object {$_.Title -like $siteNameLike}
17 |
18 | Get-SpoSiteGroup
19 |
20 |
21 | # Run through the sites...
22 | foreach ($spoSite in $allSpoSites) {
23 | # Try to get a list of users for the current site - requires owner access to the site.
24 | $allSiteGroups = Get-SpoSiteGroup -Site $spoSite.Url
25 | foreach ($siteGroup in $allSiteGroups) {
26 | Write-Host
27 | $siteGroup | Select-Object -ExpandProperty Users
28 | }
29 | }
30 |
31 | $spoUsers | Export-Csv C:\Temp\SISLive-Sharepoint-Site.csv -NoTypeInformation
32 |
33 | $allSpoSites
--------------------------------------------------------------------------------
/SkypeForBusiness/BulkEnableAudioConferencing.ps1:
--------------------------------------------------------------------------------
1 | # Enable all licenced users for Microsoft audio conferencing
2 | #
3 | # In addition to the SfB module this requires the MSOnline module so it can check who is licenced.
4 | #
5 |
6 | # Import MSOnline module and connect
7 | Import-Module MSOnline
8 | Connect-MsolService
9 |
10 | # Load the Skype Online Connector module and connect
11 | Import-Module SkypeOnlineConnector
12 | $sfbSession = New-CsOnlineSession
13 | Import-PSSession -Session $sfbSession
14 |
15 | # This can be just one licence, or several, eg. MCOMEETADV (audio conferencing), ENTERPRISEPREMIUM (E5) and MEETING_ROOM all include audio conferencing.
16 | # List of available SKUs can be obtained with (Get-MsolAccountSku).AccountSkuId
17 | $audioConferencingLicences = @('MCOMEETADV','ENTERPRISEPREMIUM','MEETING_ROOM')
18 |
19 | # Find everyone who has the audio conferencing licence(s) assigned
20 | $users = @()
21 | foreach ($audioConferencingLicence in $audioConferencingLicences) {
22 | $users += (Get-MsolUser -All | Where-Object {($_.licenses).AccountSkuId -match $audioConferencingLicence}).UserPrincipalName
23 | }
24 |
25 | # Get the default service number from your tenant
26 | $defaultServiceNumber = (Get-CsOnlineDialInConferencingBridge -Name 'Conference Bridge').DefaultServiceNumber
27 |
28 | # Enable conferencing for everyone on that list who doesn't already have it enabled
29 | foreach ($user in $users) {
30 | $currentProvider = (Get-CsOnlineDialInConferencingUserInfo -Identity $user).Provider
31 | if ($currentProvider -ne 'Microsoft') {
32 | Enable-CsOnlineDialInConferencingUser -ServiceNumber $defaultServiceNumber -ReplaceProvider -SendEmail
33 | }
34 | }
35 |
36 | # Disconnect
37 | Remove-PSSession -Session $sfbSession
38 |
--------------------------------------------------------------------------------
/SkypeForBusiness/EnableAudioConferencingForList.ps1:
--------------------------------------------------------------------------------
1 | # Enable Microsoft audio conferencing for a list of users
2 | #
3 | # Expects a CSV file with two columns, one containing the UserPrincipalName and the other containing the ServiceNumber.
4 | #
5 | # A list of dedicated conference numbers can be retrieved with:
6 | # (Get-CsOnlineDialInConferencingBridge -Name 'Conference Bridge').ServiceNumbers | Where-Object {$_.IsShared -eq $false}
7 | #
8 | # If the service number entry for a user in the CSV file is blank then the default will be used.
9 | #
10 |
11 | # Where is the list of users?
12 | $userListPath = 'C:\Temp\UserList.csv'
13 |
14 | # Load the Skype Online Connector module and connect
15 | Import-Module SkypeOnlineConnector
16 | $sfbSession = New-CsOnlineSession
17 | Import-PSSession -Session $sfbSession
18 |
19 | # Get list of users from file
20 | $users = Import-Csv -Path $userListPath
21 |
22 | # Get the conference bridge details
23 | $conferenceBridge = Get-CsOnlineDialInConferencingBridge -Name 'Conference Bridge'
24 |
25 | # Enable conferencing for everyone on that list who doesn't already have it enabled
26 | foreach ($user in $users) {
27 | if (($user.ServiceNumber).Length -gt 0) {
28 | $serviceNumber = $conferenceBridge.ServiceNumbers | Where-Object {$_.Number -eq $user.ServiceNumber}
29 | }
30 | else {
31 | $serviceNumber = $conferenceBridge.DefaultServiceNumber
32 | }
33 | $currentProvider = (Get-CsOnlineDialInConferencingUserInfo -Identity $user.UserPrincipalName).Provider
34 | if ($currentProvider -ne 'Microsoft') {
35 | Enable-CsOnlineDialInConferencingUser -Identity $user.UserPrincipalName -ServiceNumber $serviceNumber.Number -ReplaceProvider -SendEmail
36 | Write-Output -InputObject ('Audio conferencing enabled for ' + $user.UserPrincipalName + ' with number ' + $serviceNumber.Number + '.')
37 | }
38 | else {
39 | Write-Output -InputObject ('Audio conferencing already enabled for ' + $user.UserPrincipalName + '.')
40 | }
41 | }
42 |
43 | # Disconnect
44 | Remove-PSSession -Session $sfbSession
45 |
--------------------------------------------------------------------------------
/SkypeForBusiness/EnableSkypeModernAuth.ps1:
--------------------------------------------------------------------------------
1 | # Enable Modern Authentication in Skype for Business Online
2 | #
3 |
4 | # Load the Skype Online Connector module
5 | Import-Module SkypeOnlineConnector
6 |
7 | # Establish a session to Exchange Online
8 | $sfbSession = New-CsOnlineSession
9 | Import-PSSession -Session $sfbSession
10 |
11 | # Enable modern authentication
12 | Set-CsOAuthConfiguration -ClientAdalAuthOverride Allowed
13 |
14 | # Verify the setting has changed
15 | Get-CsOAuthConfiguration | Format-Table -AutoSize Identity,ClientAdalAuthOverride
16 |
17 | # End the PS Session
18 | Remove-PSSession -Session $sfbSession
19 |
--------------------------------------------------------------------------------
/SkypeForBusiness/ExportAll3rdPartyConferencing.ps1:
--------------------------------------------------------------------------------
1 | # Script to extract conferencing details for users from the AcpInfo setting
2 | #
3 |
4 | # Load the Skype Online Connector module
5 | Import-Module SkypeOnlineConnector
6 |
7 | # Establish a session to Exchange Online
8 | $sfbSession = New-CsOnlineSession
9 | Import-PSSession -Session $sfbSession
10 |
11 | # Company Wildcard
12 | $companyWildcard = '*'
13 |
14 | # AcpInfo Wildcard
15 | $acpInfoWildcard = '*BT*'
16 |
17 | # Output file
18 | $outputFile = 'C:\Temp\ConferencingUsers.csv'
19 |
20 | # Get all conferencing users matching the above wildcarded info
21 | $conferencingUsers = Get-CsOnlineUser -WarningAction:SilentlyContinue -ErrorAction:SilentlyContinue | Where-Object {($_.Company -like $companyWildcard) -and ($_.AcpInfo -like $acpInfoWildcard) -and ($_.Enabled -eq $true)} | Select-Object DisplayName,UserPrincipalName,AcpInfo
22 |
23 | # Set up user details hash table
24 | $userDetails = @()
25 |
26 | # Run through the users, check if they're in the exclusions list and if not then pull the details out of the AcpInfo code
27 | foreach ($conferencingUser in $conferencingUsers) {
28 | $tollNumber = ''
29 | if ([string]$conferencingUser.AcpInfo -match '(?.*)') {
30 | $tollNumber = $Matches.tollNumber
31 | }
32 |
33 | $tollFreeNumber = ''
34 | if ([string]$conferencingUser.AcpInfo -match '(?.*)') {
35 | $tollFreeNumber = $Matches.tollFreeNumber
36 | }
37 |
38 | $participantPassCode = ''
39 | if ([string]$conferencingUser.AcpInfo -match '(?.*)') {
40 | $participantPassCode = $Matches.participantPassCode
41 | }
42 |
43 | $domain = ''
44 | if ([string]$conferencingUser.AcpInfo -match '(?.*)') {
45 | $domain = $Matches.domain
46 | }
47 |
48 | $name = ''
49 | if ([string]$conferencingUser.AcpInfo -match '(?.*)') {
50 | $name = $Matches.name
51 | }
52 |
53 | $url = ''
54 | if ([string]$conferencingUser.AcpInfo -match '(?.*)') {
55 | $url = $Matches.url
56 | }
57 |
58 | $userDetails += [PSCustomObject]@{
59 | 'DisplayName' = [string]$conferencingUser.DisplayName
60 | 'UserPrincipalName' = [string]$conferencingUser.UserPrincipalName
61 | 'TollNumber' = [string]$tollNumber
62 | 'TollFreeNumber' = [string]$tollFreeNumber
63 | 'ParticipantPassCode' = [string]$participantPassCode
64 | 'Domain' = [string]$domain
65 | 'Name' = [string]$name
66 | 'Url' = [string]$url
67 | }
68 | }
69 |
70 | # Output to CSV file
71 | $userDetails | Export-Csv -Path $outputFile -NoTypeInformation
72 |
73 | # End the PS Session
74 | Remove-PSSession -Session $sfbSession
75 |
--------------------------------------------------------------------------------
/SkypeForBusiness/Remove3rdPartyConferencing.ps1:
--------------------------------------------------------------------------------
1 | # Script to bulk remove 3rd party conferencing details for all users
2 | #
3 |
4 | # Load the Skype Online Connector module
5 | Import-Module SkypeOnlineConnector
6 |
7 | # Establish a session to Exchange Online
8 | $sfbSession = New-CsOnlineSession
9 | Import-PSSession -Session $sfbSession -AllowClobber
10 |
11 | # Company Wildcard
12 | $companyWildcard = '*'
13 |
14 | # AcpInfo to match (doesn't need to be the full name)
15 | $acpInfoWildcard = '*BT*'
16 |
17 | # Get all conferencing users matching the above info
18 | $thirdPartyAcpUsers = Get-CsOnlineUser -WarningAction:SilentlyContinue -ErrorAction:SilentlyContinue | Where-Object {($_.Company -like $companyWildcard) -and ($_.AcpInfo -like $acpInfoWildcard) -and ($_.Enabled -eq $true)}
19 |
20 | # Run through the users and remove their ACP info
21 | foreach ($thirdPartyAcpUser in $thirdPartyAcpUsers) {
22 | $acpInfoName = ([xml]$thirdPartyAcpUser.AcpInfo).acpInformation.name
23 | Remove-CsUserAcp -Identity $thirdPartyAcpUser.Identity -Name $acpInfoName
24 | }
25 |
26 | # End the PS Session
27 | Remove-PSSession -Session $sfbSession
28 |
--------------------------------------------------------------------------------
/SkypeForBusiness/RemoveACPForUserList.ps1:
--------------------------------------------------------------------------------
1 | # Script to bulk remove conferencing details for a list of users
2 | #
3 |
4 | # Where is the list of user UPN's?
5 | $userListPath = 'C:\Temp\UserList.txt'
6 |
7 | # Load the Skype Online Connector module
8 | Import-Module SkypeOnlineConnector
9 |
10 | # Establish a session to Exchange Online
11 | $sfbSession = New-CsOnlineSession
12 | Import-PSSession -Session $sfbSession -AllowClobber
13 |
14 | # Import list of users from file
15 | $userList = Get-Content -Path $userListPath | Sort-Object
16 |
17 | # Get CS Online user identities for all the users in the list
18 | $csOnlineUsers = (Get-CsOnlineUser -WarningAction SilentlyContinue | Where-Object {$_.UserPrincipalName -in $userList}).Identity
19 |
20 | # Run through the users and remove their ACP info
21 | foreach ($csOnlineUser in $csOnlineUsers) {
22 | Remove-CsUserAcp -Identity $csOnlineUser
23 | }
24 |
25 | # End the PS Session
26 | Remove-PSSession -Session $sfbSession
27 |
--------------------------------------------------------------------------------
/SkypeForBusiness/UpdateAudioConferencingForList.ps1:
--------------------------------------------------------------------------------
1 | # Update Microsoft audio conferencing for a list of users
2 | #
3 | # Expects a CSV file with two columns, one containing the UserPrincipalName and the other containing the ServiceNumber.
4 | #
5 | # A list of dedicated conference numbers can be retrieved with:
6 | # (Get-CsOnlineDialInConferencingBridge -Name 'Conference Bridge').ServiceNumbers | Where-Object {$_.IsShared -eq $false}
7 | #
8 | # If the service number entry for a user in the CSV file is blank then the default will be used.
9 | #
10 |
11 | # Where is the list of users?
12 | $userListPath = 'C:\Temp\UsersToUpdate.csv'
13 |
14 | # Load the Skype Online Connector module and connect
15 | Import-Module SkypeOnlineConnector
16 | $sfbSession = New-CsOnlineSession
17 | Import-PSSession -Session $sfbSession
18 |
19 | # Get list of users from file
20 | $users = Import-Csv -Path $userListPath
21 |
22 | # Get the conference bridge details
23 | $conferenceBridge = Get-CsOnlineDialInConferencingBridge -Name 'Conference Bridge'
24 |
25 | # Enable conferencing for everyone on that list who doesn't already have it enabled
26 | foreach ($user in $users) {
27 | if (($user.ServiceNumber).Length -gt 0) {
28 | $serviceNumber = $conferenceBridge.ServiceNumbers | Where-Object {$_.Number -eq $user.ServiceNumber}
29 | }
30 | else {
31 | $serviceNumber = $conferenceBridge.DefaultServiceNumber
32 | }
33 | $currentTollNumber = (Get-CsOnlineDialInConferencingUserInfo -Identity $user.UserPrincipalName).DefaultTollNumber
34 | if ($currentTollNumber -ne $user.ServiceNumber) {
35 | Set-CsOnlineDialInConferencingUser -Identity $user.UserPrincipalName -ServiceNumber $serviceNumber.Number -SendEmail
36 | Write-Output -InputObject ('Audio conferencing updated for ' + $user.UserPrincipalName + ' with number ' + $serviceNumber.Number + '.')
37 | }
38 | }
39 |
40 | # Disconnect
41 | Remove-PSSession -Session $sfbSession
42 |
--------------------------------------------------------------------------------