Site moved to new server

I finally got time and energy to move this site to a more powerful server.
It´s the Odroid XU4 I wrote about some month ago.
The site is now stored at a external SSD-disk så I have more storage and quicker disk.
And you can actually feel the difference when browsing the site.

The whole server!

That´s it for now….

More will come when I find something interesting to write about…

Hyper-V and the need for speed…

Sometimes I need to build a new Windows image  to deploy with SCCM at work.
And it would be nice if it didn´t took too long time to build, because sometimes you need to test new things and the image might fail while building it and you have to correct the fault and start over again.

At work I have a Hyper-V host with plenty of ram, so why not make a ramdisk to have the VM-disks on?
But the backside is that when you reboot the host, the disk-files is lost and you manually need to remove and add new disks to the VM….or do you?

My setup is:

  • MDT and ADK hosted on another server
  • Hyper-V host with Windows Server 2012 R2 and 192Gb ram
  • A 80Gb ramdrive (enough for 2*40Gb virtual disk) made with ImDrive software
  • Powershell of course!

My VMs are stored on a ordinary disk and have these specification:

  • Generation 1 VM
  • 4Gb ram
  • 1 cpu, 2 cores
  • No HDD!
  • 1 Network adapter, legacy adapter is not necessary in my case. I boot from an ISO-files from the MDT-share directly.
  • A static MAC-adress
  • A snapshot when everything is configured

So, my idea is to script a sequence where I create a virtual disk on the ramdrive -> connect it to the VM -> start VM and buid image -> disconnect disk when finished -> delete disk file.

This script will do that. It starts the VM and waits for it to shutdown and then removes the disks and disk-files and finaly reverts the snapshot.

$VMName = "Windows10x64BC"
$DiskFileName = "Disk0.vhdx"
$VMDiskFolder = "R:\Hyper-V" # Location to ramdisk-drive and a subfolder. will be created by hyper-v if not existing
$VMDiskPath = "$VMDiskFolder\$VMName\$DiskFileName" #Folder doesnt need to exist
$DiskSize = "40960000000" # 40Gb in Bytes!

