自定义PowerShell函数,在设置参数的时候中,可以将参数设置为某些情况下可选,某些条件下又设置为必选。 示例代码从网站复制的。 1functionConnect-Somewhere2{3[CmdletBinding(DefaultParameterSetName='A')]4param5(6[Parameter(ParameterSetName='A',Mandatory=$false)]7[Parameter(ParameterSetName='B',Mandatory=$...
The List and LogName parameters identify two separate parameter sets. Unique parameter Each parameter set must have a unique parameter that the PowerShell runtime uses to expose the appropriate parameter set. If possible, the unique parameter should be a mandatory parameter. When a parameter is ...
自动变量 $PSCmdlet 提供ParameterSetName 属性。此属性包含正在使用的参数集的名称。 可以在函数中使用此属性来确定使用哪个参数集来选择特定于参数集的行为。 PowerShell 复制 function Get-ParameterSetName { [CmdletBinding(DefaultParameterSetName = 'Set1')] param ( [Parameter(ParameterSetName = 'Set1',...
ParameterSetName 属性包含正在使用的参数集的名称,而 ShouldProcess 方法将 WhatIf 和Confirm 参数动态添加到 cmdlet。 有关$PSCmdlet 自动变量的详细信息,请参阅 about_Functions_Advanced。 $PsCulture 包含操作系统中当前所用的区域性的名称。区域性确定数字、货币和日期等项的显示格式。这是系 统的System.Globaliz...
0-win-arm64.zip # Set up remoting to PowerShell 7 Set-Location .\PowerShell-7.5.0-win-arm64 # Be sure to use the -PowerShellHome parameter otherwise it tries to create a new # endpoint with Windows PowerShell 5.1 .\Install-PowerShellRemoting.ps1 -PowerShellHome . ...
还可以使用Select-Object和Format-Listcmdlet 显示对象的属性值。Select-Object和Format-List每个 都有一个 Property参数。 可以使用Property参数指定一个或多个属性及其值。 或者,可以使用通配符 (*) 来表示所有属性。 例如,以下命令显示 pwsh.exe 文件的所有属性的值。
The AddExchangeLocation parameter specifies the mailboxes to add to the list of included mailboxes when you aren't using the value All for the ExchangeLocation parameter. Valid values are: A regular user mailbox. Including other types of mailboxes (for example, inactive mailboxes or Microsoft ...
Set-PSReadLineOption-Colors@{ Command ='Magenta'Number ='DarkGray'Member ='DarkGray'Operator ='DarkGray'Type ='DarkGray'Variable ='DarkGreen'Parameter ='DarkGreen'ContinuationPrompt ='DarkGray'Default ='DarkGray'} 示例5:设置多种类型的颜色值 ...
该Set-ExecutionPolicycmdlet 的默认作用域会影响LocalMachine使用计算机的每个人。 若要更改其LocalMachine执行策略,请使用“以管理员身份运行”启动 PowerShell。 若要显示每个范围的执行策略,请使用Get-ExecutionPolicy -List。 若要查看 PowerShell 会话的有效执行策略,请使用不带任何参数的Get-ExecutionPolicy。
Convert -ChildPath parameter to string[] for Join-Path cmdlet (#24677) (Thanks @ArmaanMcleod!) PowerShell 7.6-preview.4 includes the following updated modules: Microsoft.PowerShell.ThreadJob v2.2.0 ThreadJob v2.1.0 The ThreadJob module was renamed to Microsoft.PowerShell.ThreadJob. There is...