none
Frontend PowerShell RRS feed

  • Question

  • I have created a frontend powershell script to set some variables.

    How do i run this script from from winpe before starting the build?

    Thank you

    Wednesday, May 3, 2017 4:31 PM

All replies

  • First, make certain you are including PowerShell in your WinPE image (Under the Windows PE tab, click on the Features tab and check the PowerShell box.)

    Here is one approach; Open lietouchpe_xnn.wim file (using DISM or ImageX).

    Next, copy your script into the \Deploy\Scripts folder.

    Now edit the unattend.xml file at the top level of litetouchpe_xnn.wim.  You will need to make the Litetouch entry number 2 and add an entry for your script as number 1.  it should look something like this when done (I may have the powershell command line incorrect but you get the idea):

    <?xml version="1.0" encoding="utf-8"?>
    <unattend xmlns="urn:schemas-microsoft-com:unattend">
        <settings pass="windowsPE">
            <component name="Microsoft-Windows-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State">
                <Display>
                    <ColorDepth>32</ColorDepth>
                    <HorizontalResolution>1024</HorizontalResolution>
                    <RefreshRate>60</RefreshRate>
                    <VerticalResolution>768</VerticalResolution>
                </Display>
                <RunSynchronous>
                    <RunSynchronousCommand wcm:action="add">
                        <Description>Lite Touch PE</Description>
                        <Order>1</Order>
                        <Path>powershell -file c:\yourscritp.ps1</Path>
                    </RunSynchronousCommand>
                    <RunSynchronousCommand wcm:action="add">
                        <Description>Lite Touch PE</Description>
                        <Order>2</Order>
                        <Path>wscript.exe X:\Deploy\Scripts\LiteTouch.wsf</Path>
                    </RunSynchronousCommand>
                </RunSynchronous>
            </component>
        </settings>
    </unattend>

    Finally, save the wim file.

    Another approach might be to only have your script entry in the unattend.xml file and have your script launch litetouch.wsf as the last thing it does.

    Wednesday, May 3, 2017 5:40 PM
  • Thanks for the help.

    So i mounted the wim file from my deploymentshare. Edited XML file.

    <?xml version="1.0" encoding="utf-8"?>
    <unattend xmlns="urn:schemas-microsoft-com:unattend">
        <settings pass="windowsPE">
            <component name="Microsoft-Windows-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State">
                <Display>
                    <ColorDepth>32</ColorDepth>
                    <HorizontalResolution>1024</HorizontalResolution>
                    <RefreshRate>60</RefreshRate>
                    <VerticalResolution>768</VerticalResolution>
                </Display>
                <RunSynchronous>
                    <RunSynchronousCommand wcm:action="add">
                        <Description>Lite Touch PE</Description>
                        <Order>1</Order>
                        <Path>powershell.exe X:\Deploy\Scripts\ComboBox-XML-TS.psf</Path>
                    </RunSynchronousCommand>
    <RunSynchronousCommand wcm:action="add">
                        <Description>Lite Touch PE</Description>
                        <Order>2</Order>
                        <Path>wscript.exe X:\Deploy\Scripts\LiteTouch.wsf</Path>
                    </RunSynchronousCommand>
                </RunSynchronous>
            </component>
        </settings>
    </unattend>

    Added script to a scripts folder.

    Committed and Unmounted the wim file.

    Now i need an iso for testing, how do i create an iso based on the new wim?

    Thank you

    Friday, May 5, 2017 2:41 PM
  • Lets say i made changes to a wim file. unattend.xml and copy file in a scripts folder.

    Now i made some changes to a customsettings.ini and need to undate deploymentshare.

    Will i over write my wim file?

    Also getting an error when trying to run a script: no such interface supported.

    • Edited by Ogeccut Friday, May 5, 2017 8:06 PM
    Friday, May 5, 2017 7:47 PM
  • Yes, your wim file be over-written.

    When you update the deployment share MDT builds you an ISO. If you want the changes to your Unattend.xml file persisted you need to modify the templates in \Program Files\Microsoft Deployment Toolkit\Templates (or something like that, don't remember the exact path).

    There are Unattend template files for x86 and x64 versions of WinPE. Make sure you make a backup of the originals, and then modify the template. Then when you generate media, those new templates will be used.

    As for getting the PowerShell scripts onto the media, you don't have to crack open the .wim file. Just include those files on the WinPE settings tab in the MDT Workbench. I have a folder called "Extras" that include everything I want in my WinPE boot media, and it gets copied into the .wim file when I update the deployment share.

    Friday, May 5, 2017 8:07 PM
  • David, 

    where does it copy files from extra folder? to the scripts directory? or there is a extra folder on the root?

    Is there another way to execute PS in PE besides of unattend.xml?

    Friday, May 5, 2017 9:22 PM
  • I made a folder called Extras in my Deployment share, but I'm pretty sure it can be anywhere. You just specify the path on the Deployment Share properties under the WinPE tab under 'Extra Directory to Add.'

    Image result for mdt deployment share

    Friday, May 5, 2017 10:44 PM
  • Also, it looks like you're trying to execute a .PSF file. Did that come from PowerShell studio? You need to export the file and run a .PS1 file.
    Friday, May 5, 2017 10:45 PM
  • I exported the file to an exe. Still having issues running an exe from winPE. 

    But i am able to browse to a deploymentshare and test exe. 

    For some reason i do not see TS variable change in the logs.

    Here is the code i use:

    if ($cmbSiteCode.Text -ne $null -and $cmbDomain.Text -ne $null)
    {
    $OSDComputerName = $cmbSiteCode.Text + $Script:SN
    $OSDJoinDomain = $cmbDomain.Text
    #Create TS Env COM object
    $TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment

    #Changing OSDComputerName AND Assigning New OSDDomainName
    $TSEnv.Value("OSDComputerName") = "$($OSDComputerName)"
    $TSEnv.Value("OSDDomainName") = "$($OSDJoinDomain)"
    Write-host "TS-OSDComputerName After Change" $TSEnv.Value("OSDComputerName")
    Write-host "TS-OSDJoinDomain After Change" $TSEnv.Value("$OSDJoinDomain")
    }

    Sunday, May 7, 2017 11:46 PM