SharePointDsc icon indicating copy to clipboard operation
SharePointDsc copied to clipboard

SPUserProfileServiceApp: Error with Test or Get after successfull Set with no MySiteHostLocation

Open wmaniek123 opened this issue 4 years ago • 8 comments

Details of the scenario you tried and the problem that is occurring

When creating user profile service app without Mysitehostlocation and with enabled CredSSP it is working but after trying to validate the config the TEST and GET functions are not working anymore

Verbose logs showing the problem

No verbose logging just this:

image

Suggested solution to the issue:

Fix issue with nonmandatory mysitehostlocation?

The DSC configuration that is used to reproduce the issue (as detailed as possible)

function new-pscredential{
  [CmdletBinding()]
  param (
    [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
    [string]$user,
    [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
    [string]$password
  )

  $secpasswd   = ConvertTo-SecureString $password -AsPlainText -Force
  $credentials = New-Object System.Management.Automation.PSCredential ($user, $secpasswd)
  return $credentials
}

$response = @{
  indesiredstate = $false
  rebootrequired = $false
  errormessage   = ''
}

$invokeParams = @{
Name       = 'SPUserProfileServiceApp'
ModuleName = 'SharePointDsc'
Method     = 'test'
Property   = @{
'name' = 'SP Hosting User Profile Service';
'proxyName' = 'XXXXX Profile Service Proxy';
'applicationPool' = 'SharePoint Web Services Default';
'profileDBName' = 'XXXXXUserProfile_Profile';
'profileDBServer' = 'XXXX';
'socialDBName' = 'XXXXXXUserProfile_Social';
'socialDBServer' = 'XXXX';
'syncDBName' = 'SP_Hosting_UserProfile_Sync';
'syncDBServer' = 'XXXX';
'enableNetBIOS' = $false;
'psDscRunAsCredential' = ([PSCustomObject]@{
'user' = XXXXX';
'password' = 'XXXXX'
} | new-pscredential)
}
}

try{
  $result = Invoke-DscResource @invokeParams
}catch{
  $response.errormessage = $_.Exception.Message
  return ($response | ConvertTo-Json -Compress)
}

switch($invokeParams.Method){
  'Test'{
    $response.indesiredstate = $result.InDesiredState
    return ($response | ConvertTo-Json -Compress)
  }
  'Set'{
    $response.indesiredstate = $true
    $response.rebootrequired = $result.RebootRequired
    return ($response | ConvertTo-Json -Compress)
  }
}

The operating system the target node is running

OsName               : Microsoft Windows Server 2019 Standard
OsOperatingSystemSKU : StandardServerEdition
OsArchitecture       : 64-bit
WindowsVersion       : 1809
WindowsBuildLabEx    : 17763.1.amd64fre.rs5_release.180914-1434
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

Version and build of PowerShell the target node is running

Name                           Value
----                           -----
PSVersion                      5.1.17763.1490
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17763.1490
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Version of the DSC module that was used

Get-Module -Name 'SharePointDsc' -ListAvailable | ft Name,Version,Path

Name          Version Path
----          ------- ----
SharePointDSC 4.6.0   C:\Program Files\WindowsPowerShell\Modules\SharePointDSC\SharePointDSC.psd1

wmaniek123 avatar Apr 06 '21 13:04 wmaniek123

Checking if I can reproduce this issue

ykuijs avatar Apr 08 '21 14:04 ykuijs

@wmaniek123 I am unable to reproduce the issue on my environment. Few questions:

  • If you add the -Verbose parameter to the Invoke-DscResource line (Invoke-DscResource @invokeParams -Verbose), the cmdlet should output a lot of Verbose output. Could you please share this?
  • What build/Cumulative Update of SharePoint are you using?

ykuijs avatar Apr 09 '21 21:04 ykuijs

@wmaniek123 Any chance that you share the requested info?

ykuijs avatar Apr 23 '21 08:04 ykuijs

@wmaniek123 I am trying to reproduce this issue, but am unable to. Few questions:

  • What do you mean exactly with "with enabled CredSSP it is working"?
  • Can you provide the requested verbose output?

ykuijs avatar Jun 22 '21 10:06 ykuijs

Hello, I think I'm facing the same issue.

Initial SP configuration : no User Profile SA. Start-DscConfiguration with the following code (no MySiteHostLocation parameter):

SPUserProfileServiceApp UserProfileServiceApp
        {
            Name = $ConfigurationData.NonNodeData.SPFarm.UserProfileServiceApp.Name
            ProxyName = $ConfigurationData.NonNodeData.SPFarm.UserProfileServiceApp.Name
            ApplicationPool = $ConfigurationData.NonNodeData.SPFarm.ServiceApplicationPool.ServicesAppPool.Name
            ProfileDBName = $ConfigurationData.NonNodeData.SPFarm.UserProfileServiceApp.DBName.ProfileDBName
            SocialDBName = $ConfigurationData.NonNodeData.SPFarm.UserProfileServiceApp.DBName.SocialDBName
            SyncDBName = $ConfigurationData.NonNodeData.SPFarm.UserProfileServiceApp.DBName.SyncDBName
            Ensure = "Present"
            DependsOn = "[SPFarm]Farm"
            PsDscRunAsCredential = $setupAccount
        }
            UserProfileServiceApp = @{
                Name = "User Profile Service Application"
                DBName = @{
                    ProfileDBName = "UserProfile_Profile_DB"
                    SocialDBName = "UserProfile_Social_DB"
                    SyncDBName = "UserProfile_Sync_DB"
                }
            }

Creation of User Profile SA is OK, without error. However, if I run a Test-DscConfiguration, I got this:

PS C:\Windows\system32> Test-DscConfiguration -Detailed
PowerShell DSC resource MSFT_SPUserProfileServiceApp  failed to execute Test-TargetResource functionality with error
message: You cannot call a method on a null-valued expression.
    + CategoryInfo          : InvalidOperation: (root/Microsoft/...gurationManager:String) [], CimException
    + FullyQualifiedErrorId : ProviderOperationExecutionFailure
    + PSComputerName        : localhost

If I re-run the Start-DscConfiguration again, I'm getting systematically the following error message:

VERBOSE: [CONTOSO-SPAPP01]: LCM:  [ End    Test     ]  [[SPUserProfileServiceApp]UserProfileServiceApp]  in 0.9370
seconds.
PowerShell DSC resource MSFT_SPUserProfileServiceApp  failed to execute Test-TargetResource functionality with error
message: You cannot call a method on a null-valued expression.
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : ProviderOperationExecutionFailure
    + PSComputerName        : contoso-spapp01.contoso.com

To avoid the error message, you need to setup a My Site Host location through the SharePoint Central Admin GUI. Even adding the MySiteHostLocation parameter in the DSC script does not remove the error message.

However, if I run the directly the following script (with the MySiteHostLocation parameter) - Initial SP configuration : no User Profile SA AND SPSite object exists for the URL specified:

SPUserProfileServiceApp UserProfileServiceApp
        {
            Name = $ConfigurationData.NonNodeData.SPFarm.UserProfileServiceApp.Name
            ProxyName = $ConfigurationData.NonNodeData.SPFarm.UserProfileServiceApp.Name
            ApplicationPool = $ConfigurationData.NonNodeData.SPFarm.ServiceApplicationPool.ServicesAppPool.Name
            ProfileDBName = $ConfigurationData.NonNodeData.SPFarm.UserProfileServiceApp.DBName.ProfileDBName
            SocialDBName = $ConfigurationData.NonNodeData.SPFarm.UserProfileServiceApp.DBName.SocialDBName
            SyncDBName = $ConfigurationData.NonNodeData.SPFarm.UserProfileServiceApp.DBName.SyncDBName
            MySiteHostLocation = "http://mysites.contoso.com/"
            Ensure = "Present"
            DependsOn = "[SPFarm]Farm"
            PsDscRunAsCredential = $setupAccount
        }
PS C:\Windows\system32> Test-DscConfiguration -Detailed

PSComputerName  ResourcesInDesiredState        ResourcesNotInDesiredState     InDesiredState
--------------  -----------------------        --------------------------     --------------
localhost       {[SPFarm]Farm, [SPManagedAc...                                True

It's works perfectly from end to end.

Also, points I noticed (but don't know if it's can be considered as a bug):

  • You must enter a valid URL (SPSite object must exists) for MySiteHostLocation, otherwise you'll get an error. But from Central Admin, it's possible to set up an URL on the My Site Host location even if the Site and Web application does not exist.
  • If an URL A is already set on My Site Host location (from DSC script or manually) in the User Profile, and you would like to change it to URL B with DSC script, it does not work. In the verbose logs, the Test action detect that is not correct, do a Set action, without any error message, but at the end, URL A is already set.

The Build/Cumulative Update of SharePoint is running:

SharePoint 2016
BuildVersion : 16.0.5134.1001 (March 2021 CU)

The operating system the target node is running:

OsName               : Microsoft Windows Server 2019 Standard
OsOperatingSystemSKU : StandardServerEdition
OsArchitecture       : 64-bit
WindowsVersion       : 1809
WindowsBuildLabEx    : 17763.1.amd64fre.rs5_release.180914-1434
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

Version and build of PowerShell the target node is running:

Name                           Value
----                           -----
PSVersion                      5.1.17763.1
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17763.1
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Version of the DSC module that was used:

Name          Version Path
----          ------- ----
SharePointDSC 4.7.0   C:\Program Files\WindowsPowerShell\Modules\SharePointDSC\4.7.0\SharePointDSC.psd1

Let me know if you would like more information.

julmsy avatar Aug 17 '21 10:08 julmsy

Hi @julmsy, thanks for providing such a detailed report. One question though: Can you please share the full Verbose output for this resource? I would like to see where exactly this goes wrong.

ykuijs avatar Aug 31 '21 15:08 ykuijs

Hi @ykuijs, please find complete verbose logs regarding this resource (SPUserProfileServiceApp without MySiteHostLocation parameter). This log is the second run, meaning that User Profile SA was creating on the first run.

VERBOSE: [CONTOSO-SPDEV01]: LCM:  [ Start  Resource ]  [[SPUserProfileServiceApp]UserProfileServiceApp]
VERBOSE: [CONTOSO-SPDEV01]: LCM:  [ Start  Test     ]  [[SPUserProfileServiceApp]UserProfileServiceApp]
VERBOSE: [CONTOSO-SPDEV01]:                            [[SPUserProfileServiceApp]UserProfileServiceApp] Testing for
user profile service application User Profile Service Application
VERBOSE: [CONTOSO-SPDEV01]:                            [[SPUserProfileServiceApp]UserProfileServiceApp] Getting user
profile service application User Profile Service Application
VERBOSE: [CONTOSO-SPDEV01]:                            [[SPUserProfileServiceApp]UserProfileServiceApp] Executing as
the local run as user CONTOSO\svc_sp_install
VERBOSE: [CONTOSO-SPDEV01]:                            [[SPUserProfileServiceApp]UserProfileServiceApp] Leaving
BeginProcessing Method of Get-SPFarm.
VERBOSE: [CONTOSO-SPDEV01]:                            [[SPUserProfileServiceApp]UserProfileServiceApp] Leaving
ProcessRecord Method of Get-SPFarm.
VERBOSE: [CONTOSO-SPDEV01]:                            [[SPUserProfileServiceApp]UserProfileServiceApp] Leaving
EndProcessing Method of Get-SPFarm.
VERBOSE: [CONTOSO-SPDEV01]:                            [[SPUserProfileServiceApp]UserProfileServiceApp] Leaving
BeginProcessing Method of Get-SPManagedAccount.
VERBOSE: [CONTOSO-SPDEV01]:                            [[SPUserProfileServiceApp]UserProfileServiceApp] Leaving
ProcessRecord Method of Get-SPManagedAccount.
VERBOSE: [CONTOSO-SPDEV01]:                            [[SPUserProfileServiceApp]UserProfileServiceApp] Leaving
EndProcessing Method of Get-SPManagedAccount.
VERBOSE: [CONTOSO-SPDEV01]:                            [[SPUserProfileServiceApp]UserProfileServiceApp] Executing as
the local run as user CONTOSO\svc_sp_install
VERBOSE: [CONTOSO-SPDEV01]:                            [[SPUserProfileServiceApp]UserProfileServiceApp] Leaving
BeginProcessing Method of Get-SPServiceApplication.
VERBOSE: [CONTOSO-SPDEV01]:                            [[SPUserProfileServiceApp]UserProfileServiceApp] Leaving
ProcessRecord Method of Get-SPServiceApplication.
VERBOSE: [CONTOSO-SPDEV01]:                            [[SPUserProfileServiceApp]UserProfileServiceApp] Leaving
EndProcessing Method of Get-SPServiceApplication.
VERBOSE: [CONTOSO-SPDEV01]:                            [[SPUserProfileServiceApp]UserProfileServiceApp] Leaving
BeginProcessing Method of Get-SPServiceApplicationProxy.
VERBOSE: [CONTOSO-SPDEV01]:                            [[SPUserProfileServiceApp]UserProfileServiceApp] Leaving
ProcessRecord Method of Get-SPServiceApplicationProxy.
VERBOSE: [CONTOSO-SPDEV01]:                            [[SPUserProfileServiceApp]UserProfileServiceApp] Leaving
EndProcessing Method of Get-SPServiceApplicationProxy.
VERBOSE: [CONTOSO-SPDEV01]:                            [[SPUserProfileServiceApp]UserProfileServiceApp] Leaving
BeginProcessing Method of Get-SPServiceApplicationProxyGroup.
VERBOSE: [CONTOSO-SPDEV01]:                            [[SPUserProfileServiceApp]UserProfileServiceApp] Leaving
ProcessRecord Method of Get-SPServiceApplicationProxyGroup.
VERBOSE: [CONTOSO-SPDEV01]:                            [[SPUserProfileServiceApp]UserProfileServiceApp] Leaving
EndProcessing Method of Get-SPServiceApplicationProxyGroup.
VERBOSE: [CONTOSO-SPDEV01]:                            [[SPUserProfileServiceApp]UserProfileServiceApp] Leaving
BeginProcessing Method of Get-SPWebApplication.
VERBOSE: [CONTOSO-SPDEV01]:                            [[SPUserProfileServiceApp]UserProfileServiceApp] Leaving
ProcessRecord Method of Get-SPWebApplication.
VERBOSE: [CONTOSO-SPDEV01]:                            [[SPUserProfileServiceApp]UserProfileServiceApp] Leaving
EndProcessing Method of Get-SPWebApplication.
VERBOSE: [CONTOSO-SPDEV01]:                            [[SPUserProfileServiceApp]UserProfileServiceApp] Leaving
BeginProcessing Method of Get-SPServiceContext.
VERBOSE: [CONTOSO-SPDEV01]:                            [[SPUserProfileServiceApp]UserProfileServiceApp] Leaving
ProcessRecord Method of Get-SPServiceContext.
VERBOSE: [CONTOSO-SPDEV01]:                            [[SPUserProfileServiceApp]UserProfileServiceApp] Leaving
EndProcessing Method of Get-SPServiceContext.
VERBOSE: [CONTOSO-SPDEV01]: LCM:  [ End    Test     ]  [[SPUserProfileServiceApp]UserProfileServiceApp]  in 1.2810
seconds.
PowerShell DSC resource MSFT_SPUserProfileServiceApp  failed to execute Test-TargetResource functionality with error
message: You cannot call a method on a null-valued expression.
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : ProviderOperationExecutionFailure
    + PSComputerName        : contoso-spdev01.contoso.com

This error above occurs systematically on further run, and also cause an error when you are trying to run a Test-DscConfiguration command:

PS C:\Windows\system32> Test-DscConfiguration -Detailed
WARNING: [CONTOSO-SPDEV01]:                            [] The TEST operation will be carried against a pending
configuration since the latest configuration has not converged yet.
PowerShell DSC resource MSFT_SPUserProfileServiceApp  failed to execute Test-TargetResource functionality with error
message: You cannot call a method on a null-valued expression.
    + CategoryInfo          : InvalidOperation: (root/Microsoft/...gurationManager:String) [], CimException
    + FullyQualifiedErrorId : ProviderOperationExecutionFailure
    + PSComputerName        : localhost

Let me know if you need more logs.

julmsy avatar Sep 14 '21 14:09 julmsy

I have a requirement to create a farm without any webapplication but with User Profile Service. I am getting this issue where if I do not configure MySiteHostLocation it will fail tests after creation.

Is there anything I can provide to help with assisting to find the reason for the issue?

SPSE (June CU) + SharePoint DSC 5.2.0

regularroutine avatar Sep 16 '22 12:09 regularroutine

I have the same issue.

It seems the problem is when creating the User Profile Service Application without a MySiteHost.

Then Get-TargetResource in SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/MSFT_SPUserProfileServiceApp.psm1 throws this error.

Line 208 $upMySiteLocation gets an empty [system.uri], and then on line 226 we try to run the TrimEnd method on a null value: $upMySiteLocation.AbsoluteUri.TrimEnd("/")

I'm new to contributing but i can try to fix this. :-)

hebbea avatar Oct 27 '22 14:10 hebbea

Hi @ahebx, thanks for the fix/PR. I have just merged the PR. It will be included in the next version!

ykuijs avatar Oct 31 '22 11:10 ykuijs