您的位置:首页 > 职场人生

导出AD用户信息到 XSL

2011-09-15 11:08 417 查看
$objOU=[ADSI]"LDAP://OU=TEST,OU=XXX

Users,DC=XXX,DC=intranet,DC=asia"

$searcher=new-object directoryservices.directorysearcher($objOU)

$searcher.Filter="(&(objectclass=user))"

$users=$searcher.findall()

$excel = New-Object -ComObject Excel.Application

$excel.Visible = $True

$workbook = $excel.Workbooks.add()

$workbook.workSheets.item(2).delete()

$workbook.workSheets.item(2).delete()

$workbook.WorkSheets.item(1).Name = "UsersInfo"

$sheet = $workbook.WorkSheets.Item("UsersInfo")

$sheet.cells.item(1,1) = "Name"

$sheet.cells.item(1,2) = "Description"

$sheet.cells.item(1,3) = "Dep"

$sheet.cells.item(1,4) = "Tel"

$intRow=2

foreach ( $user in $users){

$Path=$user.Path

$account=[ADSI]$Path

$sheet.cells.item($intRow,1) = $account.Name.Value

$sheet.cells.item($intRow,2) = $account.description.Value

$sheet.cells.item($intRow,3) = $account.physicaldeliveryofficename.Value

$sheet.cells.item($intRow,4) = $account.telephonenumber.Value

$intRow++

}

$strPath = "D:\Test.xls"

IF(Test-Path $strPath)

{

Remove-Item $strPath

$Excel.ActiveWorkbook.SaveAs($strPath)

}

ELSE

{

$Excel.ActiveWorkbook.SaveAs($strPath)

}

$Excel.Quit()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息