#Removes old drive
Function RemoveAllDrives {
    Get-VMHardDiskDrive -VMName $VMName | ForEach-Object {
        Write-Host "Found Drive $($_.Path)"
        Write-Host "Removing drive from VM"
        Remove-VMHardDiskDrive -VMName $VMName -ControllerNumber $($_.ControllerNumber) -ControllerLocation $($_.ControllerLocation) -ControllerType $($_.ControllerType)
        Write-Host "Deleting Drive-file from disk"
        Remove-Item -LiteralPath $($_.Path) -Force
    Remove-Item -LiteralPath $VMDiskPath -Recurse -Force
    Remove-Item -LiteralPath "$VMDiskFolder\$VMName" -Recurse -Force
#Adds new drive
New-VHD -Path $VMDiskPath -SizeBytes $DiskSize
Add-VMHardDiskDrive -VMName $VMName -ControllerType IDE -Path $VMDiskPath

#Run and wait for VM to finish, then revert to snapshot
# Start VM
Start-VM -VMName $VMName

# Monitor VM to see if it's running
$VM = Get-VM -Name $VMName
while ($VM.State -ne "off")
    write-host "The VM is still running"
    sleep 20
# Restore VMSnapshot
Get-VM –Name $VMName | Get-VMSnapshot  | Sort CreationTime | Select -Last 1 | Restore-VMSnapshot -Confirm:$false

Happy image-building!

New toy! Odroid XU4 :)

I love these computers!


This week I recieved a new arm-based computer, An Odroid XU4 from Hardkernel.
This beast have a Samsung big.LITTLE processor with 4 (Cortex A15)+4 (Cortex A7) cores, 2Gb ram, gigabit ethernet, 2 USB3 ports, 1 USB2 port and HDMI out.

Top view. Look at that beautiful blue heatsink!
The size is about the same as an Raspberry Pi.
The case I bought wasn’t that good looking, but it does the job of protecting the motherboard.

My plan is to make this the new host for this site… someday.
But first I´m going to play a little with it.

In the Odroid forum you can find a lot of help and information.

Right now I`m play around a bit with Android and RetroPi.
But soon I hope to start configure WordPress on it.

Some links for more information and other stuff

Hardkernels product page for the XU4.
Armbian Linux image.
RetroPi instructions for manuall install on the XU4 and the offical Hardkernel Linux image they base the the installation on.
DietPi Linux image, partly based on Armbian.


Mounting ISO-files with Powershell

In windows 10 and Server 2016 you have built in support for mounting ISO-files to a virtual CD/DVD-Drive.

On my HTPC I wanted to crate a simple and functional GUI to mount and unmount ISO-files.
So I wrote a Powershell-script to manage that. It also starts PowerDVD and start to play that drive the ISO-files has been mounted on.

I’t not beautiful, but functional…
$VDrive = New-Object System.Collections.Generic.List[System.Object]
$PDVDPath = "C:\Program Files (x86)\CyberLink\PowerDVD17\PowerDVD.EXE"
$IsoPaths = "D:"#"F:\4k ISOS"
$IsoFiles = ''

#region Functions

# Refreshes the list of virtual drives
Function RefreshVCDList {
    $Drives = Get-Volume
    ForEach ($Vol in $Drives){
        $DLetter = ''
        $DLetter = $Vol.DriveLetter
        IF (Get-DiskImage -DevicePath "\\.\$DLetter`:" -ErrorAction Ignore){
            Write-host $DLetter

# Refresh the list of Iso-files
Function RefreshIsoFiles {
    $Isos = @()
    ForEach($Path in $IsoPaths){
        $Isos += (Get-ChildItem -path $Path -Recurse -Include '*.iso' -File).FullName
    return $Isos

# Unmounts all virtual drives
Function UnMountAll {
    ForEach($vol in $VDrive){
        Write-Host "unmounting "\\.\$vol`:""
        Dismount-DiskImage -DevicePath "\\.\$vol`:" -ErrorAction ignore

# Mounts selected iso-file
Function MountImageFile {
    [Parameter(Mandatory = $true)]
    $global:Mounted = ''
    $IsAllreadyMouted = ''
    $IsAllreadyMouted = (Get-DiskImage -ImagePath "$ImagePath").Attached
    $Driveletter = ''
    Write-Host "Info mountstatus:" $IsAllreadyMouted
    IF($IsAllreadyMouted -eq $false){
        Write-Host "mounting $ImagePath"
        $global:Mounted = (Mount-DiskImage -ImagePath "$ImagePath" -PassThru | Get-Volume)
    } ELSEIF ($IsAllreadyMouted -eq $true){
        Write-Host "Image $ImagePath is allready mounted"
        $global:Mounted = (Get-DiskImage -ImagePath "$ImagePath" | Get-Volume)
    [STRING]$Driveletter = $global:Mounted.DriveLetter +":"
    Write-host "Info mountvolume:" $Driveletter
    return $Driveletter

Function UpdateISOList {
    $Files = @()
    $Files = RefreshIsoFiles
    ForEach($IsoItem in $Files){
        IF ($IsoItem -ne $null){


#region GUI
Add-Type -AssemblyName System.Windows.Forms
$FrmMain = New-Object system.Windows.Forms.Form
$FrmMain.Text = "Markus ISO-Mounter"
$FrmMain.TopMost = $false
$FrmMain.Width = 1300
$FrmMain.Height = 800
$FrmMain.TopMost = $false
    #Sets size and place of other stuff when main form changes
    $LstBoxIsos.Width = ($FrmMain.Width - 45)
    $LstBoxIsos.Height = ($FrmMain.Height - 200)

    $BtnRefresh.location = new-object system.drawing.point(10,($FrmMain.Height - 130))
    $BtnUnMount.location = new-object system.drawing.point(130,($FrmMain.Height - 130))
    $ChkBoxUnmount.location = new-object system.drawing.point(10,($FrmMain.Height - 160))
    $ChkStartPDVD.location = new-object system.drawing.point(10,($FrmMain.Height - 190))


$LstBoxIsos = New-Object
$LstBoxIsos.Width = 1255
$LstBoxIsos.Height = 600
$LstBoxIsos.Font = "Microsoft Sans Serif,14"
$LstBoxIsos.HorizontalScrollbar = $true
    $File = $LstBoxIsos.SelectedItem
    [STRING]$MountDrive = ''
    IF ($ChkBoxUnmount.Checked){
        Write-Host "unmounting all drives"
    Write-Host "mounting" $File
    $MountDrive = (MountImageFile -ImagePath "$File")
    Write-Host "iso mounted on $MountDrive"
    IF ($ChkStartPDVD.Checked){
        Write-Host "Starting PowerDVD with $MountDrive"
        Start-Process -FilePath $PDVDPath -ArgumentList $MountDrive
        Write-Host "Could not start PowerDVD"
$LstBoxIsos.location = new-object system.drawing.point(10,10)

$BtnRefresh = New-Object
$BtnRefresh.Text = "Refresh iso-files"
$BtnRefresh.Width = 100
$BtnRefresh.Height = 60
$BtnRefresh.location = new-object system.drawing.point(10,670)
$BtnRefresh.Font = "Microsoft Sans Serif,10"
    $BtnRefresh.BackColor = "RED"

$BtnUnMount = New-Object
$BtnUnMount.Text = "Unmount all drives"
$BtnUnMount.Width = 150
$BtnUnMount.Height = 60
$BtnUnMount.location = new-object system.drawing.point(130,670)
$BtnUnMount.Font = "Microsoft Sans Serif,10"
    $BtnUnMount.BackColor = "RED"

$ChkBoxUnmount = New-Object
$ChkBoxUnmount.Text = "Unmount all drives when mouting iso"
$ChkBoxUnmount.AutoSize = $true
$ChkBoxUnmount.Width = 95
$ChkBoxUnmount.Height = 20
$ChkBoxUnmount.location = new-object system.drawing.point(10,640)
$ChkBoxUnmount.Font = "Microsoft Sans Serif,10"
$ChkBoxUnmount.Checked = $true

$ChkStartPDVD = New-Object
$ChkStartPDVD.Text = "Start PowerDVD When mounting iso"
$ChkStartPDVD.AutoSize = $true
$ChkStartPDVD.Width = 95
$ChkStartPDVD.Height = 20
$ChkStartPDVD.location = new-object system.drawing.point(10,610)
$ChkStartPDVD.Font = "Microsoft Sans Serif,10"
$ChkStartPDVD.Checked = $true



If you know better ways in Powershell to mount/unmount and get a list of virtual drives, please let me know. Always fun to make the code better!!

Copy files to flat file structure

Recently I needed to copy a bunch of files within a lot of subfolders, but I didn’t want the folders.
I just needed a flat file structure. Who needs folders anyway? 🙂

So, my solution is of course powershell.

$Source = "x:\sourcefolder"
$Destination = "y:\destinationfolder"
$Files = Get-ChildItem -LiteralPath $Source -Recurse -file -Force
[INT]$nr = '1'
ForEach($File in $Files){
    Write-Output "------------------------------------------------------------------------------------------"
    Write-Output "File $nr/$($Files.Count)"
    Write-Output "Copying file: $($"
    Write-Output "------------------------------------------------------------------------------------------"
    $File | Copy-Item -Destination $Destination
    $nr ++

Read and Write BIOS settings to Lenovo computers



As I often say, if you can automate things you have time to do more fun stuff.
And in windows deployment from SCCM/MDT i’ts always nice to even automate BIOS settings.

Lenovo have been smart in this way. Instead of using special tools, like HP and Dell, you can use WMI methods instead.

This might not be the best coding ever, but you might get the idea here….

Reading settings

The easiest way is probably to sett BIOS as you want it, boot up in Windows or Windows PE with powershell support in it and run this script.

ForEach($Obj in $BiosSettings){
    if ($Obj.CurrentSetting -ne "") {
        Write-Host $Obj.CurrentSetting.replace(",",";")

This will output all the BIOS settings in a textfile in the same directory as the script. You can easily change the values and/or remove values you don’t want to change.

Writing settings

$SettingsFile = "Settings.txt"
$SettingsObj = ""
$SettingsObj = Get-Content $PSScriptRoot\$SettingsFile
$PasswordState = (gwmi -class Lenovo_BiosPasswordSettings -namespace root\wmi).PasswordState

function Set-LenovoBiosSettingsValues
    Param( [string]$WMIObj, [string]$WMIValue )

    If ($PasswordIsSet -eq $false) {
        (gwmi -class Lenovo_SetBiosSetting –namespace root\wmi).SetBiosSetting("$WMIObj,$WMIValue")
    Else {
     (gwmi -class Lenovo_SetBiosSetting -namespace root\wmi).SetBiosSetting("$WMIObj,$WMIValue,$BiosPass,ascii,us")

    gwmi -class Lenovo_BiosSetting -namespace root\wmi | Where-Object {$_.CurrentSetting.split(",",[StringSplitOptions]::RemoveEmptyEntries) -eq "$WMIObj"} |
    Format-List CurrentSetting

function Set-LenovoBiosSettings {

    #Check if BIOS password is set
    If ($PasswordState -eq '0') {
        $PasswordIsSet = $false
        Write-Host "BIOS password not set"
    Else {
        $PasswordIsSet = $true
        Write-Host "BIOS password is set"

    foreach ($setting in $SettingsObj) {
        $Sobj = ""
        $Svar1 = ""
        $Svar2 = ""
        $Sobj = $Setting -split ';'

        Write-Host "Sets ""$Svar1"" to ""$Svar2"""
        Set-LenovoBiosSettingsValues -WMIObj $Svar1 -WMIValue $Svar2
    #Saves the bios-settings
    Write-Host "Saving settings"
    (gwmi -class Lenovo_SaveBiosSettings -namespace root\wmi).SaveBiosSettings("$BiosPass,ascii,us")

# Start writing settings

There are some shortcomings with the way Lenovo has implemented this, some settings cannot be made.
For an example you cannot sett a BIOS password if there aren’t any allready. So you can only change password.
And you cannot set “PhysicalPresenceForTpmClear” to Disable. But only change from Disable to Enable.


You you want to read more about this, you can read the offical documentation and maybe find other things you can do via the wmi.