Skip to content

Commit

Permalink
Allineamento 20240614(1)
Browse files Browse the repository at this point in the history
  • Loading branch information
gioxx committed Jun 20, 2024
1 parent a5bc08e commit b070798
Show file tree
Hide file tree
Showing 12 changed files with 305 additions and 111 deletions.
40 changes: 34 additions & 6 deletions Gioxx.ToyBox/Calendar/GTB.Calendar.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# Calendar =========================================================================================================================================================

function Clone-OoOMessage {
param(
[Parameter(Mandatory=$True, ValueFromPipeline=$True, HelpMessage="Mailbox from which to copy OoO messages (e.g. [email protected])")]
[string] $SourceMailbox,
[Parameter(Mandatory=$True, ValueFromPipeline=$True, HelpMessage="Mailbox on which to write copied OoO messages (e.g. [email protected])")]
[string] $DestinationMailbox
)

$eolConnectedCheck = priv_CheckEOLConnection

if ( $eolConnectedCheck -eq $true ) {
$externalMessage = (Get-MailboxAutoReplyConfiguration -Identity $SourceMailbox).ExternalMessage
$internalMessage = (Get-MailboxAutoReplyConfiguration -Identity $SourceMailbox).InternalMessage

Set-MailboxAutoReplyConfiguration -Identity $DestinationMailbox -AutoReplyState "Enabled" -InternalMessage $internalMessage -ExternalMessage $externalMessage
Get-MailboxAutoReplyConfiguration -Identity $DestinationMailbox | Select-Object -Property AutoReplyState,InternalMessage,ExternalMessage

} else {
Write-Error "`nCan't connect or use Microsoft Exchange Online Management module. `nPlease check logs."
}

}

function Export-CalendarPermission {
param(
[Parameter(Mandatory=$False, ValueFromPipeline=$True, HelpMessage="Mailbox to analyze (e.g. [email protected])")]
Expand All @@ -11,23 +34,24 @@ function Export-CalendarPermission {
)

begin {
$previousProgressPreference = $ProgressPreference
Set-Variable ProgressPreference Continue

$mboxCounter = 0
$arr_CalPerm = @()
$eolConnectedCheck = priv_CheckEOLConnection

if ( $eolConnectedCheck -eq $true ) {
Set-Variable ProgressPreference Continue

if ([string]::IsNullOrEmpty($SourceMailbox)) {
Write-Host "WARNING: no mailbox(es) specified, I scan all the mailboxes, please be patient." -f "Yellow"
Write-Warning "WARNING: no mailbox(es) specified, I scan all the mailboxes, please be patient."
$All = $True
}

if ($All) {
$SourceMailbox = Get-Mailbox -ResultSize Unlimited -WarningAction SilentlyContinue
}
} else {
Write-Host "`nCan't connect or use Microsoft Exchange Online Management module. `nPlease check logs." -f "Red"
Write-Error "`nCan't connect or use Microsoft Exchange Online Management module. `nPlease check logs."
Return
}
}
Expand Down Expand Up @@ -61,6 +85,8 @@ function Export-CalendarPermission {
} else {
$arr_CalPerm | Out-Host
}

Set-Variable ProgressPreference $previousProgressPreference
}
}

Expand Down Expand Up @@ -162,13 +188,15 @@ function Set-OoO {
Get-MailboxAutoReplyConfiguration -Identity $SourceMailbox

} else {
Write-Host "`nCan't connect or use Microsoft Exchange Online Management module. `nPlease check logs." -f "Red"
Write-Error "`nCan't connect or use Microsoft Exchange Online Management module. `nPlease check logs."
}

}


# Export Modules ===================================================================================================================================================
# Export Modules and Aliases =======================================================================================================================================

