How can i do to create an automated script to create a brand new host profile for each host on the vcenter...
Try something like this
ForEach-Object -Process {
New-VMHostProfile -Name "$($_.Name)-Profile" -Description "This is my test profile based on $($_.Name))." -ReferenceHost $_ -Confirm:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
i did this but not working
$vmhostline = ""
$vmhost = ""
Connect-VIServer XXXXXX -User administrator@vsphere.local -Password XXXXXX
foreach ($vmhost in $vmhostline) {
$vmhost = Get-VMHost | select name
New-VMHostProfile -Name $vmhost_"test1" -Description "This is my test profile based on $vmhost." -ReferenceHost $vmhost
}
What is not working?
Do you get an error message?
DO you have the required license to use HostProfiles?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
it have error
xxxxxxx 443 VSPHERE.LOCAL\Administrator
New-VMHostProfile : Cannot convert 'System.Object[]' to the type 'VMware.VimAutomation.ViCore.Types.V1.Inventory.VMHost' required by
parameter 'ReferenceHost'. Specified method is not supported.
At line:9 char:113
+ ... on "This is my test profile based on $vmhost." -ReferenceHost $vmhost
+ ~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-VMHostProfile], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.NewVMHostProfile
i`ve the right license----
Try something like this
ForEach-Object -Process {
New-VMHostProfile -Name "$($_.Name)-Profile" -Description "This is my test profile based on $($_.Name))." -ReferenceHost $_ -Confirm:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Great thx sir.. u da men!!!
Sir
how can i do if i want to read the hostnames directly from a file? appreciate your help----
If you have the nodenames, one per line, in .txt file, you could do
Get-VMHost -Name $esxNames |
ForEach-Object -Process {
New-VMHostProfile -Name "$($_.Name)-Profile" -Description "This is my test profile based on $($_.Name))." -ReferenceHost $_ -Confirm:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
sir....something it`s wrong --i got this error
Name Port User
---- ---- ----
9.45.252.139 443 VSPHERE.LOCAL\Administrator
Get-VMHost : 11/29/2019 5:31:44 AM Get-VMHost VMHost with name 'b02esx003.ciolab.ibm.com ' was not found using the
specified filter(s).
At G:\itss\hostprof2.ps1:13 char:1
+ Get-VMHost -Name $esxNames |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-VMHost], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVMH
ost
Get-VMHost : 11/29/2019 5:31:44 AM Get-VMHost VMHost with name 'b02esx004.ciolab.ibm.com ' was not found using the
specified filter(s).
At G:\itss\hostprof2.ps1:13 char:1
+ Get-VMHost -Name $esxNames |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-VMHost], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVMH
Are either of those values returned under the Name property when you do a Get-VMHost?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
got this error when i run the script-below is the code...thx in avance!!!
Connect-VIServer $vcenter -User $user -Password $password -ErrorAction Stop
$esxNames = Get-Content -Path '.\esxnames.txt'
Get-VMHost -Name $esxNames |
ForEach-Object -Process {
New-VMHostProfile -Name "$($_.Name)-Profile2" -Description "This is my test profile based on $($_.Name))." -ReferenceHost $_ -Confirm:$false
}
Disconnect-VIServer $vcenter
When you do a Get-VMHost (no parameters and after a Connect-VIServer), does the Name column show the same names that you have in your .txt file?
Could there be an extra blank at the end of a line?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
it seems a blank cause the error...it`s working now...thx a lot sir!!!!
You're welcome :smileygrin:
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference