I am trying to get all of the contractors and employee from our AD with enabled true for filter. AD itself is very huge and lots of data that may cause timeout limits when running powershell script. I am getting this error when I put it into variable and if I do a straight export, I am getting timeout limit.
Is there any way to gather all of the contractor and employee data with enabled employees with big AD without having this issue? I am getting a output but not sure if the output is realiable since I am getting error.
Thank you
Param(
[Parameter(Mandatory = $true,ValueFromPipeline = $false,HelpMessage = "Specify a output file name and path.")]
[string]
$OutputFileNamePath = $null
)
$Storage = @()
Write-Host "**********************************************************" -ForegroundColor Green
Write-Host "* On Process *" -ForegroundColor Green
Write-Host "**********************************************************" -ForegroundColor Green
$filter = @("CONTRACTOR", "EMPLOYEE")
$Storage = Get-ADUser -Filter * -Properties EmployeeNumber,Name,SamAccountName,employeeType,PasswordLastSet,LastLogonDate | Where {($_.Enabled -eq $True) -and $filter -contains $_.employeeType} | Select EmployeeNumber,Name,SamAccountName,employeeType,PasswordLastSet,LastLogonDate
$Storage | Export-Csv -Path $OutputFileNamePath".csv" -Force
Write-Host "**********************************************************" -ForegroundColor Green
Write-Host "* Done *" -ForegroundColor Green
Write-Host "**********************************************************" -ForegroundColor Green