vWorkspace
Troubleshooting for Dell Software
Posts
This post is more than 5 years old
Solved!
Go to Solution17 Posts
0
574142
January 5th, 2016 06:00
Powershell - Return the template name of a running VM
Does anybody know/got the command (powershell) to return the template name of a VM?
Responses(10)
13
0
2
61
0
2
96
0
4
28
0
4
23
0
1
No Events found!
Hilbert_nl
17 Posts
0
January 7th, 2016 06:00
Sorry, I couldn't get it work. In the near future we will run vW 8.6, I will try it again then.
For now I fixed it with CmdLets from HyperV 2012 R2
$VMTemplate = ((Get-VM -Name $VM).Id | Get-VHD).ParentPath
I split and convert this to the correct template name.
DELL-Joel W1
15 Posts
0
January 5th, 2016 07:00
Which version of the PowerShell module are you running?
Hilbert_nl
17 Posts
0
January 5th, 2016 09:00
I'm using the 8.0 modules
DELL-Joel W1
15 Posts
0
January 5th, 2016 10:00
Since I don't have an 8.0 environment handy, I hesitate to give you untested code, though I can tell you what you're looking for. The 8.0 powershell module will require some reflection to get at this property. We exposed this property in the 8.5 module.
The QVWComputer object returned by cmdlets such as Get-QVWComputer has a non-public backing object called the BusinessObject. This is where you will need to use reflection to gain access.
This BusinessObject has a public property named Template which has a great deal of information that might prove useful to you.
Hilbert_nl
17 Posts
0
January 5th, 2016 12:00
I don't have any knowledge about reflection, but google helped me with it :)
But I don't see the public property Template in the Businessobject.
I tried this:
$machines = Get-QVWComputer -Filter{$qvwcomputer.ComputerGroupName -eq $ComputergroupName} -Farm $Farmname
$machines[0].GetType().GetProperties([System.Reflection.BindingFlags]::Instance -bor [System.Reflection.BindingFlags]::NonPublic) | Where-Object {$_.Name -eq "BusinessObject"}
Did I do something wrong?
Hilbert_nl
17 Posts
0
January 5th, 2016 13:00
haha..nice puzzle :)
I get only the following public properties. I am missing the template
MemberType
Name
DeclaringType
ReflectedType
MetadataToken
Module
PropertyType
Attributes
CanRead
CanWrite
GetMethod
IsSpecialName
CustomAttributes
DELL-Joel W1
15 Posts
0
January 5th, 2016 13:00
Ok, that's good, so go ahead and grab that BusinessObject and access its Template property.
I'm not 100% certain, so if it doesn't let you do that directly, it may require another level of reflection to get it out.
DELL-Joel W1
15 Posts
0
January 5th, 2016 13:00
What are the properties that you do see? If you take out the final Where-Object clause, what is the output?
Hilbert_nl
17 Posts
0
January 5th, 2016 13:00
filtermaps
BusinessObject
BackingObject
DELL-Joel W1
15 Posts
0
January 5th, 2016 14:00
Right, ok, that's the System.Reflection.PropertyInfo that the GetProperties() reflection returned.
You can use that to actually access the object's data using .GetMethod().Invoke($machines[0], []) or something to that effect. That should invoke the Get on that property for the $machines[0] object, returning the actual BusinessObject behind the QVWComputer object.