powershell array will not run

I am trying to run this over each OU but for some reason this is failing and I have attached the error below. Please help as I am not an expert in powershell.


@(
contoso.local\toys
contoso.local\radios
contoso.local\beer
contoso.local\computers
contoso.local\users
) | % {

get-mailbox -organizationalunit $_  | select displayname, alias, identity

}



Error I receive below.


 The module 'contoso.local' could not be loaded. For more information, run 'Import-Module
'contoso.local' .
At C:\temp\nameofscript.ps1:5 char:1
+ 'contoso.local\toys'
techdriveAsked:
Who is Participating?
 
SubsunCommented:
use forward slash

"contoso.local/toys"
0
 
Zephyr ICTCloud ArchitectCommented:
0
 
SubsunCommented:
Use quotes to define strings, Also you need to use forward slash between OU names.. Try..
@(
"contoso.local/toys"
"contoso.local/radios"
"contoso.local/beer"
"contoso.local/computers"
"contoso.local/users"
 ) | % {

 get-mailbox -organizationalunit $_  | select displayname, alias, identity

 }

Open in new window

Hope you are running the code from EMS.
0
 
techdriveAuthor Commented:
thanks but now I am getting the followng error


Couldn't find organizational unit "contoso.local\toys". Make sure you have typed the name correctly.
At line:6 char:1
+ get-mailbox -organizationalunit $_  | select displayname, alias, identity
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], ManagementObjectNotFoundException
0
 
techdriveAuthor Commented:
awesome thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.