Quantcast
Channel: Hyper-V forum
Viewing all articles
Browse latest Browse all 19461

looking fo a simple VM Import Script to Hyper-V

$
0
0

Hello everybody

In our company enviroment, we do offer Microsoft Learning Kurses. We deploy the whole Course Infrastructure thru an deployment tool like SCCM.
The Microsoft Learning Products come with Hyper-V VM's and if you don't use an Imaging tool like cloneZilla, you have to import every VM manually in Hyper-V.
But if you have many students and you have to do this on every single machine, it takes a lot of time.

Now iam looking for a script, wich import or add every Microsoft Learning VM to the Hyper-V Manager automatically.... I have tryed a lot of them ps1 stuff, but nothing is working fine for example this script:

Param ($ModulePath = ($env:psmodulePath -split ";")[1],$ModuleName = "HyperV",$path = "C:\Program Files\Microsoft Learning\10267\Drives\10267A-GEN-DEV\")            
 #Copy the HyperV module if it doesn't already exist
 if(!((Dir $ModulePath) -match $ModuleName)) {Copy-Item .\$ModuleName $ModulePath -Recurse}             

 #Import the HyperV module if not already imported
 if(!(Get-Module | Where{$_.Name -like $ModuleName})) {Import-Module $ModuleName}            

 #Create array to contain active VM's
 $ActiveVMs = Get-VM | Foreach{$_.ElementName}            

 #Create array to contain VM's to be imported
 $VMsToImport = ( Get-ChildItem $path ) | Foreach{$_.Name}
 [regex]$ActiveVMs_Regex = '(?i)^('+(($ActiveVMs |
        Foreach {[regex]::Escape($_)})-join "|" )+')$'            

 #Import the VMs            
 $VMsToImport -notmatch $ActiveVMs_Regex |             
        Foreach{ Import-VM ( Join-Path $path $_ )             
        Start-Sleep 5}

The funny thing is, you don't get an error and it is doing that after run the script:

\\TESTTR\root\virtualization:Msvm_ConcreteJob.InstanceID="2E60921B-95B4-4CF8-A04C-1ACFB66CCA2E"
\\TESTTR\root\virtualization:Msvm_ConcreteJob.InstanceID="A3315731-B9C8-42CB-BA8A-F289BBC08F31"
\\TESTTR\root\virtualization:Msvm_ConcreteJob.InstanceID="22C78488-BE5C-4C34-986C-C190885FCDA8"

But after, nothing happend in my Hyper-V manager, the Virtual Machine Pane is still empty!!!!
What is here going wrong? or has someone a script for a simple VM import from example Location "C:\Microsoft Learning" into the Hyper-V manager?????


Viewing all articles
Browse latest Browse all 19461

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>