Reputation: 859
function getNTAccounts {
Add-PSSnapin Quest.ActiveRoles.ADManagement
connect-QADService
$accounts = @()
Get-QADUser -CreatedAfter (Get-Date).AddDays(-3) -SerializeValue | Select-Object "samaccountname" | Foreach-Object{
$accounts += $_.samaccountname
}
Disconnect-QADService
return ,$lastaccounts
}
$tmpResult = getNTAccounts
Can you please explain to me why I got this:
{Quest.ActiveRoles.ArsPowerShellSnapIn.Data.ArsADConnection, Account1 Account2}
I'd like to get a simple array but it contains this string in the first element of the array.
Thanks in advance,
Upvotes: 0
Views: 1766
Reputation: 37730
Try these changes:
function getNTAccounts {
Add-PSSnapin Quest.ActiveRoles.ADManagement
connect-QADService | Out-Null
$accounts = @()
Get-QADUser -CreatedAfter (Get-Date).AddDays(-3) -SerializeValue | Select-Object "samaccountname" | Foreach-Object{
$accounts += $_.samaccountname
}
Disconnect-QADService
return ,$accounts
}
$tmpResult = getNTAccounts
Piping Connect-QADService to null prevents the extra entry you were getting out. Remember that everything that gets sent to the pipe will be seen as returned from the function. Also you have $lastaccounts instead of $accounts, but I suspect that this was unintentionally done when posting the question.
Upvotes: 1