简体   繁体   English

使用csv文件中的PowerCLI强化VM-HOST Set-AdvancedSetting

[英]Hardening VM-HOST Set-AdvancedSetting with PowerCLI from csv file

I would like to automate the configuration of the first HOST to create the Host Profiles with PowerCLI. 我想自动配置第一个主机,以使用PowerCLI创建主机配置文件。 I built the first HOST in ESXi 6.5 and did the fist Host Profiles from that HOST. 我在ESXi 6.5中构建了第一个HOST,并从该HOST中获得了第一个主机配置文件。 But to create the first Host Profiles, I did a Edit Host Profiles line by line and it take so long. 但是要创建第一个主机配置文件,我逐行进行了一个“编辑主机配置文件”,这花费了很长时间。 We have over 60 diffrents clusters and that means I will have to create one Host Profiles per Cluster. 我们有60多个不同的集群,这意味着我必须为每个集群创建一个主机配置文件。

I did an export from the first Host with PowerCLI with this line 我通过此行从第一台主机使用PowerCLI进行了导出

Get-AdvancedSetting -Entity $HOST65 | Export-Csv -Path T:\_Evergreening_\Script\$clHOSTprofile-config.csv -NoTypeInformation

I got this in the csv file (Header) 我在csv文件中获得了此文件(标题)

Uid Value   Description Type    Entity  Id  Name    Client

I would to use the CSV file for a Set-AdvancedSetting using Name and Value column 我将使用“名称和值”列的CSV文件进行Set-AdvancedSetting

Get-AdvancedSetting -Entity $HOST65 -Name 'from_csv_file' | Set-AdvancedSetting -Value 'from_csv_file'

I'm not sure how to set this ... 我不确定如何设置...

Checkout 'Import-Csv' 结帐“导入Csv”

You could do something like: 您可以执行以下操作:

# Obtain and export Advanced Settings from a specified host
Get-AdvancedSetting -Entity $HOST65 | Export-Csv -Path T:\_Evergreening_\Script\$clHOSTprofile-config.csv -NoTypeInformation

# Import CSV file into a PowerShell array object
$csvInputs = Import-Csv -Path T:\_Evergreening_\Script\$clHOSTprofile-config.csv

# Create a loop to address each item of the array, sourcedfrom the CSV 
foreach ($csvInput in $csvInputs) {

     # Obtain and set the individual advanced setting on a specified host
     Get-AdvancedSetting -Entity $HOST6502 -Name $csvInput.Name | Set-AdvancedSetting -Value $csvInput.Value

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM