Hello all,
I need to do a GUI to use OVF Tools for the Service.
So i have done the GUI with PrimalForm and add my script to the Generate Code.
I have just keep on the script below the part of My script and not the Generate code by PrimalForm.
#Generated Form Function
function GenerateForm {
########################################################################
# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.10.0
# Generated On: 25/10/2019 10:49
# Generated By: A0001668-r
########################################################################
#----------------------------------------------
#Generated Event Script Blocks
#----------------------------------------------
#Provide Custom Code for events specified in PrimalForms.
$button1Password_OnClick=
{
$Account = $textBox1Username.Text
$Credential = (Get-Credential "$Account")
$String = $Credential.Password | ConvertFrom-SecureString
$Password = ConvertTo-SecureString -string "$String"
$Credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList ($Account, $Password)
$password_converted = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password))
Connect-CIServer -server rgsflexvr33.airsystems.thales -Credential $Credentials
}
Add-pssnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
#Variables :
$vCloudURL1="choice1"
$vCloudURL2="Choice2"
$vOrg1="choice1"
$vOrg2="choice2"
$OvDC1="choice1"
$OvDC2=""
$Catalogue1="Catalogue_Archivage"
$Catalogue2="Catalogue_Developpement"
$Catalogue3="Catalogue_Integ_Valid"
$Catalogue4="Catalogue_FlexVR33_Dev"
$Catalogue5="Catalogue_FlexVR33_IntVal"
$comboBox1vCloudURL.Items.Add($vCloudURL1)
$comboBox1vCloudURL.Items.Add($vCloudURL2)
$comboBox2OrgvCloud.Items.Add($vOrg1)
$comboBox2OrgvCloud.Items.Add($vOrg2)
$comboBox3Catalogue.Items.Add($Catalogue1)
$comboBox3Catalogue.Items.Add($Catalogue2)
$comboBox3Catalogue.Items.Add($Catalogue3)
$comboBox3Catalogue.Items.Add($Catalogue4)
$comboBox3Catalogue.Items.Add($Catalogue5)
$comboBox1OvDC.Items.Add($OvDC1)
$button2_OnClick=
{
# Build the vCloud Connection String
Set-Location "C:\Program Files\VMware\VMware OVF Tool"
$username= $textBox1Username.Text
$zone= $comboBox1vCloudURL.Text
$vCD_ORG= $comboBox2OrgvCloud.Text
$vDC= $comboBox1OvDC.Text
$catalog= $comboBox3Catalogue.Text
$vApp= [string]$textBox5NomvApp.Text
$OVA= [String]$textBox7DirectoryOVA.Text
New-Item -ItemType file "x:\GenerateCode.txt"
Add-Content "x:\GenerateCode.txt" $username
Add-Content "x:\GenerateCode.txt" $zone
Add-Content "x:\GenerateCode.txt" $vCD_ORG
Add-Content "x:\GenerateCode.txt" $vDC
Add-Content "x:\GenerateCode.txt" $catalog
Add-Content "x:\GenerateCode.txt" $vApp
Add-Content "x:\GenerateCode.txt" $OVA
#Add-Content "x:\GenerateCode.txt" $password_converted
$vCloud="vcloud://${username}:${password_converted}@${zone}:443?org=${vCD_ORG}&vdc=${vDC}&vappTemplate=${vApp}&catalog=${catalog}"
$app = ".\ovftool.exe"
$arg1 = $vCloud
$arg2 = $OVA
#TODO: Place custom script here
& $app $arg1 $arg2
}
$button4_OnClick=
{
#TODO: Place custom script here
}
$handler_form1_Load=
{
#TODO: Place custom script here
}
$handler_label4_Click=
{
#TODO: Place custom script here
}
$button5_OnClick=
{
#TODO: Place custom script here
}
$button3_OnClick=
{
#TODO: Place custom script here
}
$handler_label1_Click=
{
#TODO: Place custom script here
}
$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
}
#----------------------------------------------
#region Generated Form Code
When i execute the script, after make all the choices in the combobox, I clic on the button "Export OVA" "Button2",
But at this moment, vcloud ask us to enter the Password again.
How it is possible to enter the password with a Get-Credential Interface for example ?
I suspect this might be a scope issue.
You do a Connect-CIServer in the code block attached to the $button1Password_OnClick event.
That connection is probably not passed to the $button2_OnClick code block.
You could check what is in the $global:DefaultCIServers variable in the $button2_OnClick block.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello LuCD ^^,
And thx for your reply
The things i have done :
Fisrt i make the variable $Credentials to be $Global:Credentials
And i insert the line Connect-CIServer -server.... in the button2.
When i run the script and push the button2, the script is waiting something.
I can't do anythings else.
I have check the Connect-CIServer, when i execute the line i'm connect to the vCloud.
Before this script i have done this script and what ever i'm connected to the CI Server, it's still ask me the password :
#
# Adding the PowerCLI Modules
$FilePath = "\\phy\admin\scripts\Crypt"
$File = "$FilePath\crypt-2-.txt"
$Account = "t0010081"
$String = Get-Content $File
$Password = ConvertTo-SecureString -string $String
$Credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList ($Account, $Password)
Connect-CIServer -server rgsflexvr33.airsystems.thales -Credential $Credentials
Add-pssnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
# Get the arguments needed for the OVFTOol to Connect and Download the vApp
$Dir= pwd
#Entrée des Crédentials
$username = Read-Host "Compte"
$password= Read-Host "Password" -AsSecureString
#Convert Secure Password
$password_converted = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))
#Import ou Export de Template ou vApp ?
Write-Host ""
Write-Host "Que souhiatez vous faire ?"
Write-Host "1 pour Importer Template"
Write-Host "2 pour Exporter Template"
Write-Host "3 pour convertir un ovf en ova"
Write-Host ""
$Operation= Read-Host "Sélectionner l'opération souhaitée !"
Write-Host ""
#Conversion OVF en OVA
If($Operation -like "3"){
$OVF= Read-Host "Taper le chemin et nom du fichier OVF"
$OVA= Read-Host "Taper le chemin et nom du fichier OVA"
$app = ".\ovftool.exe"
$arg1 = $OVF
$arg2 = $OVA
& $app $arg1 $arg2
Exit
}
# Sélection du vCloud EF3.2 ou EF3.3 (vCLOUD_URL)
Write-Host ""
Write-Host "Sélection du vCloud_URL: EF3.2 ou EF3.3 ?"
Write-Host "1 pour EF3.2"
Write-Host "2 pour EF3.3"
Write-Host ""
$answer= Read-Host "Selectionner le vCloud"
Write-Host ""
Switch($answer){
"1" {$zone= "rgsflexvr32.airsystems.thales"}
"2" {$zone= "rgsflexvr33.airsystems.thales"}
}
#Sélection automatique Organisation
Switch($zone){
"rgsflexvr32.airsystems.thales"{$vCD_ORG= "TR6-RGS-FlexVR32"}
"rgsflexvr33.airsystems.thales"{$vCD_ORG= "LAS-RGS-FlexVR33"}
}
#Sélection Semi-automatique de l'OvDC
If($vCD_ORG -like "TR6-RGS-FlexVR32"){
Write-Host ""
Write-Host "Sélection de l'OvDC"
Write-Host "1 pour OvDC_FlexVR32_DEVELOP"
Write-Host "2 pour OvDC_FlexVR32_INTEG-VALID"
Write-Host ""
$answer= Read-Host "Sélectionner l'OvDC"
Write-Host ""
Switch($answer){
"1"{$vDC="OvDC_FlexVR32_DEVELOP"}
"2"{$vDC="OvDC_FlexVR32_INTEG-VALID"}
}
}
If($vCD_ORG -like "LAS-RGS-FlexVR33"){
$vDC= "OvDC-FlexVR33"
}
#Sélection du Catalogue
If($vCD_ORG -like "TR6-RGS-FlexVR32"){
Write-Host ""
Write-Host "Sélection du Catalogue du Template"
Write-Host "1 pour Catalogue_Archivage"
Write-Host "2 pour Catalogue_Developpement"
Write-Host "3 pour Catalogue_Integ_Valid"
Write-Host ""
$answer= Read-Host "Sélectionner le catalogue"
Write-Host ""
Switch($answer){
"1" {$catalog= "Catalogue_Archivage"}
"2" {$catalog= "Catalogue_Developpement"}
"3" {$catalog= "Catalogue_Integ_Valid"}
}
}
If($vCD_ORG -like "LAS-RGS-FlexVR33"){
Write-Host ""
Write-Host "Sélection du Catalogue du Template"
Write-Host "1 pour Catalogue_FlexVR33_Dev"
Write-Host "2 pour Catalogue_FlexVR33_IntVal"
Write-Host ""
$answer= Read-Host "Sélectionner le catalogue"
Write-Host ""
Switch($answer){
"1"{$catalog= "Catalogue_FlexVR33_Dev"}
"2"{$catalog= "Catalogue_FlexVR33_IntVal"}
}
}
#Entrée du nom de la vApp ou Template a
$vApp= Read-Host "Donner le nom du Template / vApp"
#Entrée du chemin et nom de l'OVA
$OVA= Read-Host "Chemin et nom du fichier Source / estination OVA"
# Build the vCloud Connection String
$vCloud="vcloud://${username}:${password_converted}@${zone}:443?org=${vCD_ORG}&vdc=${vDC}&catalog=${catalog}&vappTemplate=${vApp}"
#Build the vCloud Connection String to Hide Password
$vCloud2="vcloud://${username}:*******@${zone}:443?org=${vCD_ORG}&vdc=${vDC}&vapp=${vApp}&catalog=${catalog}"
write-host "vCloud Connection String" $vCloud2 -ForegroundColor Yellow
# Set the OVFTool EXE and execute it with some arguments
Set-Location "C:\Program Files\VMware\VMware OVF Tool"
#Execution du script selon le type d'opération & Build the vCloud Connection String
$app = ".\ovftool.exe"
$arg1 = $vCloud
$arg2 = $OVA
If($Operation -like "1"){
$vCloud="vcloud://${username}:${password_converted}@${zone}:443?org=${vCD_ORG}&vdc=${vDC}&catalog=${catalog}&vappTemplate=${vApp}"
& $app $arg2 $arg1
}
ElseIf($Operation -like "2"){
$vCloud="vcloud://${username}:${password_converted}@${zone}:443?org=${vCD_ORG}&vdc=${vDC}&catalog=${catalog}&vappTemplate=${vApp}"
& $app $arg1 $arg2
}
Set-location $Dir.Path
read-host "Appuyer sur Enter pour sortir"
This script work's fine.
So it's seem's the problème is somethings else.
You are probably getting a prompt in de button code, and since there is no console attached, the code hangs.
When you just run the following, do you also get a prompt?
$File = "$FilePath\crypt-2-.txt"
$Account = "t0010081"
$String = Get-Content $File
$Password = ConvertTo-SecureString -string $String
$Credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList ($Account, $Password)
Connect-CIServer -server rgsflexvr33.airsystems.thales -Credential $Credentials
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I don't understand, the variable $Global:DefaultCIServers exist ?
How can i check it ?
No at this step it's ok.
I'm just connected to the CIServer.
At last, i get the prompt when i run the line :
& $app $arg1 $arg2
Write it to a file, or use Start-Transcript.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ok i add the Transcript.
And perhaps also run the following before starting your script, to see what is happening.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Transcript:
**********************
Transcript started, output file is x:\Transcript.txt
Name User Org
---- ---- ---
rgsflexvr33.airsystems.thales t0010081 System
Que souhiatez vous faire ?
1 pour Importer Template
2 pour Exporter Template
3 pour convertir un ovf en ova
Sélection du vCloud_URL: EF3.2 ou EF3.3 ?
1 pour EF3.2
2 pour EF3.3
Sélection du Catalogue du Template
1 pour Catalogue_FlexVR33_Dev
2 pour Catalogue_FlexVR33_IntVal
vCloud Connection String vcloud://T0010081:*******@rgsflexvr33.airsystems.thales:443?org=LAS-RGS-FlexVR33&vdc=OvDC-FlexVR33&vapp=MCO_2019_Test_VXLAN_org_Adm_Tpl&catalog=Catalogue_FlexVR33_Dev
Enter login information for source vcloud://rgsflexvr33.airsystems.thales/LAS-RGS-FlexVR33
Username: T0010081
Password: **********
Opening vCloud source: vcloud://T0010081@rgsflexvr33.airsystems.thales:443/
Waiting for task on server ...
Terminate process signal received - aborting operation...
PS>TerminatingError(): "The pipeline has been stopped."
>> TerminatingError(): "The pipeline has been stopped."
>> TerminatingError(): "The pipeline has been stopped."
It's seem's the Powershell/PowerCLI session is different to the OVF Session, so OVF ask me again the password.
I will try with PowerCLI without OVF Tools.
But if we have an idea , i will take it
Have a nice Week-End
That sounds logical, the ovftools command has no knowledge of the connection you made in PowerCLI.
You can pass the user and password on the command.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello LucD ^^
How are you ? Week End was fine i hope !
Yes we could passthe password but via command line....so i'm fucked for this script with OVF Tools.
So i'm making another script in PowerCLI
I was thinking, before that the PowerCLI have not command for Export and Import because, The VMware Support send me directly to the OVF Tool, but No there is some command and it's so much easy ^^
I will send you the script with GUI when i will have finish.
Have a good Evening LucD
Lol....I'm shame !
After finish the script i just realise that the command Export-VApp is just for Vapp but certainly not for a Vapp Template....
If someone is interest by it:
###########################################
### Import / Export de Template ###
### Conversion de fichier OVF / OVA ###
### Créer en PowerCLI ###
###########################################
$Account = "T0010081"
$Credential = (Get-Credential "$Account")
$String = $Credential.Password | ConvertFrom-SecureString
$Password = ConvertTo-SecureString -string "$String"
$Credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList ($Account, $Password)
$password_converted = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password))
################################
### Funtions Principales ###
################################
### Choix EF ###
Function EF(){
Write-Host "Sur quel EF voulez-vous vous connecter ? :"
Write-Host "1 pour EF3.2"
Write-Host "2 pour EF3.3"
$answer= Read-Host "Selectioner l'EF"
Switch($answer){
"1" {$zone= "rgsflexvr32.airsystems.thales"}
"2" {$zone= "rgsflexvr33.airsystems.thales"}
}
Connect-CIServer -server $zone -Credential $Credentials
}
### Export vApp ###
Function Export(){
#Selection du Nom du Template, fichier Source / Format et Destination
$vApp = Read-Host "Quel est le nom du Template "
$Dest = Read-Host "Quel est le nom du fichier OVF / OVA de destination ? "
$FormExp = Read-Host "OVA ou OVF ?"
$vApp = Get-CIVAppTemplate $vApp
#Export du Template
Export-VApp -VApp "$vApp" -Destination $Dest -Format $FormExp
}
### Import vApp ###
Function Import(){
#Recherche des Organisations et choix
$vOrg= Get-OrgVdc
$i= 0
Write-Host "Selection de l'Organisation"
$nbO= $vOrg.count
While($i -le $nbO-1){
Write-Host "$i pour "$vOrg[$i]
$i++
}
Write-Host " "
$answer = Read-Host "Selection de l'Organisation "
Switch($answer){
$answer {$Org= $vOrg[$answer]}
}
Write-Host " "
$OrgS = $vOrg[$answer]
# Recherche des Catalogues et choix
$Catalog = @()
$i= 0
Write-Host "Import Template OVF dans un Catalogue"
$Catalog = Get-Catalog
$nbC = $Catalog.count
While($i -le $nbC-1){
Write-Host "$i pour "$Catalog[$i]
$i++
}
Write-Host " "
$answer = Read-Host "Selectionner le Catalogue "
Switch($answer){
$answer {$Cata = $Catalog[$answer]}
}
Write-Host " "
$CatS = $Catalog[$answer]
#Selection du fichier Source
Write-Host ""
$answer = Read-Host "Selection du chemin et fichier OVF / OVA"
$FileS = $answer
#Nom du Template Importé
Write-Host ""
$answer = Read-Host "Nom du nouveau Template"
$NomTS = $answer
#Import du Template
Import-CIVAppTemplate -SourcePath $FileS -Name $NomTS -OrgVdc $OrgS -Catalog $CatS
}
### Convert OVF / OVA ###
Set-Location "C:\Program Files\VMware\VMware OVF Tool"
$app = ".\ovftool.exe"
#Convert OVF to OVA
Function ConvertOVF(){
$OVF = Read-Host "Chemin et nom du fichier OVF"
$OVA = Read-Host "Chemin et nom du fichier OVA"
& $app $OVF $OVA
}
#Convert OVA to OVF
Function ConvertOVA(){
$OVF = Read-Host "Chemin et nom du fichier OVA"
$OVA = Read-Host "Chemin et nom du fichier OVF"
& $app $OVA $OVF
}
### Menu ###
Write-Host "1. Import"
Write-Host "2. Export"
Write-Host "3. Convertion OVF vers OVA"
Write-Host "4. Convertion OVA vers OVF"
$answer = Read-Host "Que voulez-vous faire ?"
If($answer -eq "1"){
EF
Import
}
ElseIf($answer -eq "2"){
EF
Export
}
ElseIf($answer -eq "3"){
EF
ConvertOVF
}
ElseIf($answer -eq "4"){
EF
ConvertOVA
}
So there is just...OVF Tool and we just can use it by command line.