根据CSV找出USBGroup中计算机对应的用户

<USB.CSV>
Hostname,Username
CNHZPD-TEST1,User1
CNHZLN-01234567,User2
 
$group = "CN=Enable_CDUSB_CHNHGHWin7&8,OU=Groups,OU=Hangzhou - China,OU=TCS - China,OU=TCS - China,DC=apac,DC=TCS,DC=com"
$cmdbdesktop = Import-Csv -Path 'F:\Ivan\HZCMDB~~01--Non GE DST.csv'
$cmdblaptop = Import-Csv -Path 'F:\Ivan\HZCMDB~~02--Laptop.csv'
$machines = Get-ADGroup -Filter * -SearchBase $group | Get-ADGroupMember | Get-ADComputer -Properties *
foreach($adesktop in $cmdbdesktop) {
    foreach($machine in $machines) {
        if($machine.name -eq $adesktop.hostname) {
            $machine | select name , @{N='owner';E={$adesktop.username}}
        }
    }
}
foreach($alaptop in $cmdblaptop) {
    foreach($machine in $machines) {
        if($machine.name -eq $alaptop.hostname) {
            $machine | select name , @{N='owner';E={$alaptop.username}}
        }
    }
}

 

posted @ 2015-05-08 14:57  dongdonggeorge  阅读(227)  评论(0编辑  收藏  举报