2
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}
}
我遇到的問題是,無論我選擇哪個數字IF語句選擇最後一個選項? (組長OU)。有人知道我的IF語句有什麼問題嗎?如果語句 - Powershell
其實,你的$ contacttype設置爲1比2,3,4,5中的if語句,因爲'='意味着分配一個值,而不是進行比較。 – Martin