Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Registers a VHD disk image with Lability
param (
[parameter(Mandatory = $true, HelpMessage = "Name of the Lablity enviroment definition")]
$mediaid ,
[parameter(Mandatory = $true, HelpMessage = "UNC path the VHDs are stored on")]
$downloadPath
)
$metadataFiles = Get-ChildItem -Path $downloadPath -filter *.metadata
foreach ($file in $metadataFiles) {
$data = get-content $downloadPath\$file | ConvertFrom-Json
if ($data.mediaid -eq $mediaid) {
$hash = $data.checksum
$vhdname = $file.name.replace(".metadata", ".vhd")
break
}
}
if ($hash -eq $null) {
Write-Error "Cannot find any metadata file on path [$downloadpath] with the correct mediaId [$mediaID]"
return
}
write-host "The checksum is [$hash] for the mediaID [$mediaid]"
if(!(Get-module Lability )) {
Import-Module Lability
}
write-host "Unregister media $mediaid"
$buildmedia=get-labmedia -id $mediaid
write-host "Update details for media $mediaid"
$correctFormatFolderPath = "$downloadPath\$vhdname".Replace('\','/')
$buildmedia.Uri="file:$correctFormatFolderPath"
$buildmedia.Checksum=$hash
$buildmedia.Filename=$vhdname
write-host "Re-register media $mediaid"
register-labmedia -Checksum $buildmedia.Checksum -id $buildmedia.Id -Filename $buildmedia.Filename -Description $buildmedia.Description -Architecture $buildmedia.Architecture -MediaType $buildmedia.MediaType -OperatingSystem $buildmedia.OperatingSystem -Uri $buildmedia.uri -force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.