Case of the Win10 HyperV Fail – Property ‘MaxInternalSize’ does not exist in class ‘Msvm_VirtualHardDiskSettingData’

Trying to copy a huge file out of a HyperVM late at night I naively went and right clicked “Mount” in Windows Explorer on the VHDX file. Unfortunately my VM had multiple checkpoints, which aren’t visible when browsing the VHDX. Realised my mistake then unmounted the VHDX. Unfortunately now the VM stopped booting…

Can’t access disk, opening the VM properties selecting disk and clicking Inspect I get error:

[Window Title]
Virtual Hard Disk Properties

[Main Instruction]
There was a problem with one of the command line parameters. Either ‘DESKTOP-RTTN04O’ could not be found, or ‘C:\Users\Public\Documents\Hyper-V\Virtual hard disks\Win7_31AB2236-D8AC-4CF9-8A75-2DC321590C8C.Avhdx’ is not a valid path.

[Content]
Property ‘MaxInternalSize’ does not exist in class ‘Msvm_VirtualHardDiskSettingData’.

[Close]

This VM had the “parent” and two subsequent checkpoints..

  • Parent = Win7.vhdx
  • 1st checkpoint = Win7_5A0F4E19-3212-4D0A-8A43-83853D468B0B.avhdx
  • 2nd checkpoint = Win7_31AB2236-D8AC-4CF9-8A75-2DC321590C8C.avhdx

To fix this I used the PowerShell cmd Set-VHD

Set-VHD "C:\Users\Public\Documents\Hyper-V\Virtual hard disks\Win7_31AB2236-D8AC-4CF9-8A75-2DC321590C8C.Avhdx" -ParentPath "C:\users\public\documents\Hyper-V\Virtual hard disks\Win7_5A0F4E19-3212-4D0A-8A43-83853D468B0B.avhdx"
Set-VHD "C:\users\public\documents\Hyper-V\Virtual hard disks\Win7_5A0F4E19-3212-4D0A-8A43-83853D468B0B.avhdx" -ParentPath "C:\users\public\documents\Hyper-V\Virtual hard disks\Win7.vhdx"

Unfortunately the final command failed:

Set-VHD : Failed to set new parent for the virtual disk.
There exists ID mismatch between the differencing virtual hard disk and the parent disk.

To resolve this error I added –ignoreidmismatch

Set-VHD "C:\users\public\documents\Hyper-V\Virtual hard disks\Win7_5A0F4E19-3212-4D0A-8A43-83853D468B0B.avhdx" -ParentPath "C:\users\public\documents\Hyper-V\Virtual hard disks\Win7.vhdx" -ignoreidmismatch

I reset my VM hard disk to use the 2nd checkpoint disk file, I received a warning data loss could occur if I continued, but I risked everything and continued anyway.  Clicking “Inspect Disk” now succeeded and my VM now booted fine, and seemed to have the recent data I had added into it…

Posted in Uncategorized | 2 Comments

Faster Where-Object In PowerShell

One of the worst features of PowerShell for me is extremely slow performance in loops, especially using items like Where-Object { $_.Name –eq “value” }

For performance critical loops I use inline C#

Here is an example to search data imported from CSV more quickly, to retrieve the relevant line of data:

$Source = @"

using System;
using System.Management.Automation;
namespace FastSearch
{
    
    public static class Search
    {
        public static object Find(PSObject[] collection, string column, string data)
        {
            foreach(PSObject item in collection)
            {
                if (item.Properties[column].Value.ToString() == data) { return item; }
            }

            return null;
        }
    }
}
"@ 

Add-Type -ReferencedAssemblies $Assem -TypeDefinition $Source -Language CSharp 

$data = Import-Csv "songwriters.csv"

$row = [FastSearch.Search]::Find($data,"Name","Bob Dylan")

In test CSV file to search the CSV data 30k times the C# version took a few minutes, using $data | Where-Object { Name –eq “<name>”} took over 12 hours.

Posted in Performance, PowerShell | Leave a comment

Export Large Number of Users from ConfigMgr to CSV with PowerShell

Had a scenario where I required export of 50k+ users from ConfigMgr to do some analysis.

However PowerShell cmdlet Get-CMUser just hung for an hour or more. Maybe it would eventually come back with a result, I don’t know…

So I tried using WMI query:

