Skip to content

Instantly share code, notes, and snippets.

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")]
$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 = $".metadata", ".vhd")
if ($hash -eq $null) {
Write-Error "Cannot find any metadata file on path [$downloadpath] with the correct mediaId [$mediaID]"
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('\','/')
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