IF statment In Powershell

[CmdletBinding()]
Param(
    [Parameter(Position=0,ValuefromPipeline=$true)]
    [string]$ComputerName = $env:ComputerName
)
$Head = @'
<style>
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;}
</style>
'@

$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?
Suresh KumarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shaun VermaakTechnical Specialist/DeveloperCommented:
$OvInstallDir = 'C:\Program Files\HP\HP BTO Software\'
if(!(Test-Path -Path $OvInstallDir))
{
    $Stuff='OV not installed on the server'
}
else
{
    $Stuff=...
}
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

0
Suresh KumarAuthor Commented:
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
0
Shaun VermaakTechnical Specialist/DeveloperCommented:
Check if that path is saved in registry then we can lookup value from it
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Suresh KumarAuthor Commented:
Yes..the path is saved in registry
0
Shaun VermaakTechnical Specialist/DeveloperCommented:
Please post the registry key/value
0
Suresh KumarAuthor Commented:
C:\Program Files\HP\HP BTO Software\bin\win64\OpcWbemInterceptor.dll
0
Shaun VermaakTechnical Specialist/DeveloperCommented:
I need the value path in registry too such as HKLM\software\...
0
Suresh KumarAuthor Commented:
HKEY_CLASSES_ROOT\CLSID\{07D539F9-547C-11D3-9A1B-0060B0F5FEE6}\InprocServer32
0
Shaun VermaakTechnical Specialist/DeveloperCommented:
$OvRegistry = 'HKCR:\CLSID\{07D539F9-547C-11D3-9A1B-0060B0F5FEE6}\InprocServer32'
if(!(Test-Path -Path $OvRegistry)) { $Stuff='OV not installed on the server' } else { $Stuff=... }
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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Suresh KumarAuthor Commented:
Thanks
0
Shaun VermaakTechnical Specialist/DeveloperCommented:
Glad we could help.
Please remember to endorse my, or any other expert's comments that you found helpful.
1
Suresh KumarAuthor Commented:
sure
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.