Good day,
I was recently attempting to simplify a script for users and thought gathering a list of the available services would be the best route. The function base will have a param for computername and dynamicparam for the service names.
However i cant seem to gather the list from a remote computer the list only shows the services on my local machine. Has anyone run into this before or something similar and if so have thoughts or options?
The code i have to start is
function Get-WindowService
{
[CmdletBinding()]
Param (
# ComputerName
[Parameter(Mandatory=$false,
ValueFromPipelineByPropertyName=$true,
Position=0)]
$ComputerName = $env:COMPUTERNAME
)
DynamicParam {
$attributes = new-object System.Management.Automation.ParameterAttribute
$attributes.ParameterSetName = "__AllParameterSets"
$attributes.Mandatory = $true
$attributes.Position = 1
$attributeCollection = new-object -Type System.Collections.ObjectModel.Collection[System.Attribute]
$attributeCollection.Add($attributes)
$Values = (Get-CimInstance -ClassName win32_service -ComputerName $ComputerName).name
$ValidateSet = new-object System.Management.Automation.ValidateSetAttribute($Values)
$attributeCollection.Add($ValidateSet)
$dynParam1 = new-object -Type System.Management.Automation.RuntimeDefinedParameter("ServiceName", [string], $attributeCollection)
$paramDictionary = new-object -Type System.Management.Automation.RuntimeDefinedParameterDictionary
$paramDictionary.Add("ServiceName", $dynParam1)
return $paramDictionary
}
Begin {
$ServiceName = $PSBoundParameters.ServiceName
}
Process {
}
End {
}
}