TechTalkz.com Logo

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Microsoft > Microsoft Windows Powershell

Notices

Problems with a script.

Microsoft Windows Powershell


Reply
 
Thread Tools Display Modes
Old 20-06-2008, 07:48 AM   #1
William Holmes
Guest
 
Posts: n/a
Problems with a script.

Hello,

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 = "$"
$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 <<<<

  Reply With Quote
Old 20-06-2008, 05:50 PM   #2
Shay Levi
Guest
 
Posts: n/a
Re: Problems with a script.


Hi William,

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


> Hello,
>
> 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 = "$"
> $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 <<<<



  Reply With Quote
Reply

Thread Tools
Display Modes



< Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT +5.5. The time now is 09:25 PM.


vBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2009, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional