Using the example below:
Get-Service | ConvertTo-HTML -Property Name, Status > C:\services.htm
I was wondering if it is possible to alias the property name - the same way you could in SQL:
Example:
Get-Service | ConvertTo-HTML -Property Name AS NEWNAME , Status AS MYNEWSTATUSNAME> C:\services.htm
I know the above syntax wouldn't work... What is the correct way to alias a property name?
An alias is an alternate name or nickname for a cmdlet or for a command element, such as a function, script, file, or executable file. You can use the alias instead of the command name in any PowerShell commands.
PowerShell includes built-in aliases that are available in each PowerShell session. The Get-Alias cmdlet displays the aliases available in a PowerShell session. To create an alias, use the cmdlets Set-Alias or New-Alias . In PowerShell 6, to delete an alias, use the Remove-Alias cmdlet.
To create an alias for a command, create a function that includes the command, and then create an alias to the function. To save the aliases from a session and use them in a different session, add the Set-Alias * command to your Windows PowerShell profile. Profiles do not exist by default.
How about using select-object?
get-service | select-object -property @{N='MyNewStatus';E={$_.Status}}, @{N='MyNewName';E={$_.Name}} | ConvertTo-HTML > C:\services.htm
The way to alias a property name is to add an AliasPropery to the object.
Get-Service | foreach { $_ | Add-Member -MemberType AliasProperty -Name MYNEWSTATUSNAME -Value Status -PassThru } | Select Name,MYNEWSTATUSNAME
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With