Based on standard practices, we need to have a copyright and license notice at the top of each source file. Removed existing copyrights and updated/added copyright notices for .h, .cpp, .cs, .ps1, and .psm1 files. Updated module manifests for consistency to have Author = "PowerShell" and Company = "Microsoft Corporation". Removed multiple line breaks. Separate PR coming to update contribution document for new source files: #6140 Manually reviewed each change. Fix #6073
79 lines
2 KiB
PowerShell
79 lines
2 KiB
PowerShell
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
# Licensed under the MIT License.
|
|
|
|
# Precondition: start from fresh PS session, do not have the media mounted
|
|
param([switch]$useModule, [string]$VHDPath)
|
|
|
|
function CreateVHD ($VHDPath, $Size)
|
|
{
|
|
$drive = (New-VHD -path $vhdpath -SizeBytes $size -Dynamic | `
|
|
Mount-VHD -Passthru | `
|
|
get-disk -number {$_.DiskNumber} | `
|
|
Initialize-Disk -PartitionStyle MBR -PassThru | `
|
|
New-Partition -UseMaximumSize -AssignDriveLetter:$False -MbrType IFS | `
|
|
Format-Volume -Confirm:$false -FileSystem NTFS -force | `
|
|
get-partition | `
|
|
Add-PartitionAccessPath -AssignDriveLetter -PassThru | `
|
|
get-volume).DriveLetter
|
|
|
|
$drive
|
|
}
|
|
|
|
if ($useModule)
|
|
{
|
|
$m = New-Module {
|
|
function Test-DrivePresenceFromModule
|
|
{
|
|
param ([String]$Path)
|
|
|
|
if (Test-Path $Path)
|
|
{
|
|
"Drive found"
|
|
if (-not (Get-PSDrive -Name $Path[0] -Scope Global -ErrorAction SilentlyContinue))
|
|
{
|
|
Write-Error "Drive is NOT in Global scope"
|
|
}
|
|
}
|
|
else { Write-Error "$Path not found" }
|
|
}
|
|
|
|
Export-ModuleMember -Function Test-DrivePresenceFromModule
|
|
}
|
|
}
|
|
|
|
try
|
|
{
|
|
if ($useModule)
|
|
{
|
|
Import-Module $m -Force
|
|
}
|
|
|
|
$drive = CreateVHD -VHDPath $VHDPath -Size 5mb
|
|
$pathToCheck = "${drive}:"
|
|
|
|
if ($useModule)
|
|
{
|
|
Test-DrivePresenceFromModule -Path $pathToCheck
|
|
}
|
|
else
|
|
{
|
|
if (Test-Path $pathToCheck)
|
|
{
|
|
"Drive found"
|
|
if (-not (Get-PSDrive -Name $drive -Scope Global -ErrorAction SilentlyContinue))
|
|
{
|
|
Write-Error "Drive is NOT in Global scope"
|
|
}
|
|
}
|
|
else { Write-Error "$pathToCheck not found" }
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
if ($useModule)
|
|
{
|
|
Remove-Module $m
|
|
}
|
|
Dismount-VHD $VHDPath
|
|
Remove-Item $VHDPath
|
|
}
|