þÿ# Get-ADUser-Properties.ps1 # # Este script regresa las propiedades de un usuario de Active Directory # a partir de su nombre de usuario. # # Modo de uso: Get-ADUser-Properties.ps1 -account cuenta # # Copyright (C) Victor Lozano 2011 # victor.lozano@mildecabeza.com # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # #Se obtiene la cuenta a partir de los argumentos. param($account) #Se valida que no sea nulo el valor de $account. if($account -eq $null){ Write-Host "ERROR: Se requiere un nombre de cuenta." -foregroundcolor red exit } #Se asigna la ruta LDAP del dominio. $path = "LDAP://DC=demo,DC=com" #Se crea un objeto DirectorySearcher con la ruta LDAP. $objSearcher = New-Object System.DirectoryServices.DirectorySearcher([ADSI] $path) #Se define la consulta LDAP para la busqueda. $strFilter = "(&(objectclass=user)(objectcategory=person)(samaccountname=$account))" #Se asigna al objeto DirectorySearcher la consulta. $objSearcher.Filter = $strFilter #Se ejecuta la consulta y se obtiene el resultado. $colResults = $objSearcher.FindAll() #Se recorren los resultsdos para obtener la propiedades. foreach ($objResult in $colResults){ $objResult.properties }