i’m new to PowerShell, just want to know if there is a possibility in generating a new PropertyName with its own values? Take a look below for gps cmndlet:
I want to make a NewProperty name to be called “RANK”, and it will rank the Handle property 1st to 8th, where it will be based on Handles’value. For example Handles = 1178 would be the 1st and Handles = 165 would be the 8th. How can I do that?
Because you’d basically have to sort the items first, this would probably be best accomplished by creating a standalone function, “Select-Process,” for example, that did this. I’ll give you a very very high level example.
function Select-Process {
[CmdletBinding()]
Param(
[Parameter(ValueFromPipeline=$True)]
[object]$InputObject
)
BEGIN { $rank = 0 }
PROCESS {
$InputObject | Select *,@{n='Rank';e={$x}}
$x++
}
}