簡體   English   中英

Power Shell命令get-content和add-content的問題

[英]Issue with power shell command get-content and 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“ 服務器名稱 ”添加內容$ report“ 服務名稱 ”添加內容$ report“ 狀態 ”添加內容$ report“”

......

您沒有將$ report設置為“ report.htm”

您也可以只使用out-file report.htm -append

另外, convertto-html是可以節省大量鍵入內容的選項。 因為它會自動為您建立頁面...然后您就將結果列為文件...(下面是一個非常簡短的示例)

$body = ‘<img src=”Toplogo.png” alt=”Infosys” style=”width:100%;height:25%;” align=”Center”>’'###... etc... 
ConvertTo-HTML -Body "$body" -Title "Hyperion Services Report" -CssUri c:\style.css | Out-File c:\report.htm

這里改編

我看到您發布的代碼有兩個問題。

[1]缺少換行符OR ; 指示命令結束
錯誤您列表中提到嘗試使用Get-Content為一個位置參數的參數

這就是說的意思。 [ grin ]您需要將EACH cmdlet及其參數放在自己的行上,或者用分號分隔命令。

[2]明顯的MSWord“智能引號”
您的代碼顯示彎曲/卷曲的雙引號和單引號。 那些與標准的直接引號不同。 當使用那些奇特的(但非常漂亮的)引號時,PoSh常常會對字符串的開始/結束位置感到困惑。

強烈建議您用直引號代替那些。

照顧自己,
背風處

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM