-
Notifications
You must be signed in to change notification settings - Fork 0
/
Clear-DpDisk.ps1
47 lines (38 loc) · 1.08 KB
/
Clear-DpDisk.ps1
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
Function Clear-DpDisk {
<#
.SYNOPSIS
Removes all Partition-Information from a disk using Diskpart.
.DESCRIPTION
The Clear-DpDisk function is used to clear a disk using Diskpart utility. It selects the specified disk and performs a clean operation.
.PARAMETER Disknumber
The disk number of the disk to be cleared.
.PARAMETER Force
Indicates whether to force the disk clearing operation. If the disk contains a partition, the operation will fail unless this parameter is specified.
.EXAMPLE
Clear-DpDisk -Disknumber 1
Clears disk number 1 using Diskpart.
.EXAMPLE
Clear-DpDisk -Disknumber 2 -Force
Clears disk number 2 using Diskpart, forcing the operation.
#>
param
(
[Int]
[Parameter(Mandatory,
ValueFromPipeline,
ValueFromPipelineByPropertyName)]
[Alias('ID')]
[Int]$Disknumber,
[switch]$force
)
Process {
$DiskpartCommand = @"
Select Disk $Disknumber
Clean
"@
# $DiskpartCommand | Out-File $env:TEMP\diskpart.txt -Encoding ascii -Force
$ReturnValue = $DiskpartCommand | diskpart.exe
Write-Verbose -Message $ReturnValue[-1]
}
}