我有一个脚本,它在订阅中的Azure VM列表上运行,并 for each VM输出一个文件,下面是其内容的一个示例:
Value[0] :
Code : ComponentStatus/StdOut/succeeded
Level : Info
DisplayStatus : Provisioning succeeded
Message : Directory: C:\variasuit_windows\HARMOR\windows_server\package
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 12/23/2023 5:10 AM HARMOR
"Server Name","GPO_HARMOR","BIOMEDIC_AGENT","EDWARD_STATUS","SENSOR_STATUS","SENTINEL_STATUS"
"AZ-TSTAPP1D","OK","OK","OK","OK","KO"
Value[1] :
Code : ComponentStatus/StdErr/succeeded
Level : Info
DisplayStatus : Provisioning succeeded
Message :
Status : Succeeded
Capacity : 0
Count : 0
我想使用PowerShell解析该文件,以获得以下代码行:
"AZ-TSTAPP1D","OK","OK","OK","OK","KO"
然后将该值从每个文件收集到另一个txt文件,得到如下所示
"AZ-TSTAPP1D","OK","OK","OK","OK","KO"
"AZ-TSTAPP2D","OK","KO","KO","KO","KO"
"AZ-TSTAPP3D","OK","OK","OK","OK","KO"
I tried to get the content of this specific line but I found out that line number can change from a file to another
I tried this:
$scriptResult = Invoke-AzVMRunCommand -ResourceGroupName $vm.ResourceGroupName -VMName $vm.Name -CommandId 'RunPowerShellScript' -ScriptPath $scriptPath
$scriptResult | Out-File $tempFile
$contentFromFile = Get-Content -Path $tempFile
$line12 = $contentFromFile | Select-Object -Index 11
$line12 | Out-File $outputFile -Append
Remove-Item $tempFile
Any help please?
Thanks