html调用powershell,Powershell:在html格式化中使用powershell命令

我正在做Hyper-V虚拟机的每日检查,并且根据需要以HTML格式获取输出。 但是,在html格式中总是有改进的空间,我需要以下问题的帮助。Powershell:在html格式化中使用powershell命令

我有以下阵列

$outputArray = @()

foreach($VM in $VMS) {

$VMsRAM = [math]::round($VM.Memoryassigned/1GB)

$VMsCPU = $VM.processorCount

$VMsState = $VM.State

$VMsStatus = $VM.Status

$VMsUptime = $VM.Uptime

$VMsAutomaticstartaction = $VM.Automaticstartaction

$VMsIntegrationServicesVersion = $VM.IntegrationServicesVersion

$VMsReplicationState = $VM.ReplicationState

$VHDsGB = @{ label="File_Size"; Expression={[math]::round($_.FileSize/1GB)}}

$VHDs = Get-VHD -ComputerName $VM.ComputerName -VMId $VM.Id | Select Path, VHDType, VHDFormat, $VHDsGB

$output = new-object psobject

$output | add-member noteproperty "VM Name" $VM.Name

$output | add-member noteproperty "RAM(GB)" $VMsRAM

$output | add-member noteproperty "vCPU" $VMsCPU

$output | add-member noteproperty "State" $VMsState

$output | add-member noteproperty "Status" $VMsStatus

$output | add-member noteproperty "Uptime" $VMsUptime

$output | add-member noteproperty "Start Action" $VMsAutomaticstartaction

$output | add-member noteproperty "Integration Tools" $VMsIntegrationServicesVersion

$output | add-member noteproperty "Replication State" $VMsReplicationState

$output | add-member noteproperty "VHD Path" $VHDs.Path

$output | add-member noteproperty "Size GB" $VHDs.File_Size

$output | add-member noteproperty "VHD Type" $VHDs.vhdtype

$output | add-member noteproperty "VHD Format" $VHDs.vhdformat

$outputArray += $output

}

接下来,我使用HTML格式

#Export contents to htm

if($outputArray -ne $null) {

$HTML5 = '

#Header{font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;width:100%;border-collapse:collapse;}

#Header td, #Header th {font-size:14px;border:1px solid #98bf21;padding:3px 7px 2px 7px;}

#Header th {font-size:14px;text-align:left;padding-top:5px;padding-bottom:4px;background-color:#A7C942;color:#fff;}

#Header tr.alt td {color:#000;background-color:#EAF2D3;}

'

$HTML5 += "

VMGuest Tech Spec's
"

$HTML5 += "

Foreach($Entry in $outputArray){

$HTML5 += "

$($Entry.'VM Name')$($Entry.'RAM(GB)')$($Entry.vCPU)$($Entry.State)$($Entry.Uptime)$($Entry.'Integration Tools')$($Entry.'Replication State')$($Entry.'VHD Path')$($Entry.'Size GB')$($Entry.'VHD Type')$($Entry.'VHD Format')"

}

上面的代码工作正常抛出的输出。但是,“$($ Entry.'VHD Path')

”导致多路径,因为存在多个虚拟磁盘的这种混乱;我的报告。 现在,我的问题是我如何将每个输出格式化为表格中的单独一行。

非常感谢您的帮助。

+0

难道我理解正确的是'$ Entry.'VHD Path''是一个数组? (或可能只是一个逗号分隔的字符串...?) –

+0

是的,它的数组的一部分...在数组中,我给每个值提取标签。 以下内容会收集包含其他信息的所有路径信息。 $ VHDs = Get-VHD -ComputerName $ VM.ComputerName -VMId $ VM.Id |选择路径,VHDType,VHDFormat,$ VHDsGB 只有路径元素$ VHDs.Path现在被赋予一个标签 $ output |添加成员noteproperty “VHD路径” $ VHDs.Path 最后,在使用标签名称$($ Entry.'VHD路径“) –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值