Link to home
Start Free TrialLog in
Avatar of Parity123
Parity123Flag for United States of America

asked on

Powershell: Help with array

Hello,
I have the following script:

I need to output the users name and employeeid  - values that are not in CategoryA  and where employeeid values that are not blanks.
 Please help.

$CategoryA = "10","12","15","17"


$UserCount = $EnabledCount = $CatACount =$CatBCount = 0
foreach ($domain in Get-ADForest | select -Expand Domains) {
  Get-ADUser -Server $domain  -Filter * -Property EmployeeID | % {
     $UserCount++;
     if ($_.Enabled) { $EnabledCount++ }
     if ($CategoryA -contains $_.EmployeeID) { $CatACount++ }
       }
}
cls
write-output "Total Users:`t`t$UserCount"
write-output "Users in CategoryA:`t$CatACount"
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Parity123

ASKER

Thanks Qlemo. How do I also exclude employeeid with blank values, and only output values not in CategoryA and not a blank value.
The code does that! $NotInA contains entries with valid EmployeeID not contained in CategoryA.
Yes, but CategoryA does contain blanks. Can I add "" to the array to something like

$category = $CategoryA = "10","12","15","17",""
I meant the CategoryA does not contain blanks.
Why would you want to do that? This part | ? { $_.EmployeeID } checks if EmployeeID contains something. If not, nothing will get added to $NotInA.
ok, thanks.
One quick question, if have an array like

$CategoryA="employee","consultant"

How would I check against the array if the values entered are sometimes lowercase,uppercase, mixedcase. for employeeID. What should the following line be changed to

if ($CategoryA -contains $_.EmployeeID)

Thanks.
The default mode for string compares in PowerShell is to be case-insensitive, so you need not to care about that. -contains is the same as -icontains, and if you need case-sensitive comparision that is done with -ccontains.