Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Hudu-M365-MailboxPermissions-Documentation.ps1 #28

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 33 additions & 29 deletions CyberdrainRewrite/Hudu-M365-MailboxPermissions-Documentation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -89,40 +89,44 @@ foreach ($customer in $customers) {

foreach ($mailbox in $mailboxes) {
$AccesPermissions = Get-MailboxPermission -Identity $mailbox.identity | Where-Object { $_.user.tostring() -ne "NT AUTHORITY\SELF" -and $_.IsInherited -eq $false } -erroraction silentlycontinue | Select-Object User, accessrights
if ($AccesPermissions) { $HTMLPermissions += $AccesPermissions | convertto-html -frag -PreContent "Permissions on $($mailbox.PrimarySmtpAddress)" | Out-String }
}
Remove-PSSession $session

$AssetFields = @{
'tenantid' = $MSOLtentantID
if ($AccesPermissions)
#Only going to create or update an asset for a mailbox that has custom permissions
{ $HTMLPermissions += $AccesPermissions | convertto-html -frag -PreContent "Permissions on $($mailbox.PrimarySmtpAddress)" | Out-String
$AssetFields = @{
'mailbox_name' = $mailbox.DisplayName
'permissions' = $HTMLPermissions
'tenant_name' = $initialdomain.name
}

write-output "Uploading O365 guest $($guest.userprincipalname) into Hudu"
$companyid = $hududomain.company_id
$AssetName = "$defaultdomain - Permissions"
#Check if there is already an asset
$Asset = Get-HuduAssets -name $AssetName -companyid $companyid -assetlayoutid $Layout.id
'primary_smtp_address' = $mailbox.PrimarySmtpAddress
}

#If the Asset does not exist, we edit the body to be in the form of a new asset, if not, we just upload.
if (!$Asset) {
Write-Host "Creating new Asset"
$Asset = New-HuduAsset -name $AssetName -company_id $companyid -asset_layout_id $Layout.id -fields $AssetFields
}
else {
Write-Host "Updating Asset"
$Asset = Set-HuduAsset -asset_id $Asset.id -name $AssetName -company_id $companyid -asset_layout_id $layout.id -fields $AssetFields
}

$MSOLPrimaryDomain = $null
$MSOLtentantID = $null
$AccesPermissions = $null
$HTMLPermissions = $null
write-output "Uploading M365 mailbox permissions for $($mailbox.DisplayName) into Hudu"
$companyid = $hududomain.company_id
$AssetName = "$($mailbox.DisplayName) - Mailbox Permissions"
#Check if there is already an asset
$Asset = Get-HuduAssets -name $AssetName -companyid $companyid -assetlayoutid $Layout.id

#If the Asset does not exist, we edit the body to be in the form of a new asset, if not, we just upload.
if (!$Asset) {
Write-Host "Creating new Asset"
$Asset = New-HuduAsset -name $AssetName -company_id $companyid -asset_layout_id $Layout.id -fields $AssetFields
}
else {
Write-Host "Updating Asset"
$Asset = Set-HuduAsset -asset_id $Asset.id -name $AssetName -company_id $companyid -asset_layout_id $layout.id -fields $AssetFields
}

$MSOLPrimaryDomain = $null
$MSOLtentantID = $null
$AccesPermissions = $null
$HTMLPermissions = $null

}

}
Remove-PSSession $session


} else {
write-host "https://$defaultdomain Not found in Hudu. Please add as a website under the relevant customer" -ForegroundColor Red
}
}
}