techdrive
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'
@(
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
+ 'contoso.local\toys'
Did you load the AD module?
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
}
Hope you are running the code from EMS.
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: (:) [], ManagementObjectNotFoundEx ception
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: (:) [], ManagementObjectNotFoundEx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
awesome thanks