This repository has been archived by the owner on Jun 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
WindowsOptionalFeature: Ensure empty array output is not enumerated prematurely #192
Open
jambar42
wants to merge
4
commits into
PowerShell:dev
Choose a base branch
from
jambar42:Issue_191
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jambar42 - can you use a parameter name here? E.g.
Write-Output -InputObject ...
or$propertiesAsStrings | Write-Output -NoEnumerate
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried both of the suggestions listed above and both return the same results. The act of piping the object or feeding it into -InputObject both cause enumeration resulting in a failed LCM call to the Get method.
Invoke-DscResource -Name WindowsOptionalFeature -Method Get -ModuleName PSDSCResources -Property @{Name = 'HyperVisorPlatform'; Ensure = 'Present'}
A general error occurred that is not covered by a more specific error code.
+ CategoryInfo : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException
+ FullyQualifiedErrorId : MI RESULT 1
+ PSComputerName : localhost
Another option that may work is to make the output of line 58 always be an array.
PSDscResources/DscResources/MSFT_WindowsOptionalFeature/MSFT_WindowsOptionalFeature.psm1
Lines 54 to 65 in c6323a4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is really strange. We have a standard that we must only used named parameters, rather than positional. Specifying a parameter name shouldn't have changed the behavior here. I don't know what could have caused that.
What you could try is casting the value to an array in the return - although not sure this would work either:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are my results using the various outputs from Convert-CustomPropertyArrayToStringArray. So far, I've only found the first to return an empty array directly from this function. If you have other methods of ensuring this function always returns an array, even if empty I am curious to see them.
IsPublic IsSerial Name BaseType
True True String[] System.Array
You cannot call a method on a null-valued expression.
At line:1 char:1
(Convert-CustomPropertyArrayToStringArray -CustomProperties @()).GetT ...
CategoryInfo : InvalidOperation: (:) [], RuntimeException
FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:1 char:1
(Convert-CustomPropertyArrayToStringArray -CustomProperties @()).GetT ...
CategoryInfo : InvalidOperation: (:) [], RuntimeException
FullyQualifiedErrorId : InvokeMethodOnNull
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other option would be to adjust the calling of this function, however I don't think this is as clean and doesn't fit well with being unit tested.