I’ve been doing some SharePoint OnPremise installations via PowerShell Desired State Configuration recently. In my experience, there’s going to be a few places your DSC configuration might get stuck – especially during the initial setup.
For a while I just connected to the nodes to get the current configuration status and see what the state of the resources was. This happened several times in several farms and I found myself wanting to make it faster and easier.
This little script will just pull the current status of the resources from the nodes to allow looking at them in a central place and to avoid having to constantly switch between RDP sessions. (By the way – if you’re not using the Remote Desktop Connection Manager for this kind of scenario, your doing it wrong…). It uses the DSC configuration file as source for the node names so it doesn’t rely on the SharePoint Farm being up and running.
Get-SpDscResourceState
function Get-SpDscResourceState { param ( [Parameter(Mandatory=$true)][String]$ConfigDir, [Parameter(Mandatory=$true)][String]$ConfigFile, [Parameter(Mandatory=$true)][String]$FarmName ) # Import the node information from the DSC Config file $ConfigData = Import-LocalizedData -BaseDirectory $ConfigDir -FileName $ConfigFile $Nodes = $ConfigData.AllNodes | Where-Object Farm -eq $FarmName $NodeResources = @() # Loop through all nodes in the farm foreach ($Node in $Nodes) { try { # Get current configuration status $LocalDscConfigurationStatus = Get-DscConfigurationStatus -CimSession $Node.NodeName -ErrorAction Stop $DscBlocked = $false } # Catch blocked status catch [Microsoft.Management.Infrastructure.CimException] { $DscBlocked = $true Write-Host "Local configuration manager on"$Node.NodeName"is currently blocked by a configuration." -ForegroundColor Red } if (-not $DscBlocked) { # Get resources by state $LocalResourcesInDesiredState = $LocalDscConfigurationStatus.ResourcesInDesiredState $LocalResourcesNotInDesiredState = $LocalDscConfigurationStatus.ResourcesNotInDesiredState # Add resources to results $NodeResources += @{ $Node.NodeName = @{ "InDesiredState" = $LocalResourcesInDesiredState; "NotInDesiredState" = $LocalResourcesNotInDesiredState; "AllResources" = $LocalResourcesInDesiredState + $LocalResourcesNotInDesiredState } } Write-Host "Resource status on"$Node.NodeName"successfully evaluated." -ForegroundColor Green } } return $NodeResources } $NodeResources = Get-SpDscResourceState -ConfigDir 'C:\DscTemp' -ConfigFile 'SP2016DEVConfig.psd1' -FarmName 'SP2016DEV'
Examples
Get all resource that are not in the desired state from node WFE01
$NodeResources = Get-SpDscResourceState -ConfigDir 'C:\DscTemp' -ConfigFile 'SP2016DEVConfig.psd1' -FarmName 'SP2016DEV' $NodeResources.WFE01.NotInDesiredState
Ensure node WFE01 to be in the desired state
$NodeResources = Get-SpDscResourceState -ConfigDir 'C:\DscTemp' -ConfigFile 'SP2016DEVConfig.psd1' -FarmName 'SP2016DEV' if ($NodeResources.WFE01.NotInDesiredState.Count -eq 0) { # Do things }
Get the state of the SharePointVSSWriter Service on node WFE01
$NodeResources = Get-SpDscResourceState -ConfigDir 'C:\DscTemp' -ConfigFile 'SP2016DEVConfig.psd1' -FarmName 'SP2016DEV' $NodeResources.WFE01.AllResources | Where-Object InstanceName -eq 'SharePointVSSWriter'