file - Powershell: Missing '=' operator after key in hash literal Error -


the code:

$serverlistfile = "d:\scripts\serverlist.txt"    $serverlist = get-content $serverlistfile -erroraction silentlycontinue   $result = @()   foreach($computername in $serverlist)   {   $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) }   get-eventlog -logname security -newest 5000 | where-object {$_.eventid -eq "4624"} | select-object @{name ='username'; expression = {$_.replacementstrings[1]}} }   $result += [pscustomobject] @{           servername = "$computername"          cpuload = "$($avgproc.average)%"          memload = "$($os.memoryusage)%"          eventlog = "$username"     }       $outputreport = "<html><title> server health report </title>                       <body background-color:peachpuff>                       <font color =""#99000"" face=""microsoft tai le"">                       <h2> server health report </h2></font>                       <table border=1 cellpadding=0 cellspacing=0>                       <tr bgcolor=gray align=center>                         <td><b>server name</b></td>                         <td><b>avrg.cpu utilization</b></td>                         <td><b>memory utilization</b></td>                        <td><b>username event-4624</b></td></tr>"       foreach($entry in $result)            {             if((($entry.cpuload) -or ($entry.memload)) -ge 80 )             {               $outputreport += "<tr bgcolor=red>"             }             else             {              $outputreport += "<tr>"             }            $outputreport += "<td>$($entry.servername)</td><td align=center>$($entry.cpuload)</td><td align=center>$($entry.memload)</td><td align=center>$($entry.eventlog)</td></tr>"           }       $outputreport += "</table></body></html>"           }    $outputreport | out-file d:\scripts\test.htm   invoke-expression d:\scripts\test.htm 

produces following error:

missing '=' operator after key in hash literal.  @ d:\scripts\again.ps1:13 char:13  + get-eventlog <<<<  -logname security -newest 5000 | where-object {$_.eventid -eq "4624"} | select-object @{name ='username'; expression = {$_.replacementstrings[1]}}  + categoryinfo          : parsererror: (:) [], parentcontainserrorrecordexception + fullyqualifiederrorid : missingequalsinhashliteral 

missing } here:

select-object @{name = "memoryusage"; expression = {"{0:n2}" -f ((($_.totalvisiblememorysize - $_.freephysicalmemory)*100)/ $_.totalvisiblememorysize) } } 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -