Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Problem Combining csv files

$
0
0

Hi there my Powershell collegue is on holiday and he gave me the idea to look into powershell hashes to created the report I want. I will try to explain here what I want and what I already retreived with powershell.

I create 3 csv files 

First on is a report from all AD computer having Windows XP.

Second report is a SCCM report from all systems with the last logonname (username)

Last report is also from AD only a users export with the username and mail

 

What I want to do is like the second report using the AD column name [Name] linked to the second report column name [ComputerName]. That way I would like to get the Username column linked to my first report.

Then the next step is to link report 2 the column name [UserName] to report 3 column name [Username]. That way I would like to get the Mail column also linked to my first report.

I already created the following script:

$objlist = @{}# empty hash table (name is index)

$users = Import-Csv 'D:\INVSDATA\Powershell\Scripts\All Windows XP\AllUsers.csv'

$ADComp = Import-Csv 'D:\INVSDATA\Powershell\Scripts\All Windows XP\allWindowsXP.csv'

$SCCMComp = Import-Csv 'D:\INVSDATA\Powershell\Scripts\All Windows XP\SQLSCCMAllSystems.csv'

 

ForEach ($objItem in $ADComp)

    {

# if object already exists update container info

if ($objlist[$objItem.Name].OSName -eq $null)

{

        $obj = New-Object object 

        $obj | Add-Member -MemberType NoteProperty –Name Name –Value $objItem.Name

  $obj | Add-Member -MemberType NoteProperty –Name ParentContainer –Value $objItem.ParentContainer

        #$obj | Add-Member -MemberType NoteProperty –Name Username –Value 

            #$obj | Add-Member -MemberType NoteProperty –Name Mail –Value 

        $obj | Add-Member -MemberType NoteProperty –Name OSName –Value $objItem.OSName

        $obj | Add-Member -MemberType NoteProperty –Name operatingSystemServicePack –Value $objItem.operatingSystemServicePack

        $obj | Add-Member -MemberType NoteProperty –Name whenCreated –Value $objItem.whenCreated

        $obj | Add-Member -MemberType NoteProperty –Name LastLogonTimestamp –Value $objItem.LastLogonTimestamp

        $obj | Add-Member -MemberType NoteProperty –Name AccountIsDisabled –Value $objItem.AccountIsDisabled

            $objlist[$objItem.Name] = $obj

    }

    }

    $objlist.Values | Export-Csv -NoTypeInformation -Path 'D:\INVSDATA\Powershell\Scripts\All Windows XP\output.csv'


Viewing all articles
Browse latest Browse all 6937

Trending Articles