-
Notifications
You must be signed in to change notification settings - Fork 33
Description
hi,
I'm new on github and on powershell.
I am testing to make a powershell script to create a VM.
I want the user to enter the size of disk with read-host command, and then the script creates the disk with the variable.
I do not have this problem with the size of ram.
I have tried many solutions but it does not work.
I do not know if it is a bug or if my knowledge of powershell is too bad.
thanks for help.
here is my beginner script
`#dossier de travail
#fichiers iso debian
#fichier preseed original
#script preseed creator
Write-Output "Vérification de la présence du module vmxtoolkit"
if (get-module -Name vmxtoolkit) {
Write-Output "module existe"}
else {Write-Output "module n'existe pas"
install-module vmxtoolkit -confirm :$false -force
Set-executionpolicy -executionpolicy Remotesigned -Scope Currentuser
import-module vmxtoolkit -force
}
$cpu=Read-Host "nombre de cpu désiré ?"
[int]$mem=Read-Host "quantité de mémoire désirée en Go ?"
[int]$mem=$mem1024
$disk = Read-Host "Taille du disque en Go ?"
$vmname = Read-Host "nom de la VM ?"
$diskname=$vmname + ".vmdk"
#sélection du fichier iso
Write-Output "Veuillez sélectionner le fichier ISO"
function Select-FileDialog
{
param([string]$Title,[string]$Directory,[string]$Filter="All Files (.)|.*")
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
$objForm = New-Object System.Windows.Forms.OpenFileDialog
$objForm.InitialDirectory = $Directory
$objForm.Filter = $Filter
$objForm.Title = $Title
$Show = $objForm.ShowDialog()
If ($Show -eq "OK")
{
Return $objForm.FileName
}
Else
{
Write-Error "Operation cancelled by user."
}
}
$iso = Select-FileDialog -Title "Select a file" -Directory "C:\Users\nicolas"
New-VMX -VMXName $vmname -GuestOS debian10-64 -Firmware EFI -Path C:\VM
New-VMXScsiDisk -NewDiskname $diskname -NewDiskSize $disk -VMXName $vmname -Path C:\VM$vmname
Add-VMXScsiDisk -Diskname C:\VM$vmname$diskname -VMXName $vmname -LUN 0 -Controller 0 -config C:\VM$vmname$vmname.vmx
Connect-VMXcdromImage -VMXName $vmname -ISOfile "$iso" -config C:\VM$vmname$vmname.vmx -Contoller sata -Port 0:0
Set-VMXNetworkAdapter -VMXName $vmname -Adapter 0 -ConnectionType nat -AdapterType e1000e -config C:\VM$vmname$vmname.vmx
Set-VMXmemory -MemoryMB $mem -config C:\VM$vmname$vmname.vmx
Set-VMXprocessor -Processorcount $cpu -config C:\VM$vmname$vmname.vmx
Start-VMX -VMXName $vmname -config C:\VM$vmname$vmname.vmx
exit`
