xPSDesiredStateConfiguration icon indicating copy to clipboard operation
xPSDesiredStateConfiguration copied to clipboard

xService: cannot be used for Computer Browser Service if it is not installed

Open TuemmlerKelch opened this issue 2 years ago • 4 comments

Problem description

I want to make sure the service "Computer Browser" is not installed on my devices. Unfortunately there seems to be a Problem combined with the way Get-Service works (-Name also seems to look for DisplayName, if there is no hit) and the fact that Microsoft has this great combination of Services:

# Name DisplayName Description
1 Browser Computer Browser This is a "normal" service, that you can see in Services.msc
2 Bowser Browser Apparently this is the "Browser Support Driver"

As a result, Get-Service, which is called in line 52 of DSC_xServiceResource.psm1 returns the Bowser Service, rather than the Browser, which I am looking for. Regardless of Browser only being the DisplayName and not Name. Next, it tries to execute "Get-ServiceCimInstance -ServiceName $Name", which will be empty, as this won't work for Bowser Service. This then leads to the String-Conversion failing, as there is no return value from and thus no StartMode ($startupType = ConvertTo-StartupTypeString -StartMode $serviceCimInstance.StartMode)

Verbose logs

PowerShell DSC resource DSC_xServiceResource  failed to execute Test-TargetResource functionality with error message: The property 'StartMode' cannot be found on this object. Verify that the property exists. 
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : ProviderOperationExecutionFailure
    + PSComputerName        : DESKTOP-55FBL3B

DSC configuration

instance of DSC_xServiceResource as $DSC_xServiceResource1ref
{
Name = "Browser";
 Ensure = "Absent";
 ModuleName = "xPSDesiredStateConfiguration";
 ResourceID = "[xService]Browser";

 ModuleVersion = "9.1.0";


 ConfigurationName = "ServiceConfig";

};
instance of OMI_ConfigurationDocument
                    {
                        Version="2.0.0";
                        MinimumCompatibleVersion = "1.0.0";
                        CompatibleVersionAdditionalProperties= {"Omi_BaseResource:ConfigurationName"};

                    };

Suggested solution

Imo, Get-Service should not fall back to DisplayName, but I don't think that will ever happen. So, maybe a check if (get-service -name browser).Name (in this case Bowser) equals the input-value when checking the Service (in this case "Browser")

Operating system the target node is running

OsName               : Microsoft Windows 10 Pro
OsOperatingSystemSKU : 48
OsArchitecture       : 64-bit
WindowsVersion       : 2009
WindowsBuildLabEx    : 19041.1.amd64fre.vb_release.191206-1406
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

PowerShell version and build the target node is running

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

xPSDesiredStateConfiguration version

Name                         Version Path                                                                                                           
----                         ------- ----                                                                                                           
xPSDesiredStateConfiguration 9.1.0   C:\Program Files\WindowsPowerShell\Modules\xPSDesiredStateConfiguration\9.1.0\xPSDesiredStateConfiguration.psd1

TuemmlerKelch avatar Dec 07 '23 13:12 TuemmlerKelch

Can confirm that the parameter -Name also looks at the DisplayName, even though there exist a separate parameter -DisplayName on the command. This seems how Get-Service command is built and we cannot prevent that. I think the best option is to add a parameter Exclude that takes a string array so when it returns wrong services we can remove them, e.g. get-service -Name browser -Exclude 'bowser' 🤔

johlju avatar Dec 07 '23 16:12 johlju

So, maybe a check if (get-service -name browser).Name (in this case Bowser) equals the input-value when checking the Service (in this case "Browser")

Good suggestion but I think this could possibly be a breaking change if this Get-Service bug actually make it work in another case. 🤔 So suggest adding the Exclude parameter instead.

johlju avatar Dec 07 '23 17:12 johlju

Here is a similar discussion from the PS github: https://github.com/PowerShell/PowerShell/issues/21312

TuemmlerKelch avatar Mar 20 '24 12:03 TuemmlerKelch

Sadly above issue was closed with the information that this will not be fixed and instead just be regarded as documentation bug, which I do not agree with, as this isn't even consistently working to return kernel-drivers and "bowser" is the only kernel driver being returned that way. I really had hoped there would at least be the addition of a proper paramater that does work as it should, but apparently this cannot be helped. https://github.com/MicrosoftDocs/PowerShell-Docs/issues/10966

TuemmlerKelch avatar Apr 30 '24 07:04 TuemmlerKelch