Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 如何同时拥有写主机和html_Powershell_Powershell 2.0_Powershell 3.0_Powershell Ise - Fatal编程技术网

Powershell 如何同时拥有写主机和html

Powershell 如何同时拥有写主机和html,powershell,powershell-2.0,powershell-3.0,powershell-ise,Powershell,Powershell 2.0,Powershell 3.0,Powershell Ise,我已经写了一个代码片段,我已经将写主机合并到其中。我希望写主机和转换html都能为这个代码片段运行。有人能帮我吗 $arrComputers = get-Content -Path "C:\Computers.txt" foreach ($strComputer in $arrComputers) { $colItems = get-wmiobject -class "Win32_BIOS" -namespace "root\CIMV2" ` -

我已经写了一个代码片段,我已经将写主机合并到其中。我希望写主机和转换html都能为这个代码片段运行。有人能帮我吗

 $arrComputers = get-Content -Path "C:\Computers.txt"
    foreach ($strComputer in $arrComputers)
    {
        $colItems = get-wmiobject -class "Win32_BIOS" -namespace "root\CIMV2" `
        -computername $strComputer
       foreach ($objItem in $colItems)
       {
         write-host "Computer Name: " $strComputer
          write-host "BIOS Version: " $objItem.BIOSVersion
      }

       $colItems1 = get-wmiobject -class Win32_logicaldisk -Filter "DeviceID = 'C:'" -computername $strComputer
       foreach ($objItem1 in $colItems1)
       {
        $e=$objItem1.freeSpace/1GB
         write-host "Total Space:  " $e
         }

        $colItems4 = Get-WMIObject -class Win32_PhysicalMemory  -computername $strComputer
      $colItems5=$colItems4 | Measure-Object -Property capacity -Sum 
      foreach ($objItem4 in $colItems5)
   {
      $e4=$colItems5.Sum/1GB
      write-host "Memory :  " $e4
   }


    }

可以使用-Fragment参数

$pcName = "Computer Name: $strComputer" | ConvertTo-HTML -Fragment;
$biosV = "BIOS Version: $objItem.BIOSVersion" | ConvertTo-HTML -Fragment;

ConvertTo-HTML -Body "$pcName $biosV" -Title "List of Computers" |  Out-File c:\listofcomputers.html
只需在Write主机之后创建具有相同内容的变量,并在脚本末尾使用convertohtml


通过这种方式,您也可以使用param标记甚至table标记来设置HTML输出的样式,以获得比干净的无菌布局更好的布局。

您可以使用-Fragment参数

$pcName = "Computer Name: $strComputer" | ConvertTo-HTML -Fragment;
$biosV = "BIOS Version: $objItem.BIOSVersion" | ConvertTo-HTML -Fragment;

ConvertTo-HTML -Body "$pcName $biosV" -Title "List of Computers" |  Out-File c:\listofcomputers.html
只需在Write主机之后创建具有相同内容的变量,并在脚本末尾使用convertohtml


通过这种方式,您也可以使用param标记甚至table标记来设置HTML输出的样式,使其具有比干净的无菌布局更好的布局。

表达式或语句中的意外标记“$strComputer”。我遇到了这个错误。哦,糟糕。变量应该在“.PS”中,它的内容将由数据本身替换。编辑了我的帖子。*25*236这是我获取的用于BIOS版本和计算机名的HTML文件,它不是truewrite主机“计算机名:$strComputer$pcName=“Computer Name:$strComputer”|转换为HTML-片段;write主机”BIOS版本:“$objItem.BIOSVersion;$biosV=“BIOS版本:$objItem.BIOSVersion”|转换为HTML-片段;转换为HTML-正文“$pcName$biosV”-标题“计算机列表”|输出文件c:\listofcomputers.htmlTee对象的作业吗?表达式或语句中的意外标记“$strComputer”。我遇到了这个错误。哦,糟糕。变量应该在“.PS”中,它的内容将由数据本身替换。编辑了我的帖子。*25*236这是我获取的用于BIOS版本和计算机名的HTML文件,它不是truewrite主机“计算机名:$strComputer$pcName=“Computer Name:$strComputer”|转换为HTML-片段;write主机”BIOS版本:“$objItem.BIOSVersion;$biosV=“BIOS版本:$objItem.BIOSVersion”|转换为HTML-片段;转换为HTML-正文“$pcName$biosV”-标题“计算机列表”|输出文件c:\listofcomputers.htmlTee对象的作业吗?