$SiteName="<site code>"
$SCCMServer="<configmgr server>"
$SCCMNameSpace="root\sms\site_$SiteName"
$result = Get-WmiObject -namespace $SCCMNameSpace -computer $SCCMServer -query "select * from sms_r_user"
$result | Export-Csv UserIDs.csv -NoTypeInformation

However this also hung for quite some time until eventually failing:

Get-WmiObject : Shutting down
At line:4 char:11
+ $result = Get-WmiObject -namespace $SCCMNameSpace -computer $SCCMServer -query ” …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], ManagementException
    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

 

To work around this, did a search filtering by first character of username. In this case I just looked for usernames starting with a-z or 0-9:

$SiteName="<site code>"
$SCCMServer="<configmgr server>"
$SCCMNameSpace="root\sms\site_$SiteName"

$result = @()
ForEach ($letter in "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9")
{
    Write-Host "Searching for usernames starting with $letter"
    $result += Get-WmiObject -namespace $SCCMNameSpace -computer $SCCMServer -query "select * from sms_r_user WHERE UserName LIKE '$letter%'"
}

$result | Export-Csv UserIDs.csv -NoTypeInformation

This worked perfectly and extracted all the users into CSV format within a few minutes.

Posted in ConfigMgr | Tagged | Leave a comment

Case of the Automatic Outlook Signature Configuration Failure

An environment was using logon batch file, that called a VBS to automatically configure Outlook signatures. The signature had a different image attached to the end of it dependent on current marketing campaign.

One day it stopped working, manually running the script showed the following error

outlookad.vbs(256, 3) Microsoft VBScript runtime error: Object required: ‘objRoot’

This line had code like this:

for each campaign in objRoot.childNodes

Searching backwards in the code we found objRoot was assigned by loading XML:

Set xmlDoc = CreateObject(“Msxml.DOMDocument”)
xmlDoc.load strLogonServer & “\netlogon\marketingCampaigns.xml”
Set objRoot = xmlDOc.documentElement

Added a quick to see if XML was loading:

Set xmlDoc = CreateObject(“Msxml.DOMDocument”)
if (xmlDoc.load(strLogonServer & “\netlogon\marketingCampaigns.xml”)) Then
    WScript.Echo “XML loaded OK!”
Else
    WScript.Echo “XML Failed to load!”
End If

Set objRoot = xmlDOc.documentElement

The script output “XML Failed to load!”

Checking the XML file we could see it had last modified date of a week ago, and had content like below:

<?xml version=”1.0″?>
<campaigns>
  <campaign>
     <applicableGroup>DL-Australia</applicableGroup>
     <imageFile>NEW-Email_Footer.jpg</imageFile>
     <url>
http://www.contoso.com/?utm_source=EmailSignature&utm_campaign=CWT2017</url>
  </campaign>
</campaigns>

The issue was the XML had unescaped ampersand added into the URL field … replacing & with &amp; fixed the issue.

Posted in Office | Tagged | Leave a comment

Case of the VBS Compilation Error–Invalid Character

Running a VBS script resulted in error Microsoft VBScript compilation error: Invalid character

image

The line of code apparently containing invalid character was:

    Const ForWriting = 2

Opening in a Hex Editor it was revealed the “spaces” before the word const were something else

image

 

Selecting the blank spaces, copying them, pasting into a notepad search/replace didn’t remove them.

Using HexEdit I search/replaced the relevant bytes with 09 (tab)

image

After this some instances of C2 or A0 were on their own still causing the error, these I replaced with 0x20 (space)

image

After this the script ran fine…

Posted in Uncategorized | Leave a comment

Decompress Exchange Offline Address Book LZX Files to OAB format

Program binaries can be downloaded here https://1drv.ms/u/s!AiFhB4fT6aiTgdwrR_OOsORLs2SaUQ

Visual Studio 2017 C++ project and source code available here

https://github.com/chentiangemalc/LzxToOab

In further blog post will explain how to extract address information from OAB file.

For usage information run LzxToOab.exe without parameters:

image

Posted in Uncategorized | Tagged | Leave a comment

Decompress Exchange Offline Address Book LZX Files to OAB format

Program binaries can be downloaded here https://1drv.ms/u/s!AiFhB4fT6aiTgdwrR_OOsORLs2SaUQ

Visual Studio 2017 C++ project and source code available here

https://github.com/chentiangemalc/LzxToOab

In further blog post will explain how to extract address information from OAB file

Posted in Uncategorized | Tagged | Leave a comment