Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Powershell - Setting the $AdminSessionADSettings.ViewEntireForest=$true parameter at startup

Posted on 2010-08-13
4
Medium Priority
?
3,119 Views
Last Modified: 2012-05-10
$AdminSessionADSettings.ViewEntireForest=$true

I added the above line to my powershell profile ($profile) so that I don't have to set the scope for AD everytime I use the shell.  When I launch the shell, I get the following error:

Property 'ViewEntireForest' cannot be found on this object; make sure it exists
 and is settable.
At C:\Documents and Settings\Allen.Jones\My Documents\WindowsPowerShell\Micros
oft.PowerShell_profile.ps1:1 char:25
+ $AdminSessionADSettings.V <<<< iewEntireForest=$true

However, I can then manually type in the command after the shell is loaded.

1. Is there a way to accomplish this?
2. Why is it that the shell will accept the command manually but not at startup?

0
Comment
Question by:LN41
  • 2
4 Comments
 
LVL 8

Expert Comment

by:RyanAndres
ID: 33434563

$($AdminSessionADSettings.ViewEntireForest) = $true

Open in new window

0
 
LVL 1

Author Comment

by:LN41
ID: 33434669
I'm running XP pro, powershell v2, do you get the same result?

Invalid assignment expression. The left hand side of an assignment operator nee
ds to be something that can be assigned to like a variable or a property.
At C:\Documents and Settings\Allen.Jones\My Documents\WindowsPowerShell\Micros
oft.PowerShell_profile.ps1:1 char:46
+ $($AdminSessionADSettings.ViewEntireForest) =  <<<< $true
0
 
LVL 13

Expert Comment

by:soostibi
ID: 33438090
Unfortunately the profile is run before the $adminsessionadsettins variable is created. You should change the parameters of the shortcut of the EMS. The 'target' of the original one:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1" -noexit -command ". 'C:\Program Files\Microsoft\Exchange Server\bin\Exchange.ps1'"

You should create a scriptfile similar to this yourscript.ps1:
'C:\Program Files\Microsoft\Exchange Server\bin\Exchange.ps1'
$AdminSessionADSettings.ViewEntireForest=$true

And change the target of the shortcut of the EMS to:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1" -noexit -command pathofyourscript\yourscript.ps1

(If your path contains a space then:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1" -noexit -command ". 'pathofyourscript\yourscript.ps1'"
0
 
LVL 13

Accepted Solution

by:
soostibi earned 1600 total points
ID: 33438106
Sorry, one period sign is missing from here:

You should create a scriptfile similar to this yourscript.ps1:
. 'C:\Program Files\Microsoft\Exchange Server\bin\Exchange.ps1'
$AdminSessionADSettings.ViewEntireForest=$true
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Loops Section Overview

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question