diff --git a/Modules/Office365DSC/DSCResources/MSFT_O365User/MSFT_O365User.psm1 b/Modules/Office365DSC/DSCResources/MSFT_O365User/MSFT_O365User.psm1 new file mode 100644 index 0000000000..eba11f193f --- /dev/null +++ b/Modules/Office365DSC/DSCResources/MSFT_O365User/MSFT_O365User.psm1 @@ -0,0 +1,172 @@ +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $UserPrincipalName, + + [Parameter(Mandatory = $true)] + [System.String] + $DisplayName, + + [Parameter(Mandatory = $true)] + [System.String] + $FirstName, + + [Parameter(Mandatory = $true)] + [System.String] + $LastName, + + [Parameter(Mandatory = $true)] + [System.String] + $UsageLocation, + + [Parameter(Mandatory = $true)] + [System.String] + $LicenseAssignment, + + [Parameter()] + [System.Management.Automation.PSCredential] + $Password, + + [Parameter(Mandatory = $true)] + [System.Management.Automation.PSCredential] + $GlobalAdminAccount + ) + + Test-O365ServiceConnection -GlobalAdminAccount $GlobalAdminAccount + + $nullReturn = @{ + UserPrincipalName = $null + DisplayName = $null + FirstName = $null + LastName = $null + UsageLocation = $null + LicenseAssignment = $null + Password = $null + } + + try { + Write-Verbose -Message "Getting Office 365 User $UserPrincipalName" + $user = Get-MSOLUser -UserPrincipalName $UserPrincipalName -ErrorAction SilentlyContinue + if(!$user) + { + Write-Verbose "The specified User doesn't already exist." + return $nullReturn + } + $accountName = $user.LicenseAssignmentDetails.AccountSku.AccountName + $sku = $user.LicenseAssignmentDetails.AccountSku.SkuPartNumber + return @{ + UserPrincipalName = $user.UserPrincipalName + DisplayName = $user.DisplayName + FirstName = $user.FirstName + LastName = $user.LastName + UsageLocation = $user.UsageLocation + LicenseAssignment = $accountNAme + ":" + $sku + Passsword = $Password + } + } + catch { + Write-Verbose "The specified User doesn't already exist." + return $nullReturn + } +} + +function Set-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $UserPrincipalName, + + [Parameter(Mandatory = $true)] + [System.String] + $DisplayName, + + [Parameter(Mandatory = $true)] + [System.String] + $FirstName, + + [Parameter(Mandatory = $true)] + [System.String] + $LastName, + + [Parameter(Mandatory = $true)] + [System.String] + $UsageLocation, + + [Parameter(Mandatory = $true)] + [System.String] + $LicenseAssignment, + + [Parameter()] + [System.Management.Automation.PSCredential] + $Password, + + [Parameter(Mandatory = $true)] + [System.Management.Automation.PSCredential] + $GlobalAdminAccount + ) + + Test-O365ServiceConnection -GlobalAdminAccount $GlobalAdminAccount + + Write-Verbose -Message "Setting Office 365 User $UserPrincipalName" + $CurrentParameters = $PSBoundParameters + $CurrentParameters.Remove("GlobalAdminAccount") + + New-MsolUser @CurrentParameters +} + +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $UserPrincipalName, + + [Parameter(Mandatory = $true)] + [System.String] + $DisplayName, + + [Parameter(Mandatory = $true)] + [System.String] + $FirstName, + + [Parameter(Mandatory = $true)] + [System.String] + $LastName, + + [Parameter(Mandatory = $true)] + [System.String] + $UsageLocation, + + [Parameter(Mandatory = $true)] + [System.String] + $LicenseAssignment, + + [Parameter()] + [System.Management.Automation.PSCredential] + $Password, + + [Parameter(Mandatory = $true)] + [System.Management.Automation.PSCredential] + $GlobalAdminAccount + ) + + Write-Verbose -Message "Testing Office 365 User $UserPrincipalName" + $CurrentValues = Get-TargetResource @PSBoundParameters + return Test-Office365DSCParameterState -CurrentValues $CurrentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @("UserPrincipalName") +} + +Export-ModuleMember -Function *-TargetResource diff --git a/Modules/Office365DSC/DSCResources/MSFT_O365User/MSFT_O365User.schema.mof b/Modules/Office365DSC/DSCResources/MSFT_O365User/MSFT_O365User.schema.mof new file mode 100644 index 0000000000..886cdb2617 --- /dev/null +++ b/Modules/Office365DSC/DSCResources/MSFT_O365User/MSFT_O365User.schema.mof @@ -0,0 +1,13 @@ +[ClassVersion("1.0.0.0"), FriendlyName("O365User")] +class MSFT_O365User : OMI_BaseResource +{ + [Key, Description("The login name of the user")] string UserPrincipalName; + [Required, Description("The display name for the user")] string DisplayName; + [Required, Description("The first name of the user")] string FirstName; + [Required, Description("The last name of the user")] string LastName; + [Required, Description("The country code the user will be assigned to")] string UsageLocation; + [Required, Description("The account SKU Id for the license to be assigned to the user")] string LicenseAssignment; + [Write, Description("The password for the account"), EmbeddedInstance("MSFT_Credential")] string Password; + [Required, Description("Credentials of the SharePoint Global Admin"), EmbeddedInstance("MSFT_Credential")] string GlobalAdminAccount; +}; + diff --git a/Modules/Office365DSC/DSCResources/MSFT_O365User/readme.md b/Modules/Office365DSC/DSCResources/MSFT_O365User/readme.md new file mode 100644 index 0000000000..7b20f6feab --- /dev/null +++ b/Modules/Office365DSC/DSCResources/MSFT_O365User/readme.md @@ -0,0 +1,29 @@ +# Description + +**Type:** Distributed +**Requires CredSSP:** No + +This resource will provision a site collection to the current farm, based on +the settings that are passed through. These settings map to the New-SPSite +cmdlet and accept the same values and types. + +The current version of SharePointDsc is only able to check for the existence +of a site collection, the additional parameters are not checked for yet, but +will be in a later release + +NOTE: +When creating Host Header Site Collections, do not use the HostHeader +parameter in SPWebApplication. This will set the specified host header on your +IIS site and prevent the site from listening for the URL of the Host Header +Site Collection. +If you want to change the IIS website binding settings, please use the xWebsite +resource in the xWebAdministration module. + +NOTE2: +The CreateDefaultGroups parameter is only used for creating default site +groups. It will not remove or change the default groups if they already exist. + +NOTE3: +AdministrationSiteType is used in combination with the resource +SPWebAppClientCallableSettings. The required proxy library must be configured +before the administration site type has any effect. diff --git a/Modules/Office365DSC/Examples/ProofOfConcept.ps1 b/Modules/Office365DSC/Examples/ProofOfConcept.ps1 index 8c9638c2f1..946e82d5b9 100644 --- a/Modules/Office365DSC/Examples/ProofOfConcept.ps1 +++ b/Modules/Office365DSC/Examples/ProofOfConcept.ps1 @@ -6,13 +6,25 @@ Configuration ProofOfConcept { SPOSite TestNik { - Url = "https://O365DSC1.sharepoint.com/sites/PoC6" + Url = "https://O365DSC1.sharepoint.com/sites/PoC7" Owner = "TenantAdmin@O365DSC1.onmicrosoft.com" StorageQuota = 100 + ResourceQuota = 777 Title = "ProofOfConcept" CentralAdminUrl = "https://o365dsc1-admin.sharepoint.com" GlobalAdminAccount = $credsGlobalAdmin } + + O365User Bob + { + UserPrincipalName = "Bob.Houle@O365DSC1.onmicrosoft.com" + FirstName = "Bob" + LastName = "Houle" + DisplayName = "Bob Houle" + UsageLocation = "US" + LicenseAssignment = "O365dsc1:ENTERPRISEPREMIUM" + GlobalAdminAccount = $credsGlobalAdmin + } } } diff --git a/Modules/Office365DSC/Examples/ProofOfConcept/localhost.mof b/Modules/Office365DSC/Examples/ProofOfConcept/localhost.mof index 1cd094044e..3ce144ec6d 100644 Binary files a/Modules/Office365DSC/Examples/ProofOfConcept/localhost.mof and b/Modules/Office365DSC/Examples/ProofOfConcept/localhost.mof differ diff --git a/Modules/Office365DSC/Modules/Office365DSCUtil.psm1 b/Modules/Office365DSC/Modules/Office365DSCUtil.psm1 index 79feeef0de..2d499e58e1 100644 --- a/Modules/Office365DSC/Modules/Office365DSCUtil.psm1 +++ b/Modules/Office365DSC/Modules/Office365DSCUtil.psm1 @@ -17,6 +17,20 @@ function Test-SPOServiceConnection Connect-SPOService -Url $SPOCentralAdminUrl -Credential $GlobalAdminAccount } +function Test-O365ServiceConnection +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [System.Management.Automation.PSCredential] + $GlobalAdminAccount + ) + Write-Verbose "Verifying the LCM connection state to Microsoft Online Services" + Connect-MSOLService -Credential $GlobalAdminAccount +} + function Test-Office365DSCParameterState { [CmdletBinding()] diff --git a/Modules/Office365DSC/Office365DSC.psd1 b/Modules/Office365DSC/Office365DSC.psd1 index 7b56418de1..96f8baa0f3 100644 --- a/Modules/Office365DSC/Office365DSC.psd1 +++ b/Modules/Office365DSC/Office365DSC.psd1 @@ -48,7 +48,7 @@ PowerShellVersion = '5.1' # ProcessorArchitecture = '' # Modules that must be imported into the global environment prior to importing this module -RequiredModules = @("Microsoft.Online.SharePoint.PowerShell") +RequiredModules = @("Microsoft.Online.SharePoint.PowerShell", "AzureAD") # Assemblies that must be loaded prior to importing this module # RequiredAssemblies = @() @@ -69,7 +69,7 @@ NestedModules = @("modules\Office365DSCUtil.psm1") #FunctionsToExport = '*' # Cmdlets to export from this module -CmdletsToExport = @("Test-SPOServiceConnection", "Test-Office365DSCParameterState") +CmdletsToExport = @("Test-SPOServiceConnection", "Test-Office365DSCParameterState", "Test-O365ServiceConnection") # Variables to export from this module #VariablesToExport = '*'