mirror of
https://github.com/rbalsleyMSFT/FFU.git
synced 2026-06-14 02:09:35 -06:00
Update USBImagingToolCreator.ps1
added support for relative paths. formatted script and removed functions from inside if statement.
This commit is contained in:
@@ -1,20 +1,18 @@
|
|||||||
[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
|
||||||
@@ -31,7 +29,8 @@ Function Get-USBDrive {
|
|||||||
}
|
}
|
||||||
return $USBDrives, $USBDrivesCount
|
return $USBDrives, $USBDrivesCount
|
||||||
}
|
}
|
||||||
Function Build-DeploymentUSB{
|
|
||||||
|
function Build-DeploymentUSB {
|
||||||
param(
|
param(
|
||||||
[Array]$Drives
|
[Array]$Drives
|
||||||
)
|
)
|
||||||
@@ -65,7 +64,8 @@ Function Build-DeploymentUSB{
|
|||||||
if ($DrivesCount -gt 1) {
|
if ($DrivesCount -gt 1) {
|
||||||
writelog "Get file system information for all drives"
|
writelog "Get file system information for all drives"
|
||||||
$Partitions = Get-Partition | Get-Volume
|
$Partitions = Get-Partition | Get-Volume
|
||||||
}else{
|
}
|
||||||
|
else {
|
||||||
writelog "Get file system information for drive number $DiskNumber"
|
writelog "Get file system information for drive number $DiskNumber"
|
||||||
$Partitions = Get-Partition -DiskNumber $DriveNumber | Get-Volume
|
$Partitions = Get-Partition -DiskNumber $DriveNumber | Get-Volume
|
||||||
}
|
}
|
||||||
@@ -129,7 +129,8 @@ if(!($Drivers)){
|
|||||||
}
|
}
|
||||||
if ($DrivesCount -gt 1) {
|
if ($DrivesCount -gt 1) {
|
||||||
Writelog "Building $DrivesCount drives concurrently...Please be patient..."
|
Writelog "Building $DrivesCount drives concurrently...Please be patient..."
|
||||||
}else{
|
}
|
||||||
|
else {
|
||||||
Writelog "Building the imaging tool on $model...Please be patient..."
|
Writelog "Building the imaging tool on $model...Please be patient..."
|
||||||
}
|
}
|
||||||
Get-Job | Wait-Job | Out-Null
|
Get-Job | Wait-Job | Out-Null
|
||||||
@@ -138,7 +139,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 +170,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'
|
||||||
@@ -193,7 +196,8 @@ Function New-DeploymentUSB {
|
|||||||
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
|
||||||
}else{
|
}
|
||||||
|
else {
|
||||||
Read-Host -Prompt "Drive number $Selection was selected. Press ENTER to continue"
|
Read-Host -Prompt "Drive number $Selection was selected. Press ENTER to continue"
|
||||||
Build-DeploymentUSB -Drives $Drives[$DriveSelected]
|
Build-DeploymentUSB -Drives $Drives[$DriveSelected]
|
||||||
}
|
}
|
||||||
@@ -204,20 +208,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