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"
Parity123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
$CategoryA = "10","12","15","17"
$NotInA = @()

$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++
     } else {
       $NotInA += $_ | ? { $_.EmployeeID } | Select Name, EmployeeID
     }
  }
}
cls
write-output "Total Users:`t`t$UserCount"
write-output "Users in CategoryA:`t$CatACount"
write-output "Users not in CategoryA:"
$NotInA | ft -a

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Parity123Author Commented:
Thanks Qlemo. How do I also exclude employeeid with blank values, and only output values not in CategoryA and not a blank value.
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
The code does that! $NotInA contains entries with valid EmployeeID not contained in CategoryA.
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Parity123Author Commented:
Yes, but CategoryA does contain blanks. Can I add "" to the array to something like

$category = $CategoryA = "10","12","15","17",""
Parity123Author Commented:
I meant the CategoryA does not contain blanks.
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Why would you want to do that? This part | ? { $_.EmployeeID } checks if EmployeeID contains something. If not, nothing will get added to $NotInA.
Parity123Author Commented:
ok, thanks.
Parity123Author Commented:
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.
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.