Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 251579

Re: Answer file for host profile questions

$
0
0

Luc,

  Following your guide I have come up with this, but have a couple questions. Excuse the formatting it didn't paste in as expected

 

1.  What is the reasoning for the Switch statement for the hash table to create a new one with keys?  Can I not do something like a wild card to modify the existing hashtable? $AdditionalConfiguration['network.dvsHostNic["*management*.address'] = $data.mgmtip and just set.

2.This pipelien command is not working and i get this error

Apply Profile to host.blah.com

Set-VMHost : The input object cannot be bound to any parameters for the command either because the
command does not take pipeline input or the input and its properties do not match any of the
parameters that take pipeline input.
At U:\powercli\hostprofile\hostprofile.ps1:50 char:107
+ ... nfirm:$false | Set-VMHost -State 'Connected' | Test-VMHostProfileCompliance
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (System.Collections.Hashtable:PSObject) [Set-VMHost
   ], ParameterBindingException
    + FullyQualifiedErrorId : InputObjectNotBound,VMware.VimAutomation.ViCore.Cmdlets.Commands.Set
   VMHost

 

 

FUll script below

 

#Import spreadsheet with hostname,mgmtip,mgmtsubnet,vmoip,vmosubnet for 1000v DVS input

$answerfile=Import-CSVProfileAnswers.csv

#Loop through each row and apply host profile

foreach

($datain$answerfile)

{

 

#Set VMhost variable to be able to pipe objects

 

$VMhost=Get-VMhost$data.hostname

 

 

Write-Host"Starting $VMhost.name"

 

 

#Attach host profile to host

 

Apply-VMHostProfile-profile$data.profile -entity$VMhost-AssociateOnly-confirm:$false | Out-Null

 

 

#Get hash table for ansfer file and assign to configuraiton

 

Write-Host"Getting Hash Table Answer File"

 

$AdditionalConfiguration=Apply-VMHostProfile-profile$data.profile -entity$VMHost-ApplyOnly-confirm:$false

 

#example below for variable names to create new hash table based on wildcards. Will remove in future iteration

 

#$AdditionalConfiguration['network.dvsHostNic["key-vim-profile-host-DvsHostVnicProfile-SVD-VSM03-dell-management-management"].ipConfig.IpAddressPolicy.address'] = $data.mgmtip

 

#$AdditionalConfiguration['network.dvsHostNic["key-vim-profile-host-DvsHostVnicProfile-SVD-VSM03-dell-management-management"].ipConfig.IpAddressPolicy.subnetmask'] = $data.mgmtsubnet

 

#$AdditionalConfiguration['network.dvsHostNic["key-vim-profile-host-DvsHostVnicProfile-SVD-VSM03-dell-vmotion-vmotion"].ipConfig.IpAddressPolicy.address'] = $data.vmoip

 

#$AdditionalConfiguration['network.dvsHostNic["key-vim-profile-host-DvsHostVnicProfile-SVD-VSM03-dell-vmotion-vmotion"].ipConfig.IpAddressPolicy.subnetmask'] = $data.vmosubnet

 

 

 

#Switch Statement to read in hash table and then set keys for Vmotion IP and Management IP on DVS

 

$var= @{}

 

switch ($AdditionalConfiguration.GetEnumerator())

{

{

$_.name -like'*management*.address' } {

 

$var+= @{$_.Name =$data.mgmtip}

}

{

$_.name -like'*management*.subnetmask'} {

 

$var+= @{$_.Name =$data.mgmtsubnet}

}

{

$_.name -like'*vmotion*.address'} {

 

$var+= @{$_.Name =$data.vmoip}

}

{

$_.name -like'*vmotion*.subnetmask'} {

 

$var+= @{$_.Name =$data.vmosubnet}

}

 

#Default {

 

#$value = Read-Host "Please provide a value for ${$_.Name}"

 

# $var +=@{$_.Name = $value}

 

# }

}

 

#Set Host in maintenance mode, apply profile with answer file, exit maint, test for compliance

 

Write-Host"Apply Profile to $VMHost"

 

Set-VMHost-VMHost$VMhost-State'Maintenance' | Apply-VMHostProfile-Variable$var-Confirm:$false | Set-VMHost-State'Connected' | Test-VMHostProfileCompliance

}

 

 


Viewing all articles
Browse latest Browse all 251579

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>