I have this script but it does not extract any attributes like Company, Title:
<code># Import the DSInternals module
Import-Module "C:Program FilesWindowsPowerShellModulesDSInternals"
# Define file paths
$NTDSFile = "D:SysbackADBackupNTDS.dit"
$SYSTEMHive = "D:SysbackRegistryBackupSYSTEM"
$outputPath = "F:UserPersonnelInfo.csv"
# Extract the boot key from the SYSTEM hive
Write-Host "Extracting the boot key from the SYSTEM hive..."
$bootKey = Get-BootKey -SystemHivePath $SYSTEMHive
# Extract Active Directory accounts and attributes
Write-Host "Extracting user attributes from NTDS.dit..."
$accounts = Get-ADDBAccount -All -DBPath $NTDSFile -BootKey $bootKey
# Select personnel attributes
Write-Host "Selecting personnel attributes..."
$selectedAccounts = $accounts | Where-Object { $_.PrimaryGroupId -eq 513 } | # User accounts only
Select-Object `
SamAccountName, `
DistinguishedName, `
@{Name='Company'; Expression={($_.Attributes['company'])}}, `
@{Name='Title'; Expression={($_.Attributes['title'])}}, `
@{Name='Department'; Expression={($_.Attributes['department'])}}, `
@{Name='StreetAddress'; Expression={($_.Attributes['streetAddress'])}}, `
@{Name='City'; Expression={($_.Attributes['l'])}}, `
@{Name='State'; Expression={($_.Attributes['st'])}}, `
@{Name='PostalCode'; Expression={($_.Attributes['postalCode'])}}, `
@{Name='Country'; Expression={($_.Attributes['c'])}}
# Export to CSV
Write-Host "Exporting personnel data to $outputPath..."
$selectedAccounts | Export-Csv -Path $outputPath -NoTypeInformation
Write-Host "Extraction completed successfully!" -ForegroundColor Green
</code>
<code># Import the DSInternals module
Import-Module "C:Program FilesWindowsPowerShellModulesDSInternals"
# Define file paths
$NTDSFile = "D:SysbackADBackupNTDS.dit"
$SYSTEMHive = "D:SysbackRegistryBackupSYSTEM"
$outputPath = "F:UserPersonnelInfo.csv"
# Extract the boot key from the SYSTEM hive
Write-Host "Extracting the boot key from the SYSTEM hive..."
$bootKey = Get-BootKey -SystemHivePath $SYSTEMHive
# Extract Active Directory accounts and attributes
Write-Host "Extracting user attributes from NTDS.dit..."
$accounts = Get-ADDBAccount -All -DBPath $NTDSFile -BootKey $bootKey
# Select personnel attributes
Write-Host "Selecting personnel attributes..."
$selectedAccounts = $accounts | Where-Object { $_.PrimaryGroupId -eq 513 } | # User accounts only
Select-Object `
SamAccountName, `
DistinguishedName, `
@{Name='Company'; Expression={($_.Attributes['company'])}}, `
@{Name='Title'; Expression={($_.Attributes['title'])}}, `
@{Name='Department'; Expression={($_.Attributes['department'])}}, `
@{Name='StreetAddress'; Expression={($_.Attributes['streetAddress'])}}, `
@{Name='City'; Expression={($_.Attributes['l'])}}, `
@{Name='State'; Expression={($_.Attributes['st'])}}, `
@{Name='PostalCode'; Expression={($_.Attributes['postalCode'])}}, `
@{Name='Country'; Expression={($_.Attributes['c'])}}
# Export to CSV
Write-Host "Exporting personnel data to $outputPath..."
$selectedAccounts | Export-Csv -Path $outputPath -NoTypeInformation
Write-Host "Extraction completed successfully!" -ForegroundColor Green
</code>
# Import the DSInternals module
Import-Module "C:Program FilesWindowsPowerShellModulesDSInternals"
# Define file paths
$NTDSFile = "D:SysbackADBackupNTDS.dit"
$SYSTEMHive = "D:SysbackRegistryBackupSYSTEM"
$outputPath = "F:UserPersonnelInfo.csv"
# Extract the boot key from the SYSTEM hive
Write-Host "Extracting the boot key from the SYSTEM hive..."
$bootKey = Get-BootKey -SystemHivePath $SYSTEMHive
# Extract Active Directory accounts and attributes
Write-Host "Extracting user attributes from NTDS.dit..."
$accounts = Get-ADDBAccount -All -DBPath $NTDSFile -BootKey $bootKey
# Select personnel attributes
Write-Host "Selecting personnel attributes..."
$selectedAccounts = $accounts | Where-Object { $_.PrimaryGroupId -eq 513 } | # User accounts only
Select-Object `
SamAccountName, `
DistinguishedName, `
@{Name='Company'; Expression={($_.Attributes['company'])}}, `
@{Name='Title'; Expression={($_.Attributes['title'])}}, `
@{Name='Department'; Expression={($_.Attributes['department'])}}, `
@{Name='StreetAddress'; Expression={($_.Attributes['streetAddress'])}}, `
@{Name='City'; Expression={($_.Attributes['l'])}}, `
@{Name='State'; Expression={($_.Attributes['st'])}}, `
@{Name='PostalCode'; Expression={($_.Attributes['postalCode'])}}, `
@{Name='Country'; Expression={($_.Attributes['c'])}}
# Export to CSV
Write-Host "Exporting personnel data to $outputPath..."
$selectedAccounts | Export-Csv -Path $outputPath -NoTypeInformation
Write-Host "Extraction completed successfully!" -ForegroundColor Green
Is there any way to obtain such info from ntds.dit? Another way?
Or am I doing it wrong in attribute names?