Suresh Kumar
asked on
Powershell script does not exit
Powershell script does not exist when running through bladelogic.But it woks fine till the HTML part but doesnot exit
Please see the script below..
Please see the script below..
[cmdletbinding()]
param
(
[Parameter(Position=0,ValuefromPipeline=$true)]
[string[]]$ComputerName = $env:ComputerName
)
$cpuload = ((Get-Counter -Counter "\\$ComputerName\Process(*)\% Processor Time" -ea 0).CounterSamples) | Select-Object -Property instancename, cookedvalue | Sort-Object -Property cookedvalue -Descending | Select-Object -First 20 |Select-Object InstanceName,@{L='CPU';E={($_.Cookedvalue/100).toString('P')}}
$a = "<style>"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;}"
$a = $a + "</style>"
$cpuload | ConvertTo-Html -head $a -body "<H2>CPU LOAD</H2>" | Out-File -FilePath C:\tmp\dis.txt
#Invoke-Expression C:\tmp\dis1.txt
#cat C:\tmp\dis1.txt
Get-Content 'C:\tmp\dis.txt' | Foreach-Object {$_ -replace '^<html.*$', ("<html>")} | Set-Content 'C:\tmp\dis1.txt'
cat C:\tmp\dis1.txt
Do i need to add anything .so that script exit
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Your code still is wrong. exit does not change that.
Line 19 should be
Open in new window
(note the added parens) though I don't see why you shouldn't process the output of ConvertTo-HTML directly without first writing it to a file you then overwrite.