vmware


not able to rename computer at windows OS level using Invoke-VMScript command


I want to Create a VMware VM using New-VM command and rename the VM name (at windows level) accordingly as per the VM name.
Something like :
VM Name = 100-SVR01-Jack
Windows Host Name = Jack-100
Issue : I am not able to rename the computer to Jack-100 at windows level using Invoke-VMScript command , seems it it not able to pass newcomputername into the Invoke command . Can anyone help me on this ?
$ErrorActionPreference = "Stop"
Add-PSSnapin VMware.VimAutomation.Core
Connect-VIserver $vCenterName -user $vCenterUserName -password "Password01" -ErrorAction 'Stop'
$CID = '100'
$CName = "Jack"
$ComputerName1 = $CID + "-SVR01-" + $CName
$NewComputerName1 = "SVR01-" + $CID
$sourcetemplate = "BaseWin2012R2"
$description = "Jack System"
$OSCustomizationspec = "SVR01"
$InfraResourcePool = "Infra-ResourcePool"
Function Create-VM (ComputerName1 , $InfraResourcePool,$description,$sourcetemplate,$OSCustomizationspec ){
New-VM -Name $ComputerName1 -ResourcePool $InfraResourcePool -Datastore "datastore1" -Description $description -Template $sourcetemplate -OSCustomizationspec $OSCustomizationspec -DiskStorageFormat Thin
Start-VM -VM $ComputerName1
}
Function Set-Computername($ComputerName , $NewComputerName , $HostCredential , $GuestCredential) {
$RenameComputer = '$hostname = hostname
Rename-Computer -computername $hostname -newname $NewComputerName
RESTART-COMPUTER -force
'
Invoke-VMScript -VM $computername -HostCredential $HostCredential -GuestCredential $GuestCredential -ScriptText $RenameComputer
}
$HostCred = $Host.UI.PromptForCredential("Please enter credentials", "Enter Guest credentials for $computername", "root", "")
$GuestCred = $Host.UI.PromptForCredential("Please enter credentials", "Enter Guest credentials for $computername", "administrator", "")
Create-VM $Computername1 $InfraResourcePool $description $sourcetemplate $OSCustomizationspec;
Set-Computername $Computername1 $NewComputerName1 $HostCred $GuestCred
I typically use the mandatory parameter tags when defining functions: https://blogs.technet.microsoft.com/heyscriptingguy/2011/05/22/use-powershell-to-make-mandatory-parameters/
Doing that may help you pass the variable in properly. Also you may want to change your preferred error action in case you're not seeing everything.

Related Links

How to get all volumes attached with vm in vphere in java api?
Packer.io: Tag or Label VMWare instances (app/inventory management)
cannot access zabbix from web browser
Unable to deploy OpenStack for VMware - no datastore on selected cluster
not able to rename computer at windows OS level using Invoke-VMScript command
vmware disk activity (read) never stop, after start read file inside Virtual Machine(ubuntu)
Unable to create a VM in Terraform
Deployment ESXi VM Machine in Google Cloud Platform without migration
Do I need to install VMWare drivers to create a VMWare image using packe vmware-isor?
How to clone a VM when working with vSAN insead of local disks
How to install mac OS X EICapitan on windows 10
vmware esxi 5.5 iscsi gpt repair
VMware Fusion multiple static IPs
I need to create to Redundant VMs (both on 2 different datastores) via function
Attribute error while using vim.VimVsanReconfigSpec in pyvmomi
vmware not open .vmdk file mac os x

Categories

HOME
isabelle
json.net
hp-exstream
raspberry-pi
session
spagobi
jsp-tags
spring-cloud-stream
mouse
multiple-records
esper
medical
ssl-client-authentication
quicklook
quickbooks
circuit
netflix
serverless-framework
workload-scheduler
seaborn
apache-metamodel
code-review
custom-wordpress-pages
css-animations
kudan
zurb-foundation-6
saas
kendo-datasource
sql-server-2012-express
directx-10
ecto
key-value-observing
asset-pipeline
android-ble
overlap
dosbox
ruby-on-rails-3.1
gulp-sourcemaps
elmah
keydown
menuitem
zip4j
tizen-native-app
colorama
libusb-win32
typed-lambda-calculus
font-size
angular-cache
instant
django-debug-toolbar
xml-attribute
paypal-express
ubuntu-10.04
qcustomplot
master-slave
php-parse-error
jfugue
tcpserver
vhd
dukescript
event-bubbling
operation
clipperlib
inmobi
lustre
facebook-graph-api-v2.4
tween
gadt
angularjs-ng-click
android-imagebutton
mdt
castle
xceed-datagrid
message-driven-bean
uv-mapping
jsctypes
commoncrypto
dir
tws
interface-orientation
android-hardware
robotics-studio
bitsharp
funscript
frameset
errai
getmessage
gwt-ext
stage
zpt
appender
appendto
yui-datatable
subviews
h.323
wise
perfect-hash
firefox-5
web-architecture
javap
phonon
pascal-fc
scripting-languages
w3wp

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App