Please see the code snippet below.
Workflow getAD-Details {
$objForest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
$DCServer = $objForest.NamingRoleOwner.Name
$DCServer += ':3268'
$search_list = @('Account1','Account2','Account3','Account4')
foreach -parallel -throttlelimit 4 ($account in $search_list) {
InLineScript {
$SearchResults = @()
$AccountNotFound = @()
$account_name = $using:account
$ErrorActionPreference = 'Continue'
try {
$SearchResults += Get-ADUser -ErrorAction Stop -identity $account_name -properties * -Server $using:DCServer |
Select-Object SamAccountName, @{n="Domain"; e={$_.userPrincipalName.Split('@.')[1]}}, Created,createTimeStamp
}
Catch {
Write-Error "The account $account_name does not exist"
$AccountNotFound += [PSCustomObject]@{
SearchDate = Get-Date
Account = $account_name
}
}
}
}
}
getAD-Details
Error details.
Receive-Job : Win32 internal error "Access is denied" 0x5 occurred while reading the console output buffer. Contact Microsoft Customer Support Services.