Powershell - Get-Unique Cmdlet 命令
Cmdlet
Get-Unique cmdlet 可用于从排序的对象列表中获取唯一对象。
在此示例中,我们将看到 Get-Unique cmdlet 的实际应用。
步骤 1
在此示例中,我们在变量中设置字符串列表。
在 PowerShell ISE 控制台中键入以下命令
$list = "one","two","two","three","four","five"
步骤 2
在此示例中,我们将打印原始字符串列表。
在 PowerShell ISE 控制台中键入以下命令
$list
输出
您可以在 PowerShell 控制台中看到以下输出。
one two two three four five
步骤 3
在此示例中,我们对列表进行排序,然后获取唯一值。
在 PowerShell ISE 控制台中键入以下命令
$list | sort | get-unique
输出
您可以在 PowerShell 控制台中看到以下输出。
five four one three two
❮ powershell_advanced_cmdlets.html