Skip to content

Commit

Permalink
Merge pull request #83 from BrianFarnhill/dev
Browse files Browse the repository at this point in the history
Stability fixes and test coverage improvements
  • Loading branch information
BrianFarnhill committed Oct 2, 2015
2 parents e3e0232 + ece7a80 commit 9d29b45
Show file tree
Hide file tree
Showing 36 changed files with 778 additions and 419 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function Get-TargetResource

$wa = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue

if ($null -eq $wa) { return @{} }
if ($null -eq $wa) { return $null }

$returnVal = @{}
$returnVal.Add("WebAppUrl", $params.WebAppUrl)
Expand Down Expand Up @@ -54,7 +54,6 @@ function Set-TargetResource

$result = Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
$params = $args[0]


$wa = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue
if ($null -eq $wa) {
Expand All @@ -72,10 +71,15 @@ function Set-TargetResource
$wa.Properties.Add("portalsuperreaderaccount", $params.SuperReaderAlias)
}

Set-xSharePointCacheReaderPolicy -WebApplication $wa -UserName $params.SuperReaderAlias
Set-xSharePointCacheOwnerPolicy -WebApplication $wa -UserName $params.SuperUserAlias
$readPolicy = $wa.Policies.Add($params.SuperReaderAlias, $params.SuperReaderAlias)
$readPolicyRole = $wa.PolicyRoles.GetSpecialRole([Microsoft.SharePoint.Administration.SPPolicyRoleType]::FullRead)
$readPolicy.PolicyRoleBindings.Add($readPolicyRole)

Update-xSharePointObject -InputObject $wa
$policy = $wa.Policies.Add($params.SuperUserAlias, $params.SuperUserAlias)
$policyRole = $wa.PolicyRoles.GetSpecialRole([Microsoft.SharePoint.Administration.SPPolicyRoleType]::FullControl)
$policy.PolicyRoleBindings.Add($policyRole)

$wa.Update()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ function Get-TargetResource
)

Write-Verbose -Message "Getting the cache host information"

$result = Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
$params = $args[0]
$nullReturnValue = @{
Name = $params.Name
Ensure = "Absent"
InstallAccount = $params.InstallAccount
}

try
{
Use-CacheCluster -ErrorAction SilentlyContinue
Expand All @@ -29,12 +30,10 @@ function Get-TargetResource
if ($null -eq $cacheHost) { return $nullReturnValue }
$computerName = ([System.Net.Dns]::GetHostByName($env:computerName)).HostName
$cacheHostConfig = Get-AFCacheHostConfiguration -ComputerName $computerName -CachePort $cacheHost.PortNo -ErrorAction SilentlyContinue

if ($null -eq $cacheHostConfig) { return $nullReturnValue }

$windowsService = Get-WmiObject "win32_service" -Filter "Name='AppFabricCachingService'"
$firewallRule = Get-NetFirewallRule -DisplayName "SharePoint Distributed Cache" -ErrorAction SilentlyContinue

return @{
Name = $params.Name
CacheSizeInMB = $cacheHostConfig.Size
Expand All @@ -44,7 +43,7 @@ function Get-TargetResource
InstallAccount = $params.InstallAccount
}
}
catch{
catch {
return $nullReturnValue
}
}
Expand All @@ -67,6 +66,13 @@ function Set-TargetResource

$CurrentState = Get-TargetResource @PSBoundParameters

$isLocalAdmin = Test-xSharePointUserIsLocalAdmin -UserName $ServiceAccount

if (!$isLocalAdmin)
{
Add-xSharePointUserToLocalAdmin -UserName $ServiceAccount
}

if ($Ensure -eq "Present") {
Write-Verbose -Message "Adding the distributed cache to the server"
if($createFirewallRules -eq $true) {
Expand Down Expand Up @@ -124,6 +130,12 @@ function Set-TargetResource
}
Write-Verbose -Message "Distributed cache removed."
}

# Remove the FarmAccount from the local Administrators group, if it was added above
if (!$isLocalAdmin)
{
Remove-xSharePointUserToLocalAdmin -UserName $ServiceAccount
}
}

function Test-TargetResource
Expand All @@ -142,7 +154,6 @@ function Test-TargetResource

$CurrentValues = Get-TargetResource @PSBoundParameters
Write-Verbose -Message "Testing for distributed cache configuration"
if ($null -eq $CurrentValues) { return $false }
return Test-xSharePointSpecificParameters -CurrentValues $CurrentValues -DesiredValues $PSBoundParameters -ValuesToCheck @("Ensure", "CreateFirewallRules")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,16 @@ function Get-TargetResource

