html - 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 “<html>” Add-Content $report “<head>” Add-Content
$report “<meta http-equiv=’Content-Type’ content=’text/html; charset=iso-
8859-1'>” Add-Content $report ‘<title>Hyperion Services Report</title>’
Add-Content $report ‘<img src=”Toplogo.png” alt=”Infosys” style=”width:100%;height:25%;” align=”Center”>’ add-content $report ‘<STYLE TYPE=”text/css”>’ add-content $report “<!–” 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 “–>” add-content $report “</style>” Add-Content $report “</head>” Add-Content $report “<body>” add-content $report “<table width=’100%’>” add-content $report “<tr bgcolor=’Lavender’>” add-content $report “<td colspan=’7' height=’25’ align=’center’>” add-content $report “<font face=’tahoma’ color=’#003399' size=’4'><strong>Hyperion Services Report</strong></font>” add-content $report “</td>” add-content
$report “</tr>” add-content $report “</table>” add-content $report “<table width=’100%’>” Add-Content $report “<tr bgcolor=’IndianRed’>” Add-Content
$report “<B>服务器名称” 添加内容 $report “<B>服务名称” 添加内容 $report “<B>状态” 添加内容 $report “”</p>
……
解决方案
我发现您发布的代码有两个问题。
[1] 缺少换行符或;
指示命令结束
您列出的错误提到试图Get-Content
用作位置参数的参数。
这正是它所说的。[ grin ] 您需要将每个 cmdlet 及其参数放在单独的行中,或者用分号分隔命令。
[2] 明显的 MSWord “智能引号”
您的代码显示弯曲/卷曲的双引号和单引号。那些与标准直引号不同。当使用那些特殊的 [但非常漂亮的] 引号时,PoSh 经常会对字符串的开始/结束位置感到非常困惑。
我强烈建议你用直引号替换那些。
保重,
李
推荐阅读
- amazon-web-services - 如何为 gitlab CI CD 创建构建和部署路径?
- javascript - 为 html 创建自定义拼写检查
- ios - NWConnection 超时
- laravel - 在laravel中按降序排列
- python - 如何更改 python plotly 图形 id?
- c# - 在 C# asp.net web 表单中执行 java 脚本后如何从网站上抓取数据
- javascript - TypeError:无法读取未定义的属性“forEach”(制作禁令命令)
- mysql - 按最小值分组。为什么我的解决方案会失败?
- php - PHP检查数据库中是否存在
- python - 使用python中单词的开始和结束索引从长字符串中提取句子