none
Run PowerShell in mdt task sequence and store output in system drive, Windows 10 Autopilot

    Question

  • I've built a Windows 10 image and would like to use it with mdt -usb deployment, after the image is deployed, i would like to run a PowerShell script to gather hardware information and store the results under c:\temp\myfile, this step should run before windows boots into the user account, so basically at the OOBE step where the user selects keyboard/language. I've created the script below, stored it under deployment\scripts and added it in the mdt task sequence step under 'Install' after 'Install Operating System'-pic for details, yet i'm getting an error message

    Ps OSDisk is the default variable from mdt that I found under 'format and partition disk (BIOS and UEFI)

    Script

    $ErrorActionPreference = 'Stop'
    Param ([String]$OSDrive)
    Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force
    Install-PackageProvider -Name NuGet -Force
    Install-Script Get-WindowsAutoPilotInfo -Force
    $PCSN = (Get-CimInstance win32_bios | select SerialNumber).SerialNumber
    Try { Get-WindowsAutopilotInfo -outputfile "$($OSDrive):\temp\$(Get-Date -Format yyyymmdd)_$PCSN.csv" }
    Catch { Get-WindowsAutopilotInfo -outputfile "e:\temp\$(Get-Date -Format yyyymmdd)_$PCSN.csv" }

    MDT Task Sequence

    Error message after install os step

    Monday, July 9, 2018 3:50 AM

All replies

  • Hi,

    try to use 

    $env:SystemDrive


    To use the MDT-variables you have to import the module:

    Add this into the script

    Import-Module ZTIUtility.psm1


    Toni



    • Edited by tonibert Monday, July 9, 2018 6:03 AM
    Monday, July 9, 2018 6:02 AM
  • If you want to run scripts during the OOBE phase, you could try going down the OEM files route. Michael Niehaus wrote a guide for MDT 2012, which still works today: https://blogs.technet.microsoft.com/mniehaus/2012/08/24/copying-oem-files-and-folders-with-mdt-2012-update-1/

    Just out of curiosity: why don't you run the Get-AutopilotInfo script during the State Restore phase? https://osddeployment.dk/2018/01/21/how-to-collect-hardware-hash-to-use-in-autopilot-as-part-of-mdt-osd/


    Cheers,
    Anton

    Vacuum Breather Blog | Wing Commander Saga | Twitter

    Note: Posts are provided "AS IS" without warranty of any kind. If posts are helpful please don't forget to rate them as "Helpful" or as "Answer".

    Friday, July 13, 2018 6:53 AM