Export-ModuleMember -Alias *
Export-ModuleMember -Function "Clone-OoOMessage"
Export-ModuleMember -Function "Export-CalendarPermission"
Export-ModuleMember -Function "Set-OoO"
13 changes: 9 additions & 4 deletions Gioxx.ToyBox/Gioxx.ToyBox.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
".\Mailboxes\GTB.Mboxes.ps1",
'.\Main\GTB.Connections.ps1',
'.\Main\GTB.Tools.ps1',
'.\Main\GTB.Xtras.ps1',
".\Protection\GTB.Protection.ps1",
".\Protection\GTB.Quarantine.ps1",
".\Rooms\GTB.Room.ps1",
".\Statistics\GTB.Stats.ps1"
".\Statistics\GTB.Stats.ps1",
'.\Xtras\GTB.Custom.ps1',
'.\Xtras\Write-InformationColored.ps1'
)

ModuleVersion = '0.5'
Expand All @@ -32,6 +33,8 @@
"Add-MboxAlias",
"Add-MboxPermission",
"Change-MboxLanguage",
"Change-MFAStatus",
"Clone-OoOMessage",
"Connect-EOL",
"Connect-MSOnline",
"Export-CalendarPermission",
Expand Down Expand Up @@ -70,7 +73,9 @@
CmdletsToExport = @()

VariablesToExport = '*' # Variables to export from this module
AliasesToExport = @() # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
AliasesToExport = @(
"rqf"
) # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.

PrivateData = @{
PSData = @{
Expand All @@ -80,7 +85,7 @@
# ReleaseNotes of this module
# ReleaseNotes = ''

Prerelease = '240311(2)'
Prerelease = '20240614(1)'
RequireLicenseAcceptance = $False

}
Expand Down
106 changes: 60 additions & 46 deletions Gioxx.ToyBox/Groups/GTB.Groups.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function Export-DG {
}

} else {
Write-Host "`nCan't connect or use Microsoft Exchange Online Management module. `nPlease check logs." -f "Red"
Write-Error "`nCan't connect or use Microsoft Exchange Online Management module. `nPlease check logs."
}
}

Expand Down Expand Up @@ -156,7 +156,7 @@ function Export-DDG {
}

} else {
Write-Host "`nCan't connect or use Microsoft Exchange Online Management module. `nPlease check logs." -f "Red"
Write-Error "`nCan't connect or use Microsoft Exchange Online Management module. `nPlease check logs."
}
}

Expand Down Expand Up @@ -236,7 +236,7 @@ function Export-M365Group {
}

} else {
Write-Host "`nCan't connect or use Microsoft Exchange Online Management module. `nPlease check logs." -f "Red"
Write-Error "`nCan't connect or use Microsoft Exchange Online Management module. `nPlease check logs."
}
}

Expand All @@ -249,28 +249,34 @@ function Get-UserGroups {
[switch] $GridView
)

$groupList=@()
$mggConnectedCheck = priv_CheckMGGraphModule

