IF statment In Powershell

Suresh Kumar
Suresh Kumar used Ask the Experts™
on
[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?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Shaun VermaakTechnical Specialist
Awarded 2017
Distinguished Expert 2018

Commented:
$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

Author

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
Shaun VermaakTechnical Specialist
Awarded 2017
Distinguished Expert 2018

Commented:
Check if that path is saved in registry then we can lookup value from it
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Yes..the path is saved in registry
Shaun VermaakTechnical Specialist
Awarded 2017
Distinguished Expert 2018

Commented:
Please post the registry key/value

Author

Commented:
C:\Program Files\HP\HP BTO Software\bin\win64\OpcWbemInterceptor.dll
Shaun VermaakTechnical Specialist
Awarded 2017
Distinguished Expert 2018

Commented:
I need the value path in registry too such as HKLM\software\...

Author

Commented:
HKEY_CLASSES_ROOT\CLSID\{07D539F9-547C-11D3-9A1B-0060B0F5FEE6}\InprocServer32
Technical Specialist
Awarded 2017
Distinguished Expert 2018
Commented:
$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

Author

Commented:
Thanks
Shaun VermaakTechnical Specialist
Awarded 2017
Distinguished Expert 2018

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

Author

Commented:
sure

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial