lundi 28 mars 2016

If statements - Powershell

    function contactOU

{ #This selects which OU to place the contact in. write-host write-host '~Contact type~' write-host '1. Admin' write-host '2. Assistant Owner' write-host '3. Owner Partner' write-host '4. Owner' write-host '5. Team Leader' write-host $contacttype = (Read-host -prompt 'Which type of contact') if($contacttype = "1") {$contactOU = "OU=Admins,OU=Marketing Companies,OU=Contacts,DC=company,DC=com,DC=au"} if($contacttype = "2"){$contactOU = "OU=Assistant Owners,OU=Marketing Companies,OU=Contacts,DC=company,DC=com,DC=au"} if($contacttype = "3"){$contactOU = "OU=Owner Partner,OU=Marketing Companies,OU=Contacts,DC=company,DC=com,DC=au"} if($contacttype = "4"){$contactOU = "OU=Owners,OU=Marketing Companies,OU=Contacts,DC=company,DC=com,DC=au"} if($contacttype = "5"){$contactOU = "OU=Team Leaders,OU=Marketing Companies,OU=Contacts,DC=company,DC=com,DC=au"} else{write-host 'Please select a valid number',contactOU}

#For testing
write-host $contactOU

#May put this in an individual function?
New-ADObject -name $contactname -type Contact -Path $contactOU -OtherAttributes @{displayName=$contactname;mail=$emailaddress;targetAddress=$targetaddress}

}

The issue I'm having is, regardless of what number I select the IF statments choose the last option? (Team Leader OU). Does anyone know what is wrong with my IF statements?

Cheers, Luke

Aucun commentaire:

Enregistrer un commentaire