Hi,
I am working on a script that is supposed to modify the value of an AD account attribute should it be blank.
The script is suppose to check if there is a value already present which would be either "staff" or "visitor". And if it isn't then it will execute the next block of the script where you will have to specify whether the user is a member of staff or a visitor. The code is below:
$username = Read-Host "Please enter username"
$employeeType = Get-ADUser $username -Properties * | fl employeeType
if (($employeeType -contains 'Staff') -or ($employeeType -contains 'Visitor'))
{Write-Host "Employee attribute value exists"}
else {
$visitorStaff = Read-Host "The EmployeeType attribute value does not exist. Please state wheather they are a Visitor or Staff"
$replaceAttribute = New-Object hashtable
$replaceAttribute.Add("employeeType", $visitorStaff)
Set-ADUser $username -Replace $replaceAttribute
}The problem here is that when a valid employeeType value is set the script does not seem to recognise it and flows to the next block of the script to set the attribute value.
So when I do this from the Powershell Window:
echo $employeeType
I get:
employeeType : Staff
This in my mind seems correct. However, if do the following:
$employeeType -contains "Staff"
I get:
False
So I think I kind of understand why it never really sees a valid value and skips to the next else statement. But when I do this:
$employeeType.GetType()I get a value where the BaseType is System.Array. Any ideas or suggestions as to how I can get this if statement to work will be much appreciated. I am using Windows 7 with Powershell v3.
Please let me know if you require further information.
Regards - MobileIAm