Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Create a bootable USB flash drive in Win Srv 2022
- # https://t.ly/HzBuo
- # Save as winsrv2022_bootable.ps1
- # Select USB drive letter
- $usbDriveLetter = Read-Host "Enter USB drive letter (Ex: E)"
- # Format USB drive
- Format-Volume -DriveLetter $usbDriveLetter -FileSystem NTFS -NewFileSystemLabel "WinServerUSB" -Confirm:$false | Out-Null
- # Select ISO file mount point
- $isoMountPointDriveLetter = Read-Host "Enter ISO mount point drive letter (Ex: F)"
- # Copy ISO files to USB drive
- $source = "$($isoMountPointDriveLetter):\"
- $destination = "$($usbDriveLetter):\"
- robocopy $source $destination /COPYALL /Z /E /SEC /R:3 /W:3
- # Make USB drive bootable
- $usbDriveNumber = (Get-WmiObject -Class Win32_DiskDrive | Where-Object {$_.InterfaceType -eq "USB" -and $_.DeviceID -like "*$usbDriveLetter"}).Index
- bootsect /nt60 $usbDriveLetter`:
- # Task completion notification
- Write-Host "USB Creation Complete!"
- Start-Sleep -Seconds 2
- #------------------------------------------------------------------------------------------------
- # Error with script policy not letting it run
- The following will allow all local scripts to execute on the VM, irrespective of whether they're signed or not:
- Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
Advertisement
Add Comment
Please, Sign In to add comment