forked from Durga-96/CESARMTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormatFixedDataDisk.ps1
More file actions
82 lines (62 loc) · 3.12 KB
/
Copy pathFormatFixedDataDisk.ps1
File metadata and controls
82 lines (62 loc) · 3.12 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Name: FormatDataDisks
#
configuration FormatDataDisks
{
param (
$Disks
)
#$DiskArray = $Disks | convertfrom-Json $disks
node localhost
{
Script FormatVolumnes
{
GetScript = {
get-disk
Get-Partition
}
SetScript = {
try {
#format the ones requested
foreach($disk in $using:Disks.values) {
$diskArray = get-disk
$partArray = Get-Partition
$thisExists =$partArray | Where-Object {$_.DriveLetter -eq $($disk.DiskName)} | Select -First 1
if($thisExists -eq $null) {
$DiskExists = $diskArray | ? {$($_.Size/1GB) -eq $($disk.Disksize)} | ?{$_.Number -notin $partarray.DiskNumber} | Sort-Object DiskNumber | select -First 1
try {
if($DiskExists) {
if($DiskExists.PartitionStyle -eq 'Raw') {
$DiskExists | Initialize-Disk -PartitionStyle GPT -PassThru | New-Partition -DriveLetter $($disk.DiskName) -UseMaximumSize | Format-Volume -NewFileSystemLabel $($disk.DiskLabel) -FileSystem NTFS -AllocationUnitSize 65536 -Confirm:$false
} else {
$DiskExists | New-Partition -DriveLetter $($disk.DiskName) -UseMaximumSize | Format-Volume -NewFileSystemLabel $($disk.DiskLabel) -FileSystem NTFS -AllocationUnitSize 65536 -Confirm:$false
}
} else {
write-verbose "No Drive avail"
}
} catch {
write-verbose "`t[FAIL] $VM Setting Drive $($Disk.DiskName) Failed.`n"
}
} else {
Write-verbose "`t[PASS] $VM Drive $($Disk.DiskName) exists.`n"
}
}
#format the remaining using next available drive letter
get-disk | ? {$_.PartitionStyle -eq 'Raw'} | %{ Initialize-Disk -PartitionStyle GPT -Number $_.number -PassThru | New-Partition -AssignDriveLetter -UseMaximumSize | Format-Volume -FileSystem NTFS -AllocationUnitSize 65536 -Confirm:$false }
} catch {}
}
TestScript = {
$diskArray = get-disk | ? {$_.PartitionStyle -eq 'RAW'}
$partArray = Get-Partition
$vols =@()
$disks | ? {
$d=$_
$v = $($partArray | Where-Object {$_.DriveLetter -eq $($d.DiskName)} | Select -First 1)
if(!$v){
$vols+=$d
}
}
if($vols) {return $true} else {return $false}
}
}
}
}