Avatar of Suresh Kumar
Suresh Kumar
 asked on

IF statment In Powershell

    [string]$ComputerName = $env:ComputerName
$Head = @'
TABLE      {border-width:1px; border-style:solid; border-color:black; border-collapse:collapse;}
TH            {border-width:1px; padding:2px; border-style:solid; border-color:black;}
TD            {border-width:1px; padding:2px; border-style:solid; border-color:black;}

$Body = @'
<H2>Status for {0}</H2>
'@ -f $ComputerName

$Status = @()
$Stuff = @()
Invoke-Command -ComputerName $ComputerName -ScriptBlock {& opcagt -version} | ForEach-Object {
            $Stuff += $_
($Status | ConvertTo-Html -Head $Head -Body $Body -PostContent "<br /> $($Stuff -join '<br />')") -replace '^<html.*$', "<html>" | Out-file -Filepath C:\tmp\ver.txt
Get-Content 'C:\tmp\ver.txt' | Set-Content 'C:\tmp\ver1.txt'
cat C:\tmp\ver1.txt

The above script gives the ouput of the HPOV ( HP Openview )Version

I need to add a if statement to check if  HPOV installed,If installed it need to run the script  else need to say ÖV not installed on the Server in HTML format

i.e.I need to check if OvInstallDir is there  in the server if so then need to run the script else come out of the script saying "OV not installed on the server" in the HTML format

OvInstallDir=C:\Program Files\HP\HP BTO Software\

Can you help me on this?
PowershellHTML* if statements

Avatar of undefined
Last Comment
Suresh Kumar

8/22/2022 - Mon
Shaun Vermaak

$OvInstallDir = 'C:\Program Files\HP\HP BTO Software\'
if(!(Test-Path -Path $OvInstallDir))
    $Stuff='OV not installed on the server'
ConvertTo-Html -Head $Head -Body $Body -PostContent "<br /> $($Stuff -join '<br />')") -replace '^<html.*$', "<html>" | Out-file -Filepath 'C:\tmp\ver.txt'

Open in new window

Suresh Kumar

this path   " 'C:\Program Files\HP\HP BTO Software\' " may vary for server to server .so actually Path is not necessary.
.just to check OvInstallDir is installed
Shaun Vermaak

Check if that path is saved in registry then we can lookup value from it
Your help has saved me hundreds of hours of internet surfing.
Suresh Kumar

Yes..the path is saved in registry
Shaun Vermaak

Please post the registry key/value
Suresh Kumar

C:\Program Files\HP\HP BTO Software\bin\win64\OpcWbemInterceptor.dll
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Shaun Vermaak

I need the value path in registry too such as HKLM\software\...
Suresh Kumar

Shaun Vermaak

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Suresh Kumar

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Shaun Vermaak

Glad we could help.
Please remember to endorse my, or any other expert's comments that you found helpful.
Suresh Kumar