Hi guys!
I created a script to extract a users list from Active Directory, but it works only if I specify that I want users created today.
When I have removed the created date, my script doesn't worked.
Get-ADUser -Filter {(enabled -eq $true) -and (extensionattribute3 -eq "colaborador") -or (extensionattribute3 -eq "terceiro")} -Properties * | Select @{ expression={$_.Surname}; label='TSLASTNAME' },@{ expression={$_.GivenName}; label='TSFIRSTNAME'},@{
expression={$_.DisplayName}; label='TSDISPLAYNAME'},@{ expression={$_.PostalCode}; label='TSPOSTALCODE'},@{ expression={$_.Country}; label='TSCOUNTRY'},@{ expression={$_.StreetAddress}; label='TSADDRESSLINE1'},@{ expression={$_.State}; label='TSSTATEPROVINCE'},@{
expression={$_.Office}; label='TSLOCATIONSITE'},@{ expression={$_.OfficePhone}; label='TSPRIMARYPHONE'},@{ expression={$_.UserPrincipalName}; label='TSPRIMARYEMAIL'},@{ expression={$_.Title}; label='TSTITLE'},@{ expression={$_.Department}; label='TSDEPARTMENT'},@{
expression={$_.City}; label='TSCITY'},@{ expression={$_.UserPrincipalName}; label='TSLOGINID'},@{ expression={$_.UserPrincipalName}; label='TSUSERID'},@{ expression={$_.msExchUserCulture}; label='TSLOCALE'},@{ expression={$_.extensionAttribute14}; label='TSTYPE'},@{
expression={$_.extensionAttribute14}; label='TSGROUPUSER' },@{expression={$_.extensionAttribute14}; label='TSPLUSPCUSTVENDOR'},@{expression={$_.extensionAttribute14}; label='TSLANGUAGE'},@{expression={$_.extensionAttribute14}; label='TSTIMEZONE'},@{expression={$_.UserPrincipalName};
label='TSPERSONID'},@{expression={$_.extensionAttribute14}; label='TSJOBCODE'} | Export-Csv "\\server\integracao.adibm\teste.csv" -NoTypeInformation -Encoding unicode -Force
'99999999 LASTRECORD'| Out-File "\\server\integracao.adibm\teste.csv" -Append
(Get-Content \\server\integracao.adibm\teste.csv) | % {$_ -replace '"', ""} | out-file -FilePath "\\server\integracao.adibm\teste.csv" -Force -Encoding unicode
Error message:
Get-ADUser : Object reference not set to an instance of an object.
At C:\Scripts\Matricula\script_IBM_V2.ps1:2 char:1
+ Get-ADUser -Filter {(enabled -eq $true) -and (extensionattribute3 -eq "colaborad ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-ADUser], NullReferenceException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.NullReferenceException,Microsoft.ActiveDirectory.Management.Commands.GetADUser
Do you know how to fix this problem?
Thanks.
David Soares MCTS:MBS - MCTS - MCITP