add aParameterattribute for each parameter set. This attribute enables you to define the parameter differently for each parameter set. For example, you can define a parameter as mandatory
Those are 2 different parametersets for the Get-Process cmdlet. Here is an example of how you would code parametersets using advanced functions: function test-param { param( [Parameter(ParameterSetName=”p1″,Position=0)] [DateTime] $d, [Parameter(ParameterSetName=”p2″,Position=0)] [int]...
.PARAMETER ComputerName The remote computer(s) to check the status of the services on. .PARAMETER Credential Specifies a user account that has permission to perform this action. The default is the current user. .EXAMPLE Get-MrAutoStoppedService -ComputerName 'Server1', 'Server2' .EXAMPLE '...
theSet-SQLdmMonitoredInstancecan accept a string array for the Path parameter, which I've reflected in the $Instances variable definition ([string[]] is an array of string values; [string] is just a single string value.)
example, there are three ways to use theGet-Processcmdlet. The one most everyone knows about is usingGet-Processto obtain information about a process by passing it a name. In fact, this is the default parameter set, and you do not need to do anything special to use this parameter set....
In my example, I create an alias called Filename that applies to the Name parameter, like so:复制 private string _name = "PowerShellIsolatedStore"; /// name of store [Alias("Filename")] [Parameter] public string Name { get { return _name; } set { _name = value; } } Common ...
Or, you can use the Parameter parameter with the wildcard character ( * ) value to find information about all parameters of the command. For example, the following command gets information about all parameters of the Get-Member cmdlet: PowerShell Copy Get-Help Get-Member -Parameter * ...
For example, this parameter works when a command contains the Write-Verbose cmdlet. YAML Kopija Type: SwitchParameter Aliases: vb Required: False Position: Named Default value: False Accept pipeline input: False Accept wildcard characters: False The Verbose parameter overrides the value of the ...
As you can see, I've simply wrapped my working code in a function named Get-SPInventory. I've defined it with an input parameter named $filename, so it can just be called like this: Copy Get-SPInventory c:\computernames.txt The results can still be piped to a CSV file, converte...
Optional parameters have a default value, which is the value that is used or assumed when the parameter is not specified in the command. For example, the default value of theComputerNameparameter of many cmdlets is the name of the local computer. As a result, the local computer name is us...