supido
Goto Top

Powershell + Import VM bringt Fehlermeldung

Hallo zusammen,

ich bin etwas verwirrt, da ein PSScript mal funktioniert und mal nicht. Untenstehender Code ist teil eines längeren Scriptes.
Ich kopiere mit robocopy virtuelle Maschinen auf eine HYper-Server 2012 r2 core

Manchmal bekomem ich beim Import-VM die Fehlermeldung, das die VM nicht importiert werden kann, weil die Konfiguration nicht stimmt. Die Maschine lässt sich aber anschliessend von Hand ganz normal importieren und auch starten. Der übegebene Pfad scheint zu stimmen, sonst würde das Script ja nicht meckern, sonder sagen, das er die Maschine nicht findet.
Das ist das konfuse daran.
Kennt jemand das Problem, muss ich im Script etwas anders machen ?

Vielen Dank im Voraus
Gruss Supido


if (Test-Path -Path Y: -IsValid) 
	{		Clear-Host
		Write-Host "`n`tIn welcher Sprache sollen die VMs zur Verfügung stehen?`n`t" -ForegroundColor green  
		Write-Host "`t[D]" -ForegroundColor yellow -NoNewline  
		Write-Host " Deutsch"   
		Write-Host "`t[F]" -ForegroundColor yellow -NoNewline  
		Write-Host " Französisch"  
		Write-Host "`t[I]" -ForegroundColor yellow -NoNewline  
		Write-Host " Italienisch"  
		Write-Host "`t[Q]" -ForegroundColor yellow -NoNewline  
		Write-Host " Quit`n`t"  
		Write-Host "`tBitte Auswahl treffen " -NoNewline  
		Write-Host "und mit " -NoNewline  
		Write-Host "ENTER " -ForegroundColor yellow -NoNewline  
		write-Host "bestätigen."  
		switch($Input = Read-Host)
		{
			D {$Global:Path_VMFIL += "de\";robocopy $Global:Path_VMFIL $Global:Path_VM  }#DE  
			F {$Global:Path_VMFIL += "fr\";Copy-Item -Path $Global:Path_VMFIL -Destination $Global:Path_VM -Force -PassThru -Recurse}#FR  
			I {$Global:Path_VMFIL += "it\";Copy-Item -Path $Global:Path_VMFIL -Destination $Global:Path_VM -Force -PassThru -Recurse}#IT  
			Q {exit-pssession}#Installationsroutine abrechen
			default {
				""  
				write-host "Ungültige Eingabe" -ForegroundColor red  
				""}  
		} 
	}

	""  

$servertype = "20"  
Write-Host "Starte VMs"   
#Alle vorhandenen XML-Dateien der virtuellen Maschinen auflisten
$dir = (gci C:\vm\ -re -fi *.xml).FullName 
#VMs starten
foreach ($i in $dir)
{	$VmName = $i.ToString()
	$VmName.Trim()
	Import-VM –Path "$VmName"}  

Write-Host "$servertype"  
if ($servertype -ne 21) 
{
	foreach($VM in Get-VM) 
	{		Start-VM $VM.Name}
}
stop-VM template -asjob

Content-Key: 295763

Url: https://administrator.de/contentid/295763

Printed on: April 19, 2024 at 14:04 o'clock