Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to output to two columns

Status
Not open for further replies.

crookedm

Technical User
Aug 18, 2012
6
GB
I am using a module to query a backup product and need (what I thought would be simple) the output of the commands to create the output side by side.

ie.

Node Serial
node1 12345
node2 56789
node3 10112
etc

I query the data I need using
$backupnode = GetBackupNode
$backupnode = Get-BackupNode.hostname
$backupserial = Get=BackupSerial.id

I've then outputted that with write-output and I get the nodes and serials on top of one another.
Is this a simple thing to do as I have tried foreach and while statements that have failed to provide the output.

Apologies if this is something simple.
 
I would use a custom object then export the results. Not knowing how your data is structured, I can only give you an idea of what it would look like.
Code:
$backups = @()

#<Get Data somehow>
Foreach ($backup in $backups)
{

$backupnode = GetBackupNode
$backupnode = Get-BackupNode.hostname
$backupserial = Get=BackupSerial.id

# Create Object
$backup_info = New-Object PSObject
$backup_info | Add-Member -Type NoteProperty -Name 'Node' -Value $backupnode
$backup_info | Add-Member -Type NoteProperty -Name 'Serial' -Value $backupserial

#Save individual data
$backups += $backup_info
}
$backups | Export-Csv "C:\Temp\MyBackupFile.csv" -NoTypeInformation

Something like that


Light travels faster than sound. That's why some people appear bright until you hear them speak.
 
That's really good of you to reply, I am not sure if people are ever interested in seeing posters attempts.
I did start to go down the object route but from the above I can see I'd confused the foreach too.
I used foreach($backuphost in $backupnode)

Also I made an error in the original post, but I dont think it will matter too much:
This
$backupnode = GetBackupNode
$backupnode = Get-BackupNode.hostname
$backupserial = Get=BackupSerial.id

Should have read:

$backupnode = GetBackupNode
$backuphost = Get-BackupNode.hostname
$backupserial = Get=BackupSerial.id

Thank you again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top