$result = Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
$params = $args[0]


$feature = Get-SPFeature -Identity $params.Name -ErrorAction SilentlyContinue

if ($null -eq $feature) { return @{
Name = $params.Name
FeatureScope = $params.FeatureScope
Url = $params.Url
InstalAcount = $params.InstallAccount
Ensure = "Absent"
} }

$checkParams = @{}
$checkParams.Add("Identity", $params.Name)
if ($FeatureScope -eq "Farm") {
$checkParams = @{ Identity = $params.Name }
if ($params.FeatureScope -eq "Farm") {
$checkParams.Add($params.FeatureScope, $true)
} else {
$checkParams.Add($params.FeatureScope, $params.Url)
}
$featureAtScope = Get-SPFeature @checkParams -ErrorAction SilentlyContinue
$enabled = ($null -ne $featureAtScope)
if ($enabled) { $currentState = "Present" } else { $currentState = "Absent" }
if ($enabled -eq $true) { $currentState = "Present" } else { $currentState = "Absent" }

return @{
Name = $params.Name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ function Get-TargetResource
Write-Verbose -Message "Getting installed windows features"

if ($majorVersion -eq 15) {
$WindowsFeatures = Invoke-Command -ScriptBlock { Get-WindowsFeature -Name Net-Framework-Features,Web-Server,Web-WebServer,Web-Common-Http,Web-Static-Content,Web-Default-Doc,Web-Dir-Browsing,Web-Http-Errors,Web-App-Dev,Web-Asp-Net,Web-Net-Ext,Web-ISAPI-Ext,Web-ISAPI-Filter,Web-Health,Web-Http-Logging,Web-Log-Libraries,Web-Request-Monitor,Web-Http-Tracing,Web-Security,Web-Basic-Auth,Web-Windows-Auth,Web-Filtering,Web-Digest-Auth,Web-Performance,Web-Stat-Compression,Web-Dyn-Compression,Web-Mgmt-Tools,Web-Mgmt-Console,Web-Mgmt-Compat,Web-Metabase,Application-Server,AS-Web-Support,AS-TCP-Port-Sharing,AS-WAS-Support, AS-HTTP-Activation,AS-TCP-Activation,AS-Named-Pipes,AS-Net-Framework,WAS,WAS-Process-Model,WAS-NET-Environment,WAS-Config-APIs,Web-Lgcy-Scripting,Windows-Identity-Foundation,Server-Media-Foundation,Xps-Viewer } -NoNewScope
$WindowsFeatures = Get-WindowsFeature -Name Net-Framework-Features,Web-Server,Web-WebServer,Web-Common-Http,Web-Static-Content,Web-Default-Doc,Web-Dir-Browsing,Web-Http-Errors,Web-App-Dev,Web-Asp-Net,Web-Net-Ext,Web-ISAPI-Ext,Web-ISAPI-Filter,Web-Health,Web-Http-Logging,Web-Log-Libraries,Web-Request-Monitor,Web-Http-Tracing,Web-Security,Web-Basic-Auth,Web-Windows-Auth,Web-Filtering,Web-Digest-Auth,Web-Performance,Web-Stat-Compression,Web-Dyn-Compression,Web-Mgmt-Tools,Web-Mgmt-Console,Web-Mgmt-Compat,Web-Metabase,Application-Server,AS-Web-Support,AS-TCP-Port-Sharing,AS-WAS-Support, AS-HTTP-Activation,AS-TCP-Activation,AS-Named-Pipes,AS-Net-Framework,WAS,WAS-Process-Model,WAS-NET-Environment,WAS-Config-APIs,Web-Lgcy-Scripting,Windows-Identity-Foundation,Server-Media-Foundation,Xps-Viewer
}
if ($majorVersion -eq 16) {
$WindowsFeatures = Invoke-Command -ScriptBlock { Get-WindowsFeature -Name Application-Server,AS-NET-Framework,AS-Web-Support,Web-Server,Web-WebServer,Web-Common-Http,Web-Default-Doc,Web-Dir-Browsing,Web-Http-Errors,Web-Static-Content,Web-Http-Redirect,Web-Health,Web-Http-Logging,Web-Log-Libraries,Web-Request-Monitor,Web-Performance,Web-Stat-Compression,Web-Dyn-Compression,Web-Security,Web-Filtering,Web-Basic-Auth,Web-Client-Auth,Web-Digest-Auth,Web-Cert-Auth,Web-IP-Security,Web-Url-Auth,Web-Windows-Auth,Web-App-Dev,Web-Net-Ext,Web-Net-Ext45,Web-Asp-Net45,Web-ISAPI-Ext,Web-ISAPI-Filter,Web-Mgmt-Tools,Web-Mgmt-Console,Web-Mgmt-Compat,Web-Metabase,Web-Lgcy-Mgmt-Console,Web-Lgcy-Scripting,Web-WMI,Web-Scripting-Tools,NET-Framework-Features,NET-Framework-Core,NET-HTTP-Activation,NET-Non-HTTP-Activ,NET-Framework-45-ASPNET,NET-WCF-HTTP-Activation45,Windows-Identity-Foundation,PowerShell-V2,WAS,WAS-Process-Model,WAS-NET-Environment,WAS-Config-APIs } -NoNewScope
$WindowsFeatures = Get-WindowsFeature -Name Application-Server,AS-NET-Framework,AS-Web-Support,Web-Server,Web-WebServer,Web-Common-Http,Web-Default-Doc,Web-Dir-Browsing,Web-Http-Errors,Web-Static-Content,Web-Http-Redirect,Web-Health,Web-Http-Logging,Web-Log-Libraries,Web-Request-Monitor,Web-Performance,Web-Stat-Compression,Web-Dyn-Compression,Web-Security,Web-Filtering,Web-Basic-Auth,Web-Client-Auth,Web-Digest-Auth,Web-Cert-Auth,Web-IP-Security,Web-Url-Auth,Web-Windows-Auth,Web-App-Dev,Web-Net-Ext,Web-Net-Ext45,Web-Asp-Net45,Web-ISAPI-Ext,Web-ISAPI-Filter,Web-Mgmt-Tools,Web-Mgmt-Console,Web-Mgmt-Compat,Web-Metabase,Web-Lgcy-Mgmt-Console,Web-Lgcy-Scripting,Web-WMI,Web-Scripting-Tools,NET-Framework-Features,NET-Framework-Core,NET-HTTP-Activation,NET-Non-HTTP-Activ,NET-Framework-45-ASPNET,NET-WCF-HTTP-Activation45,Windows-Identity-Foundation,PowerShell-V2,WAS,WAS-Process-Model,WAS-NET-Environment,WAS-Config-APIs
}

foreach ($feature in $WindowsFeatures) {
Expand All @@ -49,7 +49,7 @@ function Get-TargetResource
$installedItems = Get-CimInstance -ClassName Win32_Product

#Common prereqs
$returnValue.Add("Microsoft Identity Extensions", (Check-xSharePointInstalledProductRegistryKey -RegKeysCollection (Get-ChildItem HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\ -Recurse) -ProductName "Microsoft Identity Extensions").Count -gt 0)
$returnValue.Add("Microsoft Identity Extensions", (@(Get-ChildItem HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\ -Recurse | ? {$_.GetValue("DisplayName") -eq "Microsoft Identity Extensions" }).Count -gt 0))
$returnValue.Add("Microsoft CCR and DSS Runtime 2008 R3", (($installedItems | ? {$_.Name -eq "Microsoft CCR and DSS Runtime 2008 R3"}) -ne $null))
$returnValue.Add("Microsoft Sync Framework Runtime v1.0 SP1 (x64)", (($installedItems | ? {$_.Name -eq "Microsoft Sync Framework Runtime v1.0 SP1 (x64)"}) -ne $null))
$returnValue.Add("AppFabric 1.1 for Windows Server", (($installedItems | ? {$_.Name -eq "AppFabric 1.1 for Windows Server"}) -ne $null))
Expand Down Expand Up @@ -81,18 +81,6 @@ function Get-TargetResource
return $results
}

function Check-xSharePointInstalledProductRegistryKey() {
[CmdletBinding()]
param
(
[parameter(Mandatory = $false)] [object] $RegKeysCollection,
[parameter(Mandatory = $true)] [string] $ProductName
)
if ($RegKeysCollection -eq $null) { return $null }
return @($RegKeysCollection | ? {$_.GetValue("DisplayName") -eq $ProductName })
}


function Set-TargetResource
{
[CmdletBinding()]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function Set-TargetResource
Start-Service -Name sptimerv4

Write-Verbose -Message "Pausing for 5 minutes to allow the timer service to fully provision the server"
Invoke-Command -ScriptBlock { Start-Sleep -Seconds 300 } -NoNewScope
Start-Sleep -Seconds 300
Write-Verbose -Message "Join farm complete. Restarting computer to allow configuration to continue"

$global:DSCMachineStatus = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,15 @@ function Get-TargetResource
$result = Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
$params = $args[0]


try {
$ma = Get-SPManagedAccount -Identity $params.Account.UserName -ErrorAction SilentlyContinue
if ($null -eq $ma) { return $null }
return @{
AccountName = $ma.Username
EmailNotification = $ma.DaysBeforeChangeToEmail
PreExpireDays = $ma.DaysBeforeExpiryToChange
Schedule = $ma.ChangeSchedule
Account = $params.Account
InstallAccount = $params.InstallAccount
}
} catch {
return $null
$ma = Get-SPManagedAccount -Identity $params.Account.UserName -ErrorAction SilentlyContinue
if ($null -eq $ma) { return $null }
return @{
AccountName = $ma.Username
EmailNotification = $ma.DaysBeforeChangeToEmail
PreExpireDays = $ma.DaysBeforeExpiryToChange
Schedule = $ma.ChangeSchedule
Account = $params.Account
InstallAccount = $params.InstallAccount
}
}
return $result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,25 @@ function Get-TargetResource
$result = Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
$params = $args[0]

$serviceApps = Get-SPServiceApplication -Name $params.Name -ErrorAction SilentlyContinue
if ($null -eq $serviceApps) {
return $null
}
$serviceApp = $serviceApps | Where-Object { $_.TypeName -eq "Managed Metadata Service" }

try
If ($null -eq $serviceApp)
{
$serviceApps = Get-SPServiceApplication -Name $params.Name -ErrorAction SilentlyContinue
if ($null -eq $serviceApps) {
return $null
}
$serviceApp = $serviceApps | Where-Object { $_.TypeName -eq "Managed Metadata Service" }

If ($null -eq $serviceApp)
{
return $null
}
else
{
return @{
Name = $serviceApp.DisplayName
ApplicationPool = $serviceApp.ApplicationPool.Name
DatabaseName = $serviceApp.Database.Name
DatabaseServer = $serviceApp.Database.Server.Name
InstallAccount = $params.InstallAccount
}
}
}
catch
return $null
}
else
{
return $null
return @{
Name = $serviceApp.DisplayName
ApplicationPool = $serviceApp.ApplicationPool.Name
DatabaseName = $serviceApp.Database.Name
DatabaseServer = $serviceApp.Database.Server.Name
InstallAccount = $params.InstallAccount
}
}
}
return $result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,12 @@ function Set-TargetResource

Write-Verbose -Message "Creating the managed path $RelativeUrl in $WebAppUrl"

Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
$params = $args[0]


$path = Get-TargetResource @params -ErrorAction SilentlyContinue
$path = Get-TargetResource @PSBoundParameters

if ($params.ContainsKey("InstallAccount")) { $params.Remove("InstallAccount") | Out-Null }
if ($null -eq $path) {
Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
$params = $args[0]

if ($null -eq $path) {

$newParams = @{}
if ($params.HostHeader) {
$newParams.Add("HostHeader", $params.HostHeader)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,11 @@ function Set-TargetResource
if ($null -eq $CurrentState) {
Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
$params = $args[0]


$newParams = @{}
$newParams.Add("Name", $params.Name)
if ($params.ContainsKey("DatabaseName")) { $newParams.Add("DatabaseName", $params.DatabaseName) }
if ($params.ContainsKey("DatabasePassword")) { $newParams.Add("DatabasePassword", $params.DatabasePassword) }
if ($params.ContainsKey("DatabasePassword")) { $newParams.Add("DatabasePassword", (ConvertTo-SecureString -String $params.DatabasePassword -AsPlainText -force)) }
if ($params.ContainsKey("DatabaseServer")) { $newParams.Add("DatabaseServer", $params.DatabaseServer) }
if ($params.ContainsKey("DatabaseUsername")) { $newParams.Add("DatabaseUsername", $params.DatabaseUsername) }
if ($params.ContainsKey("FailoverDatabaseServer")) { $newParams.Add("FailoverDatabaseServer", $params.FailoverDatabaseServer) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,9 @@ function Set-TargetResource
$maxCount = 10

while (($count -lt $maxCount) -and ($syncService.Status -ne $desiredState)) {
if ($syncService.Status -ne $desiredState) { Start-Sleep -Seconds 60 }
# Get the current status of the Sync service
$syncService = Get-SPServiceInstance -Server $env:COMPUTERNAME | Where-Object { $_.TypeName -eq "User Profile Synchronization Service" }

if ($syncService.Status -ne $desiredState) { Start-Sleep -Seconds 60 }
$count++
}
}
Expand Down

This file was deleted.

Loading

0 comments on commit 9d29b45

Please sign in to comment.