可以看到我们传入Sort-Object的是一个Hashtable对象 TypeName:System.Collections.Hashtable 这玩意就是整体,没有可排序的。 解决 所以我们要把Hashtable拆为多个item的集合,一遍Sort-Object可以根据我们指定的属性进行排序,此处我们使用GetEnumerator()方法 $a.GetEnumerator() |sort-Property name Ref https://devblogs....
如果集合中有你想要按照它来排序的字段,排序是非常容易的,你可以把数据添加到对象里或者使用Sort-Object来创建一个自定义排序表达式 Get-ADUser|Sort-Object-Parameter@{ e={Get-TotalSales$_.Name } } 在这个示例中,我取出了用户集合并使用自定义命令获取额外信息用来排序. 排序hashtable列表 如果你有一个hashtabl...
Describes how to create, use, and sort hashtables in PowerShell. Long description A hashtable, also known as a dictionary or associative array, is a compact data structure that stores one or more key-value pairs. For example, a hashtable might contain a series of IP addresses and computer...
PS (11) > $user[[string[]] ($user.keys | sort)] John Smith 555-1212 You’ll notice something funny about the last example: we had to cast or convert the sorted list into an array of strings. This is because the hashtable keys mechanism expects strings, not objects, as keys. There...
当你执行$hash = $hash.GetEnumerator() | Sort-Object -property:Value时,你正在将哈希表重新分配给...
如果您有想要排序的哈希表清單,您會發現Sort-Object不會將您的索引鍵視為屬性。 我們可以使用自定義排序表示式來繞過這個問題。 PowerShell $data= @( @{name='a'} @{name='c'} @{name='e'} @{name='f'} @{name='d'} @{name='b'} )$data|Sort-Object-Property@{e={$_.name}} ...
and munching on a kiwi. I do not have enough time to make my usual bowl of Irish steel-cut oats this morning. While I wait for my tea to steep, I thought I would answer a question that I have received several times over the last few days, “How do I sort a hash table in Windo...
哈希表的嵌套使用可以让表的层次结构更清晰,就像多维数组一样。 譬如我要录入某个账号的属性,其中其地址需细分: 六、给对象和哈希表进行排序 如果要完成主要关键字降序,次要关键字升序的排序: Dir | Sort-Object@{expression="Length";Descending=$true},@{expression="Name";Ascending=$true}...
Ergh! What happened? Well, without going into tons of detail, it has to do with the type that backs HashTable and how you can’t sort the object itself. You’ve got to generate a list of key-value pairs and sort that. Here’s the correct way to do it: ...
Get-Process | Sort-Object StartTime | Format-Table -View StartTime Get-Process 获取表示计算机上运行的进程 System.Diagnostics.Process 对象。 对象将向下发送到 Sort-Object,并根据 StartTime 属性进行排序。 排序的对象将向下发送到管道 Format-Table。 View 参数指定在 PowerShell 文件中为 DotNetTypes.format...