need assistance with this powershell script

siber1
siber1 used Ask the Experts™
on
hello, I'm trying to run the following powershell script [using the quest commandlets] and receiving the following error:
the term 'displayname' is not recognized as the name of a cmdlet.

any assistance would be much appreciated.

S.
# Move mailboxes by security group 
Write-Host "You have choosen to migrate mailboxes by specifying an AD security group" 
$ADSecGroupName = Read-Host "Enter AD security group that you want to migrate" 
Get-QADUser -MemberOf $ADSecGroupName | ft 
Write-Host "The above list of users will get migrated!!" 
Write-Host " " 
Get-MailboxDatabase | ft 
$TargetDatabaseName = Read-Host "Type the database that you want to migrate user(s) to" 
#  
#Loop through each mailbox 
foreach ($mailbox in (Get-QADUser -MemberOf $ADSecGroupName)) 
{$displayname = $mailbox.Displayname 
New-MoveRequest -Identity $displayname -TargetDatabase $TargetDatabaseName -BadItemLimit 50}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Chris DentPowerShell Developer
Top Expert 2010

Commented:
Hmm I can't reproduce that error using the code you've posted. Is that exactly as you have it? No extra line-breaks? Nothing missed?

Chris
Chris DentPowerShell Developer
Top Expert 2010

Commented:
Oh yes, the error message will have more information than that, would you be able to share it?

Cheers!

Chris

Author

Commented:
sure Chris. here is the exact error that is generated when i run it
The term 'displayname' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\admin\Desktop\test.ps1:14 char:13
+ {displayname <<<<  = $mailbox.Displayname
    + CategoryInfo          : ObjectNotFound: (displayname:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

A positional parameter cannot be found that accepts argument 'Identity'.
    + CategoryInfo          : InvalidArgument: (:) [New-MoveRequest], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,New-MoveRequest

The term 'displayname' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\admin\Desktop\test.ps1:14 char:13
+ {displayname <<<<  = $mailbox.Displayname
    + CategoryInfo          : ObjectNotFound: (displayname:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

A positional parameter cannot be found that accepts argument 'Identity'.
    + CategoryInfo          : InvalidArgument: (:) [New-MoveRequest], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,New-MoveRequest

The term 'displayname' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\admin\Desktop\test.ps1:14 char:13
+ {displayname <<<<  = $mailbox.Displayname
    + CategoryInfo          : ObjectNotFound: (displayname:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

A positional parameter cannot be found that accepts argument 'Identity'.
    + CategoryInfo          : InvalidArgument: (:) [New-MoveRequest], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,New-MoveRequest

Open in new window

PowerShell Developer
Top Expert 2010
Commented:
Ahh there it is :)

In your snippet you have a $ here:

{$displayname = $mailbox.Displayname

In your script, test.ps1, the first $ is missing. That changes $displayname from a variable to a command and is where it's getting hung up.

Cheers,

Chris

Author

Commented:
ahh.. yes thats it!
works perfect now.

many thanks Chris!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial