blob: 6bbc175872eec8178c91f667864db8dd283a0eae (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: MIT
# REPLACE WITH UTILITY-PREFIX.ps1
<#
.SYNOPSIS
Partitions a new physical disk.
.DESCRIPTION
Takes the disk $DiskNumber, turns it on, then partitions it for use with label
$Label and drive letter $Letter.
.PARAMETER DiskNumber
The number of the disk to set up.
.PARAMETER Letter
The drive letter at which to mount the disk.
.PARAMETER Label
The label to give the disk.
#>
Function New-PhysicalDisk {
Param(
[int]$DiskNumber,
[string]$Letter,
[string]$Label
)
if ($Letter.Length -ne 1) {
throw "Bad drive letter $Letter, expected only one letter. (Did you accidentially add a : ?)"
}
try {
Write-Host "Attempting to online physical disk $DiskNumber"
[string]$diskpartScriptPath = Get-TempFilePath -Extension 'txt'
[string]$diskpartScriptContent =
"SELECT DISK $DiskNumber`r`n" +
"ONLINE DISK`r`n"
Write-Host "Writing diskpart script to $diskpartScriptPath with content:"
Write-Host $diskpartScriptContent
Set-Content -Path $diskpartScriptPath -Value $diskpartScriptContent
Write-Host 'Invoking DISKPART...'
& diskpart.exe /s $diskpartScriptPath
Write-Host "Provisioning physical disk $DiskNumber as drive $Letter"
[string]$diskpartScriptContent =
"SELECT DISK $DiskNumber`r`n" +
"ATTRIBUTES DISK CLEAR READONLY`r`n" +
"CREATE PARTITION PRIMARY`r`n" +
"FORMAT FS=NTFS LABEL=`"$Label`" QUICK`r`n" +
"ASSIGN LETTER=$Letter`r`n"
Write-Host "Writing diskpart script to $diskpartScriptPath with content:"
Write-Host $diskpartScriptContent
Set-Content -Path $diskpartScriptPath -Value $diskpartScriptContent
Write-Host 'Invoking DISKPART...'
& diskpart.exe /s $diskpartScriptPath
}
catch {
Write-Error "Failed to provision physical disk $DiskNumber as drive $Letter! $($_.Exception.Message)"
}
}
New-PhysicalDisk -DiskNumber 1 -Letter 'E' -Label 'install disk'
|