-
Notifications
You must be signed in to change notification settings - Fork 536
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Microsoft/Dev
Merge from base repo
- Loading branch information
Showing
16 changed files
with
1,266 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 160 additions & 0 deletions
160
Modules/Office365DSC/DSCResources/MSFT_O365SharedMailbox/MSFT_O365SharedMailbox.psm1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
function Get-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Collections.Hashtable])] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[System.String] | ||
$DisplayName, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$PrimarySMTPAddress, | ||
|
||
[Parameter()] | ||
[ValidateSet("Present","Absent")] | ||
[System.String] | ||
$Ensure = "Present", | ||
|
||
[Parameter(Mandatory = $true)] | ||
[System.Management.Automation.PSCredential] | ||
$GlobalAdminAccount | ||
) | ||
Write-Verbose "Get-TargetResource will attempt to retrieve information for Shared Mailbox $($DisplayName)" | ||
$nullReturn = @{ | ||
DisplayName = $DisplayName | ||
PrimarySMTPAddress = $null | ||
GlobalAdminAccount = $null | ||
Ensure = "Absent" | ||
} | ||
|
||
$mailboxes = Invoke-ExoCommand -GlobalAdminAccount $GlobalAdminAccount ` | ||
-ScriptBlock { | ||
Get-Mailbox | ||
} | ||
$mailbox = $mailboxes | Where-Object {$_.RecipientTypeDetails -eq "SharedMailbox" -and $_.Identity -eq $DisplayName} | ||
|
||
if(!$mailbox) | ||
{ | ||
Write-Verbose "The specified Shared Mailbox doesn't already exist." | ||
return $nullReturn | ||
} | ||
$result = @{ | ||
DisplayName = $DisplayName | ||
PrimarySMTPAddress = $mailbox.PrimarySMTPAddress | ||
Ensure = "Present" | ||
GlobalAdminAccount = $GlobalAdminAccount | ||
} | ||
Write-Verbose "Found an existing instance of Shared Mailbox $($DisplayName)" | ||
return $result | ||
} | ||
|
||
function Set-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[System.String] | ||
$DisplayName, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$PrimarySMTPAddress, | ||
|
||
[Parameter()] | ||
[ValidateSet("Present","Absent")] | ||
[System.String] | ||
$Ensure = "Present", | ||
|
||
[Parameter(Mandatory = $true)] | ||
[System.Management.Automation.PSCredential] | ||
$GlobalAdminAccount | ||
) | ||
Write-Verbose "Entering Set-TargetResource" | ||
Write-Verbose "Retrieving information about Shared Mailbox $($DisplayName) to see if it already exists" | ||
$currentMailbox = Get-TargetResource @PSBoundParameters | ||
|
||
# CASE: Mailbox doesn't exist but should; | ||
if ($Ensure -eq "Present" -and $currentMailbox.Ensure -eq "Absent") | ||
{ | ||
Write-Verbose "Shared Mailbox $($DisplayName) does not exist but it should. Creating it." | ||
Invoke-ExoCommand -GlobalAdminAccount $GlobalAdminAccount ` | ||
-Arguments $PSBoundParameters ` | ||
-ScriptBlock { | ||
New-MailBox -Name $args[0].DisplayName -PrimarySMTPAddress $args[0].PrimarySMTPAddress -Shared:$true | ||
} | ||
} | ||
# CASE: Mailbox exists but it shouldn't; | ||
elseif ($Ensure -eq "Absent" -and $currentMailbox.Ensure -eq "Present") | ||
{ | ||
Write-Verbose "Shared Mailbox $($DisplayName) exists but it shouldn't. Deleting it." | ||
Invoke-ExoCommand -GlobalAdminAccount $GlobalAdminAccount ` | ||
-Arguments $PSBoundParameters ` | ||
-ScriptBlock { | ||
Remove-Mailbox -Identity $args[0]..DisplayName -Confirm:$false | ||
} | ||
} | ||
} | ||
|
||
function Test-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Boolean])] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[System.String] | ||
$DisplayName, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$PrimarySMTPAddress, | ||
|
||
[Parameter()] | ||
[ValidateSet("Present","Absent")] | ||
[System.String] | ||
$Ensure = "Present", | ||
|
||
[Parameter(Mandatory = $true)] | ||
[System.Management.Automation.PSCredential] | ||
$GlobalAdminAccount | ||
) | ||
|
||
Write-Verbose -Message "Testing Office 365 Shared Mailbox $DisplayName" | ||
$CurrentValues = Get-TargetResource @PSBoundParameters | ||
return Test-Office365DSCParameterState -CurrentValues $CurrentValues ` | ||
-DesiredValues $PSBoundParameters ` | ||
-ValuesToCheck @("Ensure", ` | ||
"DisplayName", ` | ||
"PrimarySMTPAddress") | ||
} | ||
|
||
function Export-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.String])] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[System.String] | ||
$DisplayName, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[System.String] | ||
$PrimarySMTPAddress, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[System.Management.Automation.PSCredential] | ||
$GlobalAdminAccount | ||
) | ||
$result = Get-TargetResource @PSBoundParameters | ||
$content = "O365SharedMailbox " + (New-GUID).ToString() + "`r`n" | ||
$content += "{`r`n" | ||
$content += Get-DSCBlock -Params $result -ModulePath $PSScriptRoot | ||
$content += "}`r`n" | ||
return $content | ||
} | ||
|
||
Export-ModuleMember -Function *-TargetResource |
9 changes: 9 additions & 0 deletions
9
Modules/Office365DSC/DSCResources/MSFT_O365SharedMailbox/MSFT_O365SharedMailbox.schema.mof
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[ClassVersion("1.0.0.0"), FriendlyName("O365SharedMailbox")] | ||
class MSFT_O365SharedMailbox : OMI_BaseResource | ||
{ | ||
[Key, Description("The display name of the Shared Mailbox")] string DisplayName; | ||
[Write, Description("The primary email address of the Shared Mailbox")] string PrimarySMTPAddress; | ||
[Write, Description("Present ensures the group exists, absent ensures it is removed"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] string Ensure; | ||
[Required, Description("Credentials of the SharePoint Global Admin"), EmbeddedInstance("MSFT_Credential")] string GlobalAdminAccount; | ||
}; | ||
|
3 changes: 3 additions & 0 deletions
3
Modules/Office365DSC/DSCResources/MSFT_O365SharedMailbox/readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Description | ||
|
||
This resource allows users to create Office 365 Shared Mailboxes. |
Oops, something went wrong.