• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Invoking a different version of powershell from a powershell script.

imagoon

Diamond Member
I am running Server 2012R2 which is running Powershell 4 natively including all the stock modules like ActiveDirectory etc. I also have Exchange 2010 management tools installed and they are working correctly. The issue I am running in to is I need to either a) run at Powershell 4 for AD commands and invoke commands in Exchange shell (Version 3) or run from version 3 and invoke AD commands in to a Powershell 4 instance.

AD won't load in the Exchange shell (3) nor will Exchange load in to the AD (4). Invoke-Command doesn't seem to have a version identifier. I think I could get this to work by having the AD shell (4) basically build a .ps1 on the fly then call powershell with -version 3 (or vis versa) but this seems like a odd convoluted back door option.

To summerize what I am working on: I am getting information from AD about last logons etc and then trying to clean up and set archive settings on Exchange. All of this works fine if I run 2 shells and execute the pieces, exporting the results from one shell to a .csv that the other one picks up and works with. I am just trying to put it all together in one now and not leave random .csv files around to work on.

Am I just missing something here?
 
I'm not a PowerShell user but can you treat the other shell the same way you would run a random EXE file inside the shell? (Then pipe the results?)

http://social.technet.microsoft.com/wiki/contents/articles/7703.powershell-running-executables.aspx

So that gave me an idea, looks like powershell.exe itself has -outputformat XML as an option. I ran this from the Exchange shell:

Code:
[PS] C:\Users\user\Desktop>$things=(powershell -command {get-aduser administrator} -outputformat XML)
[PS] C:\Users\user\Desktop>$things


DistinguishedName : CN=Administrator,OU=Managed Accounts,DC=mydc
Enabled           : False
GivenName         :
Name              : Administrator
ObjectClass       : user
ObjectGUID        : ceaf3454-b33a-411b-bd85-dae4afa8c273
SamAccountName    : Administrator
SID               : S-1-5-21-1715567821-1417001333-839522115-500
Surname           :
UserPrincipalName : Administrator@mydomain.com

Object in a variable I can work with!

Thanks!
 
Sometimes I would use powershell to create secondary scripts rather than running them in the same thread... Basically, I would use New-Item to create a timestamped outfile...then schedule it to run a reasonable time after my initial script to execute code from the Outfiles. That allowed me to switch between versions.

I've had mixed results with a few commandlets....Invoke-Expression and even Get-ChildItem (too many results in a directory causes it to cease) have caused me problems in the past
 
Back
Top