I'm trying to convert a WMI based script to CIM, this script is able to inject an IP Address to an Hyper-V Virtual Mahine Original Script is : http://www.ravichaganti.com/blog/?p=2766
In my case, I've converted the WMI to CIM sentences like this:
$vmname="mytestvm"
$vm=get-ciminstance -namespace 'root\virtualization\v2' -Class 'Msvm_ComputerSystem' -ComputerName $ComputerName | Where-Object { $_.ElementName -eq $vmname }
$VMSettings = get-cimassociatedinstance $vm -resultclassname 'Msvm_VirtualSystemSettingData' | Where-Object { $_.VirtualSystemType
-eq 'Microsoft:Hyper-V:System:Realized' }
$vmnetadapters=get-cimassociatedinstance $vmSettings -resultclassname 'Msvm_SyntheticEthernetPortSettingData'
$NetworkSettings = @( Get-CimAssociatedInstance $vmnetadapters -resultclassname 'Msvm_GuestNetworkAdapterConfiguration' )
Until this point, all works fine, data is accessed and I'm able to see interface characteristics. But when I'll try to set a value like the original script does, I can't modify It, it tells me that property is set as Read Only.
These assignations doesn't work.
$NetworkSettings[0].DHCPEnabled = $false
$NetworkSettings[0].IPAddresses = $IPAddress
$NetworkSettings[0].Subnets = $Subnet
And when I check the object with "Get-Member" I could see that these properties only have "get" method, and "set" method is not available.
Name MemberType Definition
---- ---------- ----------
DefaultGateways Property string[] DefaultGateways {get;}
DHCPEnabled Property bool DHCPEnabled {get;}
DNSServers Property string[] DNSServers {get;}
InstanceID Property string InstanceID {get;}
IPAddresses Property string[] IPAddresses {get;}
IPAddressOrigins Property uint16[] IPAddressOrigins {get;}
ProtocolIFType Property uint16 ProtocolIFType {get;}
PSComputerName Property string PSComputerName {get;}
Subnets Property string[] Subnets {get;}
Original Script, that uses WMI is able to modify these values, but is not possible when I use CIM
According to Microsoft WMI and CIM should be equivalents, but seems that there are some differences.
How can I do it to modify these read-only properties using CIM sentences?
Thanks in advance.