Created
July 22, 2022 06:06
-
-
Save maxautomation/3778d375274225f982ca1db3bbab0c44 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Initialize-EC2Disk { | |
param( | |
[parameter (mandatory=$true)][string] $InstanceId | |
) | |
$Commands = @( | |
'Get-Disk | ` | |
Where partitionstyle -eq "raw" | ` | |
Initialize-Disk -PartitionStyle MBR -PassThru | ` | |
New-Partition -AssignDriveLetter -UseMaximumSize | ` | |
Format-Volume -FileSystem NTFS -Confirm:$false -force' | |
) | |
$Parameter = @{ | |
commands = $Commands | |
} | |
$Document = 'AWS-RunPowerShellScript' | |
Write-Host "" | |
Write-Host "Initializing disk..." -ForegroundColor Green | |
Try { | |
$Cmd = Send-SSMCommand -DocumentName $Document -Parameter $Parameter -InstanceId $InstanceId | |
While ($Cmd.Status -ne 'Success') | |
{ | |
$Cmd = Get-SSMCommand -CommandId $Cmd.CommandId | |
Start-Sleep 10 | |
} | |
Write-Host "" | |
Write-Host "Disk is initialized & formatted" -ForegroundColor Green | |
} | |
Catch { | |
Write-Host "" | |
Write-Host "Failed to initialize disk" -ForegroundColor Red | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment