locked
running Powershell Script in MDT 2013 TS RRS feed

  • Question

  • hi all,

    i have simple powershell script

    #=================

    Import-Module ZTIUtility
    Import-Module ActiveDirectory

    $targetOU =$TSEnv:MachineObjectOU
    $computername = $TSEnv:OSDCOMPUTERNAME

    get-adcomputer $computername | Move-ADObject -TargetPath $targetOU

    #=================

    I have copied moduled to Tools\Modules\ActiveDirectory and Tools\Modules\ZTIUtility. getting following error

    i am running this script in Postinstall.

    Script works in windows when run through custom TS. But error out running under reimagin TS.

    ANY HELP Thanks in advance


    orion

    Wednesday, March 26, 2014 9:31 PM

All replies

  • First question: Did you add the .net and powershell frameworks to the WinPE image? Specifically, which ones?

    That's *not* to say that the Active Directory Cmdlets will actually be available in WinPE, that's a different question.

    Have you tried creating a web service to perform the task?


    Keith Garner - keithga.wordpress.com

    • Marked as answer by Keith GarnerMVP Wednesday, March 26, 2014 11:08 PM
    • Unmarked as answer by Ultra9.99 Thursday, March 27, 2014 3:11 AM
    Wednesday, March 26, 2014 11:08 PM
  • thanks Keith for your reply

    Yes i have added .net and PS in boot image.

    web service is not an option, atleast for now.

    this script works fine in custom TS.

    But not in TS


    orion

    Thursday, March 27, 2014 3:05 AM

  • orion

    Thursday, March 27, 2014 3:05 AM
  • My guess would be that option two is loading with a different profile than option one and option two does not have AD cmdlets available.  I personally do not run any of my powershell scripts through the Run PowerShell Script option.  I prefer the option of running any scripts of significance as an application and calling it with the command line powershell.exe -executionpolicy unrestricted .\myscript.ps1 -  always has been more reliable for me. 

    Here's a great example of that process -

    http://www.deploymentresearch.com/Research/tabid/62/EntryId/97/PowerShell-wrapper-for-MDT-2012-Update-1-and-MDT-2013-Preview.aspx

    That way I can organize my scripts inside of applications and update them with some sort of organizational logic.  Hope this helps.

    Thursday, March 27, 2014 2:28 PM
  • hello , can you show me location for the PS1 file you save .
    Wednesday, May 10, 2017 8:48 AM
  • Save it in the Scripts folder

    If this post is helpful please vote it as Helpful or click Mark for answer.

    Wednesday, May 10, 2017 3:08 PM
  • Hi,

    Afaik, using AD powershell module can only be done with trickery as it originaly comes with RSAT.

    I'ts "of course" unsupported but works with modification in your PE image. What is happening to your script is that you probably missed some files. check this post http://mickitblog.blogspot.fr/2016/04/import-active-directory-module-into.html for a full check. If you've already done that and still have problem, you could try to add the path of your AD Module to the  enviroment variable PsModule before your import module command:

    $env:PSModulePath = $env:PSModulePath + ";C:\MyADModulePath\"


    • Edited by mrdiagg Thursday, June 8, 2017 10:29 PM
    Thursday, June 8, 2017 10:28 PM