troubleshooting Question

Powershell: Code modification assistance

Avatar of Parity123
Parity123Flag for United States of America asked on
12 Comments1 Solution40 ViewsLast Modified:

I have the following code, and I also want to filter out "blanks/not set" values. Can you please assist.
$NotInA  (must not contain any users with blank values for employeeid) and (anything that does not match $CategoryA)
If have 3 users with values 10, 26,blank. $NotInA must contain only the user with the value 26.

$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 | % {
     if ($_.Enabled) { $EnabledCount++ }
     if ($CategoryA -contains $_.EmployeeID) {
     } else {
       $NotInA += $_ | ? { $_.EmployeeID } | Select Name, EmployeeID
write-output "Total Users:`t`t$UserCount"
write-output "Users in CategoryA:`t$CatACount"
write-output "Users not in CategoryA:"$NotInA | ft -a
"Batchelor", Developer and EE Topic Advisor
Join our community to see this answer!
Unlock 1 Answer and 12 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros