Parity123
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"
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The code does that! $NotInA contains entries with valid EmployeeID not contained in CategoryA.
ASKER
Yes, but CategoryA does contain blanks. Can I add "" to the array to something like
$category = $CategoryA = "10","12","15","17",""
$category = $CategoryA = "10","12","15","17",""
ASKER
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.
ASKER
ok, thanks.
ASKER
One quick question, if have an array like
$CategoryA="employee","con sultant"
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.
$CategoryA="employee","con
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.
ASKER