I have the following script that is exiting with an error. The error is
appended to the message. Can anyone point out the proper way to convert
these variable types?
Thanks
Bill
$strFilter = "(&(objectCategory=User)(cn=$netid))"
Write-Host "Searching Active Directory With: " $strFilter
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 1
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = "Subtree"
$colResults = $objSearcher.FindAll()
foreach ($objResult in $colResults)
{
$properties = $objResult.properties
$givenName = $properties.givenname
$sn = $properties.sn
$middleName = $properties.middlename
$uid = $properties.uid
$mail = $properties.mail
$exchangeDatabase = useDatabase
write-host $uid
enable-mailbox -Identity $uid -Database $exchangeDatabase
$newMBX = get-mailbox $uid
$additionalAddress = "$u...@mydomain.com"
$newMBX.EmailAddresses += $additionalAddress
$mbx | set-Mailbox
}
Enable-Mailbox : Cannot bind parameter 'Identity'. Cannot convert
"System.Direc
toryServices.ResultPropertyValueCollection" to
"Microsoft.Exchange.Configuratio
n.Tasks.UserIdParameter".
At C:\scripts\newusermailbox.ps1:53 char:27
+ enable-mailbox -Identity <<<< $uid -Database $exchangeDatabase
Get-Mailbox : A parameter cannot be found that matches parameter name
'System.D
irectoryServices.ResultPropertyValueCollection'.
At C:\scripts\newusermailbox.ps1:54 char:24
+ $newMBX = get-mailbox <<<< $uid
Property 'EmailAddresses' cannot be found on this object; make sure it
exists a
nd is settable.
At C:\scripts\newusermailbox.ps1:56 char:11
+ $newMBX.E <<<< mailAddresses += $cornellAddress
Set-Mailbox : Cannot bind argument to parameter 'Identity' because it is
null.
At C:\scripts\newusermailbox.ps1:57 char:21
+ $mbx | set-Mailbox <<<<
The -identity paramater value must be in one of the following formats:
* GUID
* Distinguished name (DN)
* Domain\Account
* User principal name (UPN)
If $uid is not one of the above then the command will fail.
What's the value of $uid? Doe's it resemble to any one of the above?
---
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com