PSDscResources icon indicating copy to clipboard operation
PSDscResources copied to clipboard

WindowsFeature Absent should account for 'removed' as well

Open ewhitesides opened this issue 6 years ago • 2 comments

When I declare a simple resource such as this:

WindowsFeature RemoveTFTP {
    Name = 'TFTP-Client'
    Ensure = 'Absent'
}

I get returned that the resource is not in desired state (from get-dscconfigurationstatus) when applying this to 2016 servers without a GUI, because apparently by default this feature is removed, not available, etc.

To me, if the feature is removed, that also qualifies as absent, so it should return that it is in the desired state.

ewhitesides avatar May 20 '19 21:05 ewhitesides

output from a similar setting I had set on 'PNRP' feature:

Message System.InvalidOperationException: The requested feature PNRP could not be found on the target machine. HResult -2146233087 StackTrack at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input) at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke) at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync) at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection1 input, PSDataCollection1 output, PSInvocationSettings settings) at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection1 input, PSDataCollection1 output, PSInvocationSettings settings) at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings) at Microsoft.PowerShell.DesiredStateConfiguration.Internal.ResourceProviderAdapter.ExecuteCommand(PowerShell powerShell, ResourceModuleInfo resInfo, String operationCmd, List1 acceptedProperties, CimInstance nonResourcePropeties, CimInstance resourceConfiguration, LCMDebugMode debugMode, PSInvocationSettings pSInvocationSettings, UInt32& resultStatusHandle, Collection1& result, ErrorRecord& errorRecord, PSModuleInfo localRunSpaceModuleInfo)

ewhitesides avatar May 20 '19 21:05 ewhitesides

I had to do the following to overcome the issue:

#Disabled Features (STIG Requirements) $DisabledFeatures = @( 'Simple-TCPIP' 'Telnet-Client' 'PNRP' 'Web-Ftp-Server' 'Web-Ftp-Service' 'Web-Ftp-Ext' 'TFTP-Client' 'Fax' 'RSAT-Fax' ) Script Remove_Disabled_Features { #Using script resource because some features are not available at all, and windowsfeature resource reports error in configuring #'$.InstallState -match '^Install' covers Install and InstallPending GetScript = { #Do Nothing } SetScript = { $Installed_Features = Get-WindowsFeature | Where-Object {$.Name -in $Using:DisabledFeatures -and $.InstallState -match '^Install'} ForEach ($Feature in $Installed_Features) {Uninstall-WindowsFeature -Name $Feature} } TestScript = { $Installed_Features = Get-WindowsFeature | Where-Object {$.Name -in $Using:DisabledFeatures -and $_.InstallState -match '^Install'} if ($Installed_Features) {return $false} else {return $true} } }

ewhitesides avatar May 20 '19 21:05 ewhitesides