VMware Cloud Community
Tanaris
Contributor
Contributor
Jump to solution

powercli set hostname

i use this command to set hostname

$esx = Get-VMHost

$hostnamearray = $esx.name.split(",")

$hostname = $hostnamearray[0]

$n='LOCAL'+ $hostnamearray

Get-VMHostNetwork -VMHost $esx | Set-VMHostNetwork -HostName $hostname

1.PNG

i get the hostname is:test192.168.50.180,i wan't set the hostname like test-50-180,help me please!

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could do something like this

$esx = Get-VMHost

$nameArr = @('test')

$nameArr += $esx.Name.split('.')[2..3]


Get-VMHostNetwork -VMHost $esx |

Set-VMHostNetwork -HostName ($nameArr -join '-')


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

View solution in original post

4 Replies
scott28tt
VMware Employee
VMware Employee
Jump to solution

Moderator: Thread moved to the PowerCLI area.


-------------------------------------------------------------------------------------------------------------------------------------------------------------

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
0 Kudos
Tanaris
Contributor
Contributor
Jump to solution

thanks

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You could do something like this

$esx = Get-VMHost

$nameArr = @('test')

$nameArr += $esx.Name.split('.')[2..3]


Get-VMHostNetwork -VMHost $esx |

Set-VMHostNetwork -HostName ($nameArr -join '-')


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

Tanaris
Contributor
Contributor
Jump to solution

it works ,thanks for helping me!

0 Kudos