Skip to content

Instantly share code, notes, and snippets.

@rfennell
Created December 20, 2019 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rfennell/f1a0240639e3064f266de0d41f46aaf7 to your computer and use it in GitHub Desktop.
Save rfennell/f1a0240639e3064f266de0d41f46aaf7 to your computer and use it in GitHub Desktop.
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