将txt数据与变量-powershell进行比较

将txt数据与变量-powershell进行比较,powershell,vmware,vcenter,Powershell,Vmware,Vcenter,这是我想要使用的脚本: $path = split-path $MyInvocation.MyCommand.path $vcenter = Read-Host "Please enter the vCenter name where You want to connect" Import-Module -Name VMware.VimAutomation.Core Connect-VIserver $vcenter $folderName = 'Datacenters' $folder

这是我想要使用的脚本:

$path = split-path $MyInvocation.MyCommand.path

$vcenter = Read-Host "Please enter the vCenter name where You want to connect"

Import-Module -Name VMware.VimAutomation.Core
Connect-VIserver $vcenter

$folderName = 'Datacenters'
$folder = Get-Folder -Name $folderName
$patches = Get-Content $path\patches.txt -Raw
$baseline = New-PatchBaseline -Name "Baseline$(Get-Random)" -Static -IncludePatch $patches

Attach-Baseline -Entity $folder -Baseline $baseline -Confirm:$false

Scan-Inventory -Entity $folder

Get-Compliance -baseline $baseline -entity $folder | select Entity, Status

Detach-Baseline -Entity $folder -Baseline $baseline -Confirm:$false

Remove-Baseline -Baseline $baseline -Confirm:$false
如果我在txt中写入多个修补程序编号-我尝试了以下方法-:

ESXi670-201912001,ESXi670-201905001

ESXi670-201905001ESXi670-201912001

我还尝试用enter分隔行,但没有逗号,脚本无法与$baseline变量进行比较

理想的结果是:将修补程序编号写入文本文件,将新的基线附加到vmware环境,并将主机上安装的修补程序与我写入文本的修补程序进行比较


非常感谢你的帮助

参数
-IncludePatch
需要一个项目数组。首先,我建议从
Get Content
中删除
-Raw
开关,因为这样会将文件内容作为一个长字符串读取。其次,我建议一次只列出一行补丁。这种组合将导致文件被读取为字符串数组,每个字符串都是补丁名

# patches.txt Contents
ESXi670-201912001
ESXi670-201905001

# Update This Line
$patches = Get-Content $path\patches.txt

-IncludePatch
需要一个项目数组。您需要从
Get Content
中删除
-Raw
开关,因为这样会将文件内容作为一个长字符串读入。