The code below first gets a list of server names from a text file. It then loops through that list grabbing a date/time stamp that is inside of another text file that is located on each of those servers.
I am trying to build an object that contains two properties: ‘Server’ and ‘Datetime’. I would then like to add the server name and the date/time info that is collected from each loop iteration to the object. So far I can only add a single row to the object. How can I add multiple rows to it? Does the hash table created before need to contain the multiple rows of data before making it into an object?
$servers = Get-Content ".\servers.txt" $datetime_stamps = @() foreach($server in $servers){ $datetime_stamps += Get-Content "\\$server\info.txt" $props = @{ 'Server' = $server; 'DateTime' = $datetime_stamp } $obj = New-Object -TypeName PSObject -Property $props $obj }
Thanks,
Shane