VMware Cloud Community
RocasYeh
Contributor
Contributor

Any way to simplify the installation process of vPowerCLI and make it able to be automated?

Hello,

I want to make the work of network configuration automated. Then I found vPowerCLI is a useful tool.

The following is my script:


## use Invoke-VMScript cmdlet(and remote netsh) to set up IP configurations

$IP = "10.144.1.1"

$SNM = "255.255.255.0"

$GW = "10.144.1.254"

$netsh = "c:\windows\system32\netsh.exe interface ip set address ""Mgmt"" static $IP $SNM $GW 1"

$vm = Get-VM -Name 'myVM'

$user = "administrator"

$pw = "password"

Write-Host "Setting IP address for $VM..."

Invoke-VMScript -VM $vm -GuestUser $user -GuestPassword $pw -ScriptType bat -ScriptText $netsh

Write-Host "Setting IP address completed."

However, I have to install the whole installation process of vPowerCLI before using Invoke-VMScript cmdlet.

That is a trouble for me to pack my installation wizard which will copy the OVA files to local host, import VMs to vCenter(use ovftool) and modify the network configuration of VMs.

Briefly, Invoke-VMScript is the key cmdlet, and I want to find a simple way to use it in my installation process.

0 Kudos
6 Replies
LucD
Leadership
Leadership

You can use the GuestProcessManager API, they allow starting and monitoring applications in a guest.

But, without PowerCLI installed, you will have to set up the complete framework yourself.

Why is installing PowerCLI once on a specific station a problem ?

You do it once, and then from there you can automate the process for all the VMs you want to create.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
RocasYeh
Contributor
Contributor

Because the installation process of vPowerCLI is too complex and I don't want my user to see the step.

Is it possible that I just copy some necessary files and I could also run vPowerCLI(Invoke-VMScript cmdlet) normally?


Take importing VMs as an example.


At first, I installed ovftool, and I can pack these files into installation wizard(made by InstallShield).


I also wrote some scripts to use these files(ovftool) to import VMs automatically.


Users could just click the wizard which will extract these necessary files and run the scripts to import the VM they choose.

0 Kudos
LucD
Leadership
Leadership

You can install PowerCLI silently, see Silent installation of PowerCLI into a custom directory

The user will not see anything.

And no, it's not possible to just copy some files.

But I still don't see why you need to install PowerCLI each time ?

Perhaps I don't understand the environment and what you are trying to do ?

You can install PowerCLI on a dedicated station, and then run your scripts (remotely) on that station.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

RocasYeh
Contributor
Contributor

Oh, my main goal is a single installation wizard. Users could just select the VMs they want and the wizard would prepare for them.

Hence, I would like to simplify the steps of vPowerCLI preparation and make the three things of copying OVA files, importing VMs and modifying network configuration able to work together under the wizard.

0 Kudos
LucD
Leadership
Leadership

I understand that, but my point is that the part that uses PowerCLI doesn't actually have to run on the user's station.

It can be run remotely on a station where you already have PowerCLI installed.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
RocasYeh
Contributor
Contributor

Yup, that would be easier. However, the actual environment of the users could be under LAN and in another country...

My job is making them able to deploy necessary customized VMs easily.

The feasible strategy now is requiring the users to install PowerCLI(or make the install process automatic and silent under my wizard) and my wizard will run the following script to configure network.

powershell

Add-PSSnapin VMware.VimAutomation.Core

## use Invoke-VMScript cmdlet(and remote netsh) to set up IP configurations

$server = "10.144.1.1"

$user = "admin"

$pw = "pw"

$IP = "10.144.1.2"

$SNM = "255.255.255.0"

$GW = "10.144.1.254"

$netsh = "c:\windows\system32\netsh.exe interface ip set address ""Mgmt"" static $IP $SNM $GW 1"

Connect-VIServer -Server $server -user $user -password $pw

$vm = Get-VM -Name "myVM"

Write-Host "Setting IP address for $VM..."

Invoke-VMScript -VM $vm -GuestUser $user -GuestPassword $pw -ScriptType bat -ScriptText $netsh

Write-Host "Setting IP address completed."

0 Kudos