Functions/Reset-VMDiskToCleanInstall.ps1


function Reset-VMDiskToCleanInstall {

    [CmdletBinding()]
    param (
        [Parameter()]
        [ArgumentCompleter( {
                param ( $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters )
                Get-VM "$wordToComplete*" | ForEach-Object { "`"$($_.Name)`"" }
            })]
        [string]
        $VMName,
        [Parameter()] [String] $VHDPath
    )

    $VMHDD = Get-VM $VMName | Get-VMHardDiskDrive

    $VMHDDPath = ($VMHDD).Path

    if ($VMHDDPath) {

        Remove-Item $VMHDDPath

        Start-BitsTransfer -Source $VHDPath -Destination $VMHDDPath -Description "Copying VHD file" -DisplayName "Copying VHD file $($VMName)"

    }

}