Functions/New-MyVolume.ps1


function New-MyVolume {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        [ValidateScript( {
                $_ -in ((Get-Disk).Number)
            } ) ]
        [string] $Disk,
        [Parameter(Mandatory)] [string] $DriveLetter
    )

    if ((Get-Disk -Number $Disk).AllocatedSize -ne 0) {
        Write-Warning "Unable to create partition, the disk already has data present."
    } elseif (Get-Volume $DriveLetter -ea 0) {
        Write-Warning "Unable to create partition, a volume with driveletter $DriveLetter already exists."
    } else {
        Clear-Disk $Disk -Confirm:$false -ea 0
        Initialize-Disk $Disk -PartitionStyle GPT
        New-Volume -DiskNumber $Disk -FileSystem NTFS -DriveLetter $DriveLetter -FriendlyName $DriveLetter
    }
}