if ( $mggConnectedCheck -eq $true ) {
$groupList=@()

if ( $UserPrincipalName -inotmatch "@" ) {
$emailAddresses = (Get-Recipient $UserPrincipalName).EmailAddresses | Where-Object { $_ -clike 'SMTP:*' }
if ($emailAddresses.Count -gt 1) {
Write-Host "Complete e-mail address not specified, multiple email addresses found:" -f "Cyan"
$emailAddresses | ForEach-Object { Write-Host $_.Replace('SMTP:', ' ') }
Write-Host "Run the command again but specify the full address to perform a more accurate search." -f "Cyan"
$UserPrincipalName = (Get-Recipient $UserPrincipalName).PrimarySmtpAddress | Select-Object -First 1
Write-Host "First user selected: $($UserPrincipalName)" -f "Cyan"
} else {
$UserPrincipalName = (Get-Recipient $UserPrincipalName).PrimarySmtpAddress
Write-Host "Complete e-mail address not specified, user found: $($UserPrincipalName)" -f "Cyan"
try {
$emailAddresses = (Get-Recipient $UserPrincipalName).EmailAddresses | Where-Object { $_ -clike 'SMTP:*' }
if ($emailAddresses.Count -le 0) {
Write-Host "Recipient not available or not found ($($UserPrincipalName))." -f "Red"
break
} elseif ($emailAddresses.Count -gt 1) {
Write-Host "Complete e-mail address not specified, multiple email addresses found:" -f "Cyan"
$emailAddresses | ForEach-Object { Write-Host $_.Replace('SMTP:', ' ') }
Write-Host "Run the command again but specify the full address to perform a more accurate search." -f "Cyan"
$UserPrincipalName = (Get-Recipient $UserPrincipalName).PrimarySmtpAddress | Select-Object -First 1
Write-Host "First user selected: $($UserPrincipalName)" -f "Cyan"
} else {
$UserPrincipalName = (Get-Recipient $UserPrincipalName).PrimarySmtpAddress
Write-Host "Complete e-mail address not specified, user found: $($UserPrincipalName)" -f "Cyan"
}
} catch {
Write-Error $_.Exception.Message
}
}

try {
$RecipientType = (Get-Recipient $UserPrincipalName -ErrorAction SilentlyContinue).RecipientTypeDetails

if ( $RecipientType -ne $null ) {
Switch ($RecipientType) {
"MailContact" {
Expand All @@ -294,48 +300,56 @@ function Get-UserGroups {
$groups = Get-MgUserMemberOf -UserId $userID.Id | Select-Object *
}
}
} else {
Write-Host "Recipient not available or not found." -f "Red"
}

if ( $groups -ne $null ) {
$groups | ForEach {
$groupIDs = $_.id
$otherproperties = $_.AdditionalProperties

if ($GridView) {
$groupList += New-Object -TypeName PSObject -Property $([ordered]@{
"Group Name" = $otherproperties.displayName
"Group Description" = $otherproperties.description
"Group Mail" = $otherproperties.mail
"Group Mail Nickname" = $otherproperties.mailNickname
"Group Mail Enabled" = $otherproperties.mailEnabled
"Group ID" = $groupIDs
})
} else {
$groupList += New-Object -TypeName PSObject -Property $([ordered]@{
"Group Name" = $otherproperties.displayName
"Group Mail" = $otherproperties.mail
})
if ( $groups -ne $null ) {
$groups | ForEach {
$groupIDs = $_.id
$otherproperties = $_.AdditionalProperties

if (($otherproperties.groupTypes).count -eq 0) {
$groupType = (Get-Recipient $otherproperties.mail).RecipientTypeDetails
} else {
$groupType = $otherproperties.groupTypes
}

if ($GridView) {
$groupList += New-Object -TypeName PSObject -Property $([ordered]@{
"Group Name" = $otherproperties.displayName
"Group Description" = $otherproperties.description
"Group Mail" = $otherproperties.mail
"Group Mail Nickname" = $otherproperties.mailNickname
"Group Mail Enabled" = $otherproperties.mailEnabled
"Group Type" = $groupType
"Group ID" = $groupIDs
})
} else {
$groupList += New-Object -TypeName PSObject -Property $([ordered]@{
"Group Name" = $otherproperties.displayName
"Group Mail" = $otherproperties.mail
"Group Type" = $groupType
})
}

}

if ($GridView) { $groupList | Out-GridView -Title "M365 User Groups" } else { $groupList | Sort "Group Name" | Out-Host }
}

if ($GridView) { $groupList | Out-GridView -Title "M365 User Groups" } else { $groupList }
}

} else {
Write-Host "Recipient not available or not found ($($UserPrincipalName))." -f "Red"
}
} catch {
Write-Host "Recipient not available or not found." -f "Red"
# Write-Host "Error details: $_"
Write-Error $_.Exception.Message
}

} else {
Write-Host "`nCan't connect or use Microsoft Graph modules. `nPlease check logs." -f "Red"
}
}

# Export Modules ===================================================================================================================================================
# Export Modules and Aliases =======================================================================================================================================

Export-ModuleMember -Alias *
Export-ModuleMember -Function "Export-DG"
Export-ModuleMember -Function "Export-DDG"
Export-ModuleMember -Function "Export-M365Group"
Expand Down
Loading

0 comments on commit b070798

Please sign in to comment.