Skip to content

Instantly share code, notes, and snippets.

View brianfgonzalez's full-sized avatar

Brian Gonzalez brianfgonzalez

View GitHub Profile
@brianfgonzalez
brianfgonzalez / RecoveryWipe.ps1
Created May 7, 2019 21:04
This script is meant to run in Windows PE and requires the following PE packages: StorageWmi, Powershell, and .NET
if ((Get-Disk).NumberOfPartitions -eq 4)
{
[System.IO.DriveInfo]::GetDrives() | `
? { (($_.DriveType -eq 'Fixed') -and ($_.VolumeLabel -eq 'RECOVERY')) } | `
% {
Write-Host ('{0}util' -f $_.RootDirectory)
if (test-path ('{0}MININT' -f $_.RootDirectory)) { Remove-Item ('{0}MININT' -f $_.RootDirectory) -Force -Recurse }
if (test-path ('{0}_SMSTaskSequence' -f $_.RootDirectory)) { Remove-Item ('{0}_SMSTaskSequence' -f $_.RootDirectory) -Force -Recurse }
if (test-path ('{0}util' -f $_.RootDirectory)) { Remove-Item ('{0}util' -f $_.RootDirectory) -Force -Recurse }
}
@brianfgonzalez
brianfgonzalez / _RecoveryTool.ps1
Last active May 8, 2019 20:43
This file should reside on the <MdtDeploymentShare>\Scripts folder.
[CmdletBinding()]
Param (
[Parameter(Mandatory=$false)]
[switch]$AddRecoveryBcd,
[Parameter(Mandatory=$false)]
[string]$TaskSequence,
[Parameter(Mandatory=$false)]
[switch]$HideRecovery
)
@brianfgonzalez
brianfgonzalez / easymdt_bg.ps1
Last active April 30, 2019 15:10
Run this script as an administrator on a clean Windows 10 installation. It will install MDT (w/ADK), download and import the initial OS files, create a Capture and OEM TS, and downloads and imports an initial CAB package.
<#
.SYNOPSIS
This script performs the installation of MDT including dependencies.
# LICENSE #
PowerShell EasyMdt BG edition
Copyright (C) 2019 - Brian Gonzalez.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
.DESCRIPTION
This script sets up MDT including it's dependencies. It also performs some basic configurations.
Set-ExplorerOptions -showHiddenFilesFoldersDrives -showProtectedOSFiles -showFileExtensions
Enable-RemoteDesktop
Install-WindowsUpdate
#Script creates a Selection Profile for each folder under the MDT's "Out-of-Box Drivers" node.
$deployRoot = "D:\AiO"
Import-Module -Name "${env:ProgramFiles}\Microsoft Deployment Toolkit\bin\MicrosoftDeploymentToolkit.psd1"
New-PSDrive -Name 'SelectionProfileScript' -PSProvider MDTProvider -Root $deployRoot -Force
Get-ChildItem -Path 'SelectionProfileScript:\Out-Of-Box Drivers' -Recurse | `
Where-Object { $_.NodeType -eq 'DriverFolder' } | `
ForEach-Object {
#before: Out-Of-Box Drivers\10 x64\Panasonic\PDP_CF-53mk4_Win7x64_V2.00L11M00
#after: OoB-10x64-Panasonic-PDP_CF-53mk4_Win7x64_V2.00L11M00
$path = ($_.PSPath -replace 'MicrosoftDeploymentToolkit\\MDTProvider::SelectionProfileScript:\\', '')
Param([string]$Phase = "A")
#$VerbosePreference = "Continue"
# Give system time to start up and re-connect to vagrant shares.
#Import-Module "$env:WinDir\system32\WindowsPowerShell\v1.0\Modules\NetTCPIP\NetTCPIP.psd1"
#Import-Module "$env:WinDir\system32\WindowsPowerShell\v1.0\Modules\ServerManager\ServerManager.psd1"
$scriptPath = $myInvocation.MyCommand.Definition
function DCRoleInstall {
$SafeModeAdministratorPasswordText = "P@ssw0rd"
$SafeModeAdministratorPassword = ConvertTo-SecureString -AsPlainText $SafeModeAdministratorPasswordText -Force
' ScriptCryptor Project Options Begin
' HasVersionInfo: No
' Companyname:
' Productname:
' Filedescription:
' Copyrights:
' Trademarks:
' Originalname:
' Comments:
' Productversion: 0. 0. 0. 0
REM Install Windows ADK ( https://developer.microsoft.com/en-us/windows/hardware/windows-assessment-deployment-kit )
REM If USB3.0 drivers where not already injected into PE:
REM a. download our Win7x64 USB3.0 drivers:
REM USB 3.0 Host Controller Driver: http://pc-dl.panasonic.co.jp/dl/docs/069978?dc%5B%5D=002001&lang=005&no=20&oc=001020&p1=117&p2=1170534&score=1.0&sri=10357315&trn_org=2
REM USB 3.0 Driver: http://pc-dl.panasonic.co.jp/dl/docs/069977?dc%5B%5D=002001&lang=005&no=21&oc=001020&p1=117&p2=1170534&score=1.0&sri=10357315&trn_org=2
REM d. Extract the EXEs using 7zip.
REM e. Add the extracted folder path to the DriverPath variable.
REM f. un-REM the lines to install them.
REM In SCCM07, edit the "winpe.wim" boot file ( file name does NOT include packageid ) then run "Update Dis.." against the Boot Image in the console
DISM commands to prepare thumbdrive for applying Pre-Staged media:
* tested with ADK Win 10
copype amd64 \PEx64
dism /mount-wim /wimfile:\PEx64\media\sources\boot.wim /index:1 /mountdir:\PEx64\mount
explorer \PEx64\mount\Windows\System32
- copy/overwrite custom startnet.cmd
dism /unmount-wim /mountdir:\PEx64\mount /commit
- copy PreStagedMedia.wim to root of thumbdrive.
function Get-DirSize {
param([Parameter(Mandatory = $true, ValueFromPipeline = $true)][string]$path)
Set-Location $env:SystemDrive
$Size = (Get-ChildItem -Path $path | Measure-Object -Property Length -Sum).Sum
If ( $Size -lt 1KB ) { $formattedsize = "$("{0:N2}" -f $Size) B" }
ElseIf ( $Size -lt 1MB ) { $formattedsize = "$("{0:N2}" -f ($Size / 1KB)) KB" }
ElseIf ( $Size -lt 1GB ) { $formattedsize = "$("{0:N2}" -f ($Size / 1MB)) MB" }
ElseIf ( $Size -lt 1TB ) { $formattedsize = "$("{0:N2}" -f ($Size / 1GB)) GB" }
$FileCount = (Get-ChildItem -Path $path | Measure-Object).Count
$Name = (Get-Item -Path $path).Name