mirror of
https://github.com/rbalsleyMSFT/FFU.git
synced 2026-06-14 02:09:35 -06:00
@@ -1,25 +1,22 @@
|
|||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory = $True, Position = 0)]
|
[Parameter(Mandatory = $True, Position = 0)]
|
||||||
$DeployISOPath,
|
[io.fileinfo] $DeployISOPath,
|
||||||
[Switch]$DisableAutoPlay
|
[Switch]$DisableAutoPlay
|
||||||
)
|
)
|
||||||
$Host.UI.RawUI.WindowTitle = 'USB Imaging Tool Creator'
|
|
||||||
|
|
||||||
if($DeployISOPath){
|
|
||||||
$DevelopmentPath = $DeployISOPath | Split-Path
|
|
||||||
function WriteLog($LogText) {
|
function WriteLog($LogText) {
|
||||||
$LogFileName = '\Script.log'
|
$LogFileName = '\Script.log'
|
||||||
$LogFile = $DevelopmentPath + $LogFilename
|
$LogFile = $DevelopmentPath + $LogFilename
|
||||||
Add-Content -path $LogFile -value "$((Get-Date).ToString()) $LogText" -Force -ErrorAction SilentlyContinue
|
Add-Content -path $LogFile -value "$((Get-Date).ToString()) $LogText" -Force -ErrorAction SilentlyContinue
|
||||||
Write-Verbose $LogText
|
Write-Verbose $LogText
|
||||||
}
|
}
|
||||||
Function Get-USBDrive {
|
|
||||||
|
function Get-USBDrive {
|
||||||
$USBDrives = (Get-WmiObject -Class Win32_DiskDrive -Filter "MediaType='Removable Media'")
|
$USBDrives = (Get-WmiObject -Class Win32_DiskDrive -Filter "MediaType='Removable Media'")
|
||||||
If ($USBDrives -and ($null -eq $USBDrives.count)) {
|
If ($USBDrives -and ($null -eq $USBDrives.count)) {
|
||||||
$USBDrivesCount = 1
|
$USBDrivesCount = 1
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$USBDrivesCount = $USBDrives.Count
|
$USBDrivesCount = $USBDrives.Count
|
||||||
}
|
}
|
||||||
WriteLog "Found $USBDrivesCount USB drives"
|
WriteLog "Found $USBDrivesCount USB drives"
|
||||||
@@ -31,7 +28,8 @@ Function Get-USBDrive {
|
|||||||
}
|
}
|
||||||
return $USBDrives, $USBDrivesCount
|
return $USBDrives, $USBDrivesCount
|
||||||
}
|
}
|
||||||
Function Build-DeploymentUSB{
|
|
||||||
|
function Build-DeploymentUSB {
|
||||||
param(
|
param(
|
||||||
[Array]$Drives
|
[Array]$Drives
|
||||||
)
|
)
|
||||||
@@ -138,7 +136,7 @@ Dismount-DiskImage -ImagePath $DeployISOPath | Out-Null
|
|||||||
Writelog "Drive creation jobs completed..."
|
Writelog "Drive creation jobs completed..."
|
||||||
}
|
}
|
||||||
|
|
||||||
Function New-DeploymentUSB {
|
function New-DeploymentUSB {
|
||||||
param(
|
param(
|
||||||
[Array]$Drives,
|
[Array]$Drives,
|
||||||
[int]$Count,
|
[int]$Count,
|
||||||
@@ -169,8 +167,10 @@ Function New-DeploymentUSB {
|
|||||||
$DriveSelected = ($DriveSelected -as [int]) - 1
|
$DriveSelected = ($DriveSelected -as [int]) - 1
|
||||||
if ($Last) {
|
if ($Last) {
|
||||||
writelog "All drives selected"
|
writelog "All drives selected"
|
||||||
}else{
|
}
|
||||||
writelog "Drive $DriveSelected selected"}
|
else {
|
||||||
|
writelog "Drive $DriveSelected selected"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
Write-Host 'Input was not in correct format. Please enter a valid FFU number'
|
Write-Host 'Input was not in correct format. Please enter a valid FFU number'
|
||||||
@@ -189,7 +189,7 @@ Function New-DeploymentUSB {
|
|||||||
WriteLog "Closing all Diskpart windows to prevent drive lock errors"
|
WriteLog "Closing all Diskpart windows to prevent drive lock errors"
|
||||||
Stop-Process -Name diskpart -ErrorAction SilentlyContinue
|
Stop-Process -Name diskpart -ErrorAction SilentlyContinue
|
||||||
$Selection = $Drivelist[$DriveSelected].Number
|
$Selection = $Drivelist[$DriveSelected].Number
|
||||||
$totalSteps = 5
|
|
||||||
if ($Selection -eq $last) {
|
if ($Selection -eq $last) {
|
||||||
Read-Host -Prompt "ALL DRIVES SELECTED! WILL ERASE ALL CURRENTLY CONNECTED USB DRIVES!! Press ENTER to continue"
|
Read-Host -Prompt "ALL DRIVES SELECTED! WILL ERASE ALL CURRENTLY CONNECTED USB DRIVES!! Press ENTER to continue"
|
||||||
Build-DeploymentUSB -Drives $Drives
|
Build-DeploymentUSB -Drives $Drives
|
||||||
@@ -204,20 +204,34 @@ Function New-DeploymentUSB {
|
|||||||
}
|
}
|
||||||
Writelog "Completed!"
|
Writelog "Completed!"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$Host.UI.RawUI.WindowTitle = 'USB Imaging Tool Creator'
|
||||||
|
|
||||||
|
# Check if path is relative
|
||||||
|
if (-not [System.IO.Path]::IsPathRooted($DeployISOPath)) {
|
||||||
|
# Path is relative, Build full path
|
||||||
|
[io.fileinfo] $DeployISOPath = (Resolve-Path $DeployISOPath).Path
|
||||||
|
Write-Verbose "Path to ISO was relative. Attempting to resolve at: $($DeployISOPath.FullName)"
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($DeployISOPath.Exists) {
|
||||||
|
$DevelopmentPath = $DeployISOPath.Directory.FullName
|
||||||
|
|
||||||
#Get USB Drive and create log file
|
#Get USB Drive and create log file
|
||||||
if (Test-Path "$DevelopmentPath\Script.log") {
|
if (Test-Path "$DevelopmentPath\Script.log") {
|
||||||
Remove-Item -Path "$DevelopmentPath\Script.log" -Force -Confirm:$false
|
Remove-Item -Path "$DevelopmentPath\Script.log" -Force -Confirm:$false
|
||||||
New-item -Path $DevelopmentPath -Name 'Script.log' -ItemType "file" -Force | Out-Null
|
New-item -Path $DevelopmentPath -Name 'Script.log' -ItemType "file" -Force | Out-Null
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteLog 'Begin Logging'
|
WriteLog 'Begin Logging'
|
||||||
WriteLog 'Getting USB drive information and usb drive count'
|
WriteLog 'Getting USB drive information and usb drive count'
|
||||||
$USBDrives,$USBDrivesCount = Get-USBDrive
|
|
||||||
New-DeploymentUSB -Drives $USBDrives -Count $USBDrivesCount
|
|
||||||
read-host -Prompt "USB drive creation complete. Press ENTER to exit"
|
|
||||||
|
|
||||||
|
$USBDrives, $USBDrivesCount = Get-USBDrive
|
||||||
|
|
||||||
|
New-DeploymentUSB -Drives $USBDrives -Count $USBDrivesCount
|
||||||
|
|
||||||
|
Read-Host -Prompt "USB drive creation complete. Press ENTER to exit"
|
||||||
Exit
|
Exit
|
||||||
} else {
|
} else {
|
||||||
Write-Host "No .ISO file selected..."
|
Write-Error "Unable to locate ISO file at: $($DeployISOPath.FullName)"
|
||||||
read-host "Press ENTER to Exit..."
|
|
||||||
Exit
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user