Link to home
Start Free TrialLog in
Avatar of techdrive
techdriveFlag for United States of America

asked on

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'
Avatar of Zephyr ICT
Zephyr ICT
Flag of Belgium image

Avatar of SubSun
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.
Avatar of techdrive

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
awesome thanks