My MDT PowerShell Template

By | March 17, 2014
Share

I’ve recently come to really appreciate PowerShell as the most versatile and powerful language available natively in any/all Windows OS.

i.e. 2 lines of code to ensure laptop battery is plugged in and prompt the user.
If ((Get-WmiObject -Query “SELECT * From Win32_Battery”).BatteryStatus -ne 2)
{ Write-Host “Please plug in your laptop” }

An equivalent VBScript would easily run around 30 lines of code.

Running PowerShell via the Task Sequence has been around for a bit, which is simple enough.

This however, does NOT include any logging support and requires that your scripts exist in the “Scripts” Directory. Which in my opinion almost renders the feature useless.

Here is my Template, which can be used within an application:

GitHub Link: https://github.com/brianfgonzalez/Scripts/blob/master/Z-MyMDTTemplate.ps1

 

/BG

4 thoughts on “My MDT PowerShell Template

  1. David Bloom

    Hi Brian,

    I like this script, but I am having some issues trying to test it out. Admitiddly, I am testing this outside of an MDT task sequence, so the script cannot attach to the TS Environment.

    I am using this script to install an application, and it does that just fine. However, I get errors when trying to write to the log files, because they don’t exist. I can’t see anywhere in the script where it creates these log files if they don’t exist. All I see are commands to update log files, not create them.

    Am I missing something? Thank you!

    Reply
    1. Brian Gonzalez Post author

      David,

      Im happy you found the post. I actually ended up creating a separate script to act like the ZTIUtility.wsf script, but via Powershell.

      Here is the script, must be placed in the Scripts\ Directory.
      https://github.com/brianfgonzalez/Scripts/blob/master/ZTIUtility.ps1

      And here is an example Powershell script using the functions in the other script.
      https://github.com/brianfgonzalez/Scripts/blob/master/ZTIUtility.ps1

      it seems to work great in my testing.

      /BrianG

      Reply
  2. David Bloom

    Hi Brian,

    I keep finding myself back at this page as I need to write my own PowerShell scripts for MDT. I noticed in your reply above that the example you linked to is the same URL as the ZTIUtility.ps1 link.

    Could you please post to a working example that uses the ZTIUtility script? That would be most helpful, at least to me. 🙂

    Thanks.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*