首页 > 解决方案 > power shell 命令 get-content 和 add-content 的问题

问题描述

我正在尝试使用 power shell(使用现有代码)创建服务报告,我对 power shell 非常陌生,但我不断收到错误消息(见下文。

Add-Content : A positional parameter cannot be found that accepts argument 'Add-Content'.
At 
 C:\HYPERION_DOCS\Projects\SERVICESMonitoring\CheckServiceStatus.ps1:19 char:1
+ Add-Content $report "<html>" Add-Content $report "<head>" Add-Content ...

##############################################################################
$checkrep = Test-Path “.\report.htm”
If ($checkrep -like “True”)
{
Remove-Item “.\report.htm”

}
New-Item “.\report.htm” -type file
################################ADD HTML 
Content#############################

Add-Content $report “&lt;html>” Add-Content $report “&lt;head>” Add-Content 
$report “&lt;meta http-equiv=’Content-Type’ content=’text/html; charset=iso- 
8859-1'>” Add-Content $report ‘&lt;title>Hyperion Services Report</title>’ 
Add-Content $report ‘&lt;img src=”Toplogo.png” alt=”Infosys” style=”width:100%;height:25%;” align=”Center”&gt;’ add-content $report ‘&lt;STYLE TYPE=”text/css”&gt;’ add-content $report  “&lt;!–” add-content $report  “td {” add-content $report  “font-family: Tahoma;” add-content $report  “font-size: 11px;” add-content $report  “border-top: 1px solid #999999;” add-content $report  “border-right: 1px solid #999999;” add-content $report  “border-bottom: 1px solid #999999;” add-content $report  “border-left: 1px solid #999999;” add-content $report  “padding-top: 0px;” add-content $report  “padding-right: 0px;” add-content $report  “padding-bottom: 0px;” add-content $report  “padding-left: 0px;” add-content $report  “}” add-content $report  “body {” add-content $report  “margin-left: 5px;” add-content $report  “margin-top: 5px;” add-content $report  “margin-right: 0px;” add-content $report  “margin-bottom: 10px;” add-content $report  “” add-content $report  “table {” add-content $report  “border: thin solid #000000;” add-content $report  “}” add-content $report  “–&gt;” add-content $report  “&lt;/style>” Add-Content $report “&lt;/head>” Add-Content $report “&lt;body>” add-content $report  “&lt;table width=’100%’&gt;” add-content $report  “&lt;tr bgcolor=’Lavender’&gt;” add-content $report  “&lt;td colspan=’7' height=’25’ align=’center’&gt;” add-content $report  “&lt;font face=’tahoma’ color=’#003399' size=’4'><strong>Hyperion Services Report</strong></font>” add-content $report  “&lt;/td>” add-content 
$report  “&lt;/tr>” add-content $report  “&lt;/table>”  add-content $report  “&lt;table width=’100%’&gt;” Add-Content $report “&lt;tr bgcolor=’IndianRed’&gt;” Add-Content 

$report “<B>服务器名称” 添加内容 $report “<B>服务名称” 添加内容 $report “<B>状态” 添加内容 $report “”</p>

……

标签: htmlpowershell

解决方案


我发现您发布的代码有两个问题。

[1] 缺少换行符或;指示命令结束
您列出的错误提到试图Get-Content用作位置参数的参数。

这正是它所说的。[ grin ] 您需要将每个 cmdlet 及其参数放在单独的行中,或者用分号分隔命令。

[2] 明显的 MSWord “智能引号”
您的代码显示弯曲/卷曲的双引号和单引号。那些与标准直引号不同。当使用那些特殊的 [但非常漂亮的] 引号时,PoSh 经常会对字符串的开始/结束位置感到非常困惑。

强烈建议你用直引号替换那些。

保重,


推荐阅读