Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 260 Vote(s) - 3.53 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Alias a Property Name In Powershell 3

#1
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?
Reply

#2

You could do an intermediate step of creating objects with the property names you want using the `new-object` cmdlet.

Get-Service | foreach{ new-object PSObject -property @{newname=($_.Name); newstatus=($_.Status)}} | ConvertTo-Html > .\services.htm
Reply

#3
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
Reply

#4
How about using select-object?

get-service | select-object -property @{N='MyNewStatus';E={$_.Status}}, @{N='MyNewName';E={$_.Name}} | ConvertTo-HTML > C:\services.htm
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through