我遇到了第一批PowerShell代码的问题。
代码:
$resultVar=get-CPUAndMemUtilization -computername $computername -CPUCriteria $CPUCriteria -MemCriteria $MemCriteria
#Write-Host "Mme:"$resultVar;
$CPUMem += [PSCustomObject] @{
CPULoad = "$($resultVar[0])"
MemLoad = "$($resultVar[1])"
}
Write-Host $CPUMem;
function get-CPUAndMemUtilization($computername,$CPUCriteria,$MemCriteria)
{
$Memstatus=$null;
$CPUstatus=$null;
$AVGProc = Get-WmiObject -computername $computername win32_processor | Measure-Object -property LoadPercentage -Average | Select Average
$OS = gwmi -Class win32_operatingsystem -computername $computername |
Select-Object @{Name = "MemoryUsage"; Expression = {“{0:N2}” -f ((($_.TotalVisibleMemorySize - $_.FreePhysicalMemory)*100)/ $_.TotalVisibleMemorySize) }}
$result += [PSCustomObject] @{
ServerName = "$computername"
CPULoad = "$($AVGProc.Average)%"
MemLoad = "$($OS.MemoryUsage)%"
}
if($AVGProc.Average -lt $CPUCriteria)
{
$Memstatus=1;
}else{
$Memstatus=0;
}
if($OS.MemoryUsage -lt $MemCriteria)
{
$CPUstatus=1;
}else{
$CPUstatus=0;
}
$CPUstatus
$Memstatus
return;
}
代码返回系统CPU&我在CPU和CPU中使用该系统系统的内存利用率 错误:
get-CPUAndMemUtilization:术语'get-CPUAndMemUtilization'不是 被识别为cmdlet,函数,脚本文件或可操作的名称 程序。检查名称的拼写,或者是否包含路径, 验证路径是否正确,然后重试。
答案 0 :(得分:2)
在将函数导入(因此它不存在)进入powershell会话之前调用该函数,只需交换这两件事:
<style>
img {
position: absolute;
clip: rect(0px,60px,250px,10px);
}
</style>