Created
March 26, 2019 22:37
-
-
Save IISResetMe/447f3bb2c271ad993ac84c7d1cb6849c to your computer and use it in GitHub Desktop.
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
$params = @{ | |
Name = 'w*' | |
} | |
# unrelated stuff happening | |
# ... | |
# ... | |
# ... | |
$params2 = @{ | |
Exclude = 'w32time' | |
} | |
# another 200 lines of logging, comments, setup | |
# ... | |
# ... | |
# ... | |
# what are we looking for again? | |
$services = Get-Service @params @params2 |
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
# unrelated stuff happening | |
# ... | |
# ... | |
# ... | |
$params = @{ | |
Name = 'w*' | |
} | |
$params2 = @{ | |
Exclude = 'w32time' | |
} | |
# why do I have to look twice for these | |
$services = Get-Service @params @params2 |
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
# unrelated stuff happening | |
# ... | |
# ... | |
# ... | |
$params = @{ | |
Name = 'w*' | |
Exclude = 'w32time' | |
} | |
# lines are short and readable, $params definition is close | |
$services = Get-Service @params |
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
# Implementing proxy functions | |
function Get-ServicesWithW | |
{ | |
param( | |
[Parameter(ValueFromPipelineByPropertyName=$true)] | |
[Alias('Cn')] | |
[ValidateNotNullOrEmpty()] | |
[string[]] | |
${ComputerName}, | |
[Alias('DS')] | |
[switch] | |
${DependentServices}, | |
[Alias('SDO','ServicesDependedOn')] | |
[switch] | |
${RequiredServices}, | |
[Parameter(ParameterSetName='DisplayName', Mandatory=$true)] | |
[string[]] | |
${DisplayName}, | |
[ValidateNotNullOrEmpty()] | |
[string[]] | |
${Include}, | |
[ValidateNotNullOrEmpty()] | |
[string[]] | |
${Exclude}, | |
[Parameter(ParameterSetName='InputObject', ValueFromPipeline=$true)] | |
[ValidateNotNullOrEmpty()] | |
[System.ServiceProcess.ServiceController[]] | |
${InputObject} | |
) | |
# Ain't no way in hell I'm gonna write the if/elseif/else logic to inspect and | |
# ensure every possible permutation of named parameter arguments are supported here. | |
# I want to focus only on the behavior of this function instead | |
$PSBoundParameters['Name'] = 'w*' | |
$PSBoundParameters['Exclude'] = if($PSBoundParameters.Contains('Exclude')){ | |
@($PSBoundParameters['Exclude'];'w32time') | |
} | |
else { | |
,'w32time' | |
} | |
Get-Service @PSBoundParameters | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment