下面是我的HTML代码中的提取物,在我的PowerShell脚本定义为$ HTML:为什么我从一个here字符串中获取“not a cmdlet”错误?
$html = @"
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="/js/lib/dummy.js"></script>
<link rel="stylesheet" type="text/css" href="/css/result-light.css">
<link rel="stylesheet" type="text/css" href="https://rawgit.com/pguso/jquery-plugin-circliful/1.0.2/css/jquery.circliful.css">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script type="text/javascript" src="https://rawgit.com/pguso/jquery-plugin-circliful/1.0.2/js/jquery.circliful.js"></script>
<style type="text/css"></style>
<title>Orders</title>
</head>
<body>
<div class="container">
<h3 style="text-align: center; margin-top: 2%; font-size: 300%">Actual Vs Expected orders for Today:</h3>
<h2 style="text-align: center; color: #ff3333; margin-top: 2.5%; font-size: 500%">$SAPTodayExel<small style="color: #000000">/$ExpectedExelOrders</small></h2>
<div class="col-lg-12">
<div id="test-circle"></div>
<table style="margin-top: 100px; width:75%; position: fixed; bottom: 40px;">
<tr>
<th style="font-size: 16px; width:11%; background: linear-gradient(to bottom, #f0f9ff 0%,#cbebff 49%,#a1dbff 100%)">12</th>
<td style="font-size: 30px; color: #ff3333; width:20%; background: linear-gradient(to bottom, #f0f9ff 0%,#cbebff 49%,#a1dbff 100%)">$SAPTodayNonConExel</td>
<th style="font-size: 16px; width:8%; background: linear-gradient(to bottom, #f0f9ff 0%,#cbebff 49%,#a1dbff 100%)">13</th>
<td style="font-size: 30px; color: #ff3333; width:20%; background: linear-gradient(to bottom, #f0f9ff 0%,#cbebff 49%,#a1dbff 100%)">$SAPTodayPOSExel</td>
<th style="font-size: 16px; width:8%; background: linear-gradient(to bottom, #f0f9ff 0%,#cbebff 49%,#a1dbff 100%)">24</th>
<td style="font-size: 30px; color: #ff3333; width:15%; background: linear-gradient(to bottom, #f0f9ff 0%,#cbebff 49%,#a1dbff 100%)">$SAPTodayROIExel</td>
<th style="font-size: 16px; width:7%; background: linear-gradient(to bottom, #f0f9ff 0%,#cbebff 49%,#a1dbff 100%)">245</th>
<td style="font-size: 30px; color: #ff3333; width:20%; background: linear-gradient(to bottom, #f0f9ff 0%,#cbebff 49%,#a1dbff 100%)">$SAPTodayUnited</td>
</tr>
</table>
</div>
</div>
</head>
<script type='text/javascript'>
window.onload=function(){
$(document).ready(function() { // 6,32 5,38 2,34
$("#test-circle").circliful({
foregroundColor: "#cb60b3",
backgroundColor: "#e5e7e9",
pointColor: "none",
fillColor: 'none',
foregroundBorderWidth: 15,
backgroundBorderWidth: 15,
pointSize: 28.5,
fontColor: '#aaa',
animation: 1,
animationStep: 5,
showPercent: 1,
noPercentageSign: false,
replacePercentageByText: null,
percentageTextSize: 22,
percent: $PercentReceived,
multiPercentage: 0,
percentages: null,
targetPercent: null,
targetTextSize: 12,
targetColor: '#2980B9',
icon: 'none',
iconSize: '30',
iconColor: '#ccc',
iconPosition: 'top',
target: 0,
start: 0,
textBelow: true,
text: null,
textStyle: "font-size: 10px",
textColor: '#17202a',
textAdditionalCss: 'test',
halfCircle: false,
animateInView: false,
decimals: 0,
alwaysDecimals: false
});
});
}
</script>
</html>
"@
$html | out-file "c:\test.html"
当我运行这是一个HTML文件,它运行完全正常的,预期的脚本运行。不过,如果我通过PS解析这一点,一个错误出现:
document : The term 'document' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:46 char:6 + $(document).ready(function() { // 6,32 5,38 2,34 + ~~~~~~~~ + CategoryInfo : ObjectNotFound: (document:String) [], CommandNot FoundException + FullyQualifiedErrorId : CommandNotFoundException
我试图改变“$(文件)”到“$(”文件“),将在报价单,这似乎工作,但是当您查看输出中的html文件时,它将删除“$(”和“)”,所以它有效地禁用了由于语法不正确而启用的脚本。
是因为它看到美元符号一个PS变量?我怎么去解决这个?
感谢
从语法突出显示,似乎你没有逃脱你的字符串。 – Artyer