Skip to content

Commit

Permalink
Added support for Office365 USers
Browse files Browse the repository at this point in the history
  • Loading branch information
NikCharlebois committed Nov 23, 2018
1 parent 28136fd commit 1f03788
Show file tree
Hide file tree
Showing 7 changed files with 243 additions and 3 deletions.
172 changes: 172 additions & 0 deletions Modules/Office365DSC/DSCResources/MSFT_O365User/MSFT_O365User.psm1
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;
};

29 changes: 29 additions & 0 deletions Modules/Office365DSC/DSCResources/MSFT_O365User/readme.md
Original file line number Diff line number Diff line change
@@ -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.
14 changes: 13 additions & 1 deletion Modules/Office365DSC/Examples/ProofOfConcept.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,25 @@ Configuration ProofOfConcept
{
SPOSite TestNik
{
Url = "https://O365DSC1.sharepoint.com/sites/PoC6"
Url = "https://O365DSC1.sharepoint.com/sites/PoC7"
Owner = "[email protected]"
StorageQuota = 100
ResourceQuota = 777
Title = "ProofOfConcept"
CentralAdminUrl = "https://o365dsc1-admin.sharepoint.com"
GlobalAdminAccount = $credsGlobalAdmin
}

O365User Bob
{
UserPrincipalName = "[email protected]"
FirstName = "Bob"
LastName = "Houle"
DisplayName = "Bob Houle"
UsageLocation = "US"
LicenseAssignment = "O365dsc1:ENTERPRISEPREMIUM"
GlobalAdminAccount = $credsGlobalAdmin
}
}
}

Expand Down
Binary file modified Modules/Office365DSC/Examples/ProofOfConcept/localhost.mof
Binary file not shown.
14 changes: 14 additions & 0 deletions Modules/Office365DSC/Modules/Office365DSCUtil.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand Down
4 changes: 2 additions & 2 deletions Modules/Office365DSC/Office365DSC.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @()
Expand All @@ -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 = '*'
Expand Down

0 comments on commit 1f03788

Please sign in to comment.