I don’t think so, no. Even if there is a way using
$b = $t.a
Get-Service @b
still much cleaner and what I would recommend.
An example of how to implement it:
function disableservices ($type) {
$types = @{
web = @{name = '*iis*'}
db = @{name = '*sqlserv*'}
windows = @{name = 'win*' }
}
if($types.ContainsKey($type)) {
$b = $types[$type]
Get-Service @b | Stop-Service
} else {
Write-Error "The type '$type' is not supported"
}
}
disableservices windows
source
share