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

Is there a way (in Vmware) to open a Host-file with a Guest App from the Host computer?
Openstack with vmware esxi as hypervisor?
Port forwarding to a VMware machine via iptables
Installing VMWare tools
updating tizen-2.1 on test device
Server of VMWare virtual machines [closed]
Gwan dies every day and consume a lot of ressources
How to WaitForUpdates from VMs in a cluster?
Getting VMWare DataStore inventory data (inventory traversal)
Vmware Powecli Alarm trigger
powercli set-networkadapter object reference not set to an instance of an object
Race condition for USB devices with Multiple VMs
Automated Send Keys Failing When No RDP
Free VM with management API that runs on windows?
Access Internet from BB10 simulator
CPU ID in VMware environment

Categories

HOME
maven
bluetooth
netbeans
keycloak
read-eval-print-loop
routes
getelementsbytagname
add
facebook-messenger-bot
slurm
cloudkit
spring-kafka
spring-xd
php-7.1
hex-editors
event-handling
quickfix
hapi
highlight.js
autocad-plugin
paging
orleans
graphicsmagick
web-sql
claims-based-identity
fish
underflow
apache-commons-io
wpfdatagrid
user-interaction
compatibility
kendo-datasource
bluestacks
directx-10
bosh
xquery-3.0
uisplitview
hybridauth
nssegmentedcontrol
bytecode-manipulation
suricata
git-merge
email-templates
galen
isbn
http-redirect
qwt
long-polling
celery-task
rdfs
namecoin
sqlbulkcopy
jspdf-autotable
redundancy
crosswalk-runtime
color-picker
angular-cache
xml-attribute
simplewebrtc
prettytensor
goose
cannon.js
tableau-online
appfabric-cache
generic-programming
sortedlist
javax.mail
npapi
nsmutabledictionary
sorl-thumbnail
clicktag
tablelayout
gui-test-framework
phalanger
xcode-6.2
mesa
starcluster
resty-gwt
concurrent-collections
intentservice
soundtouch
coverflow
tws
ril
eventual-consistency
type-equivalence
clipper
funscript
dotnethighcharts
removeclass
spyware
hirefire
django-tagging
rfc1123
calling-convention
pyinotify
gdlib
radcombobox
visitor-statistic
cxxtest
h.323
bespin
thunderbird-lightning
database-management
adrotator
xetex
project-hosting
msdev
caching-application-block
document-conversion

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