0

I need to create custom columns to the output of my script in powershell.

dc55   (UTC-04:00) Santiago 4/26/2017 11:34:42 AM
DC10   (UTC-04:00) Santiago 4/26/2017 11:34:43 AM
DC11   (UTC-04:00) Santiago 4/26/2017 11:34:44 AM
DHCP10 (UTC-04:00) Santiago 4/26/2017 11:34:44 AM
DHCP11 (UTC-04:00) Santiago 4/26/2017 11:34:45 AM

so for example i need to format the output in this way

Server       TimeZone         Date and Time
-----        --------         --------------
dc55   (UTC-04:00) Santiago 4/26/2017 11:34:42 AM
DC10   (UTC-04:00) Santiago 4/26/2017 11:34:43 AM
DC11   (UTC-04:00) Santiago 4/26/2017 11:34:44 AM
DHCP10 (UTC-04:00) Santiago 4/26/2017 11:34:44 AM
DHCP11 (UTC-04:00) Santiago 4/26/2017 11:34:45 AM

this is the line of output in my script:

Write-Host "$Server $TimeZone  $date_time"
1

3 Answers 3

2

I usually do something like this:

New-Object -TypeName PSCustomObject -Property @{
            Server= $Server
            Timezone= $TimeZone
            DateTime= $DateTime}

You can then show that on screen or export to CSV or whatever works for you.

Sign up to request clarification or add additional context in comments.

Comments

2

or like this :

[pscustomobject]@{Server= $Server;Timezone= $TimeZone;DateTime= $DateTime}

Comments

1

Thanks guys i followed your advice and i was able to give format to my output

+10 for you guys!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.