Powershell burp;

Soldato
Joined
8 Mar 2005
Posts
3,676
Location
London, UK
Getting myself into a terrible pickle;

I have two functions, 1 which works seemingly as expected, the other less so;
Here is the first which checks whether an OS HFB is installed and if so correctly exits stating so but will drop to the catch if it is not installed.
Code:
Function CheckHFB() 
{   
	Param ($HFBName)
	Try 
	{   if (!(Get-Hotfix -id $HFBName -ComputerName $server -ErrorAction Stop) ) { "$HFBName is not installed..." }
    	else {
            ((Get-Hotfix -id $HFBName -ComputerName $server -ErrorAction Stop) )
        	"$HFBName is installed" }
			return $ServiceResult
    	
	} Catch { "Error while checking the HFB. Server may be down or has a permission issue." } 
}

The second which checks for XA HFB does not. It will always result in " .. not installed."

Code:
Function CheckXAHFB() 
{   
	Param ($XAHFBName)
	Try 
	{   if (!(Get-XAServerHotFix $server | where-object {$_.hotfixname -like '$XAHFBName'} ) ) { "$XAHFBName is not installed..." }
    	else { 
           ((Get-XAServerHotFix $server | where-object {$_.hotfixname -like '$XAHFBName'} ) )
                  "$XAHFBName is  installed" }
			return $ServiceResult
    	
	} Catch { "Error while checking the XAHFB $XAHFBname. Server may be down or has a permission issue."} 
}

Would appreciate any pointers with this.

Cheers, Paul.
 
Last edited:
Soldato
OP
Joined
8 Mar 2005
Posts
3,676
Location
London, UK
Hmm odd;
So
? {$_.hotfixname -match "$XAHFBName"}
Seems to of been the key, at least for the CheckXAHFB function which now works entirely as expected.

I'll use your entire logic for the CheckHFB function and test. Still my scratching my head about this though but many thanks for your eyes!

Fully working function;
Code:
Function CheckXAHFB() 
{   
	Param ($XAHFBName)
	Try 
	{   if (!(Get-XAServerHotFix $server -erroraction stop | ? {$_.hotfixname -match "$XAHFBName"} ) ) { "$XAHFBName is not installed..." }
    	else { 
            ((Get-XAServerHotFix $server -erroraction stop | ? {$_.hotfixname -match "$XAHFBName"} ) )
            
        	"$XAHFBName is installed" }
			return $ServiceResult
    	
	} Catch { "Error while checking the XAHFB $XAHFBname. Server may be down or has a permission issue."} 
}
 
Back
Top Bottom