Powershell - Script para exportar listado de cuentas de usuario, estado y email

Publicado: 01 Junio 2018, 15:04
por Cazador
Requisitos

Reemplazar las XXXXXX con la cuenta del dominio de Directorio Activo. Ejemplo: DC=contoso,DC=local

DC=XXXXXX,DC=XXXXXX

Powershell Script

Código:

<#power<# Creator: ELSATE.com
Creation date: 01-06-2018

.SYNOPSIS
   Get amount of DA accounts that are in use.
.DESCRIPTION
   This script will create a report of DA accounts in AD.

#>
#>

[system.reflection.assembly]::loadwithpartialname('microsoft.visualbasic') | Out-Null
$fileLocation = [microsoft.visualbasic.interaction]::inputbox('give up filelocation were to save the file','Save As','c:\Temp\exportdata.csv')

<#
This is the Script block it sels that will do everything
#>
Clear-Host
Write-Host "Starting Script..."

$OurUsers = Get-ADUser -SearchBase "DC=XXXXXX,DC=XXXXXX" -filter * -Properties *
$OurUsers = $OurUsers | Select-Object @{Name='DistinguishedName';Expression = {$_.DistinguishedName.Split(',', 2)[1]}}, @{Name="AD DisplayName";Expression={$_.CN}}, @{Name="Accountname";Expression={$_.SamAccountName}},@{Name="Disabled";Expression={$_.Enabled}}, @{Name="E-mail";Expression={$_.Mail}}
$AllUsers += $OurUsers


$AllUsers = $AllUsers | Export-Csv $fileLocation -Encoding UTF8 -NoTypeInformation -UseCulture

Write-Host "Finish"

Publicidad