How to ensure the existence of user before deleting from local user group?
===

I am trying to Replace a user in local group using powershell script.

    Function ReplaceUserInGroup {
    
    	Param (
    		[string]$Group,
    		[string]$OldUserName,
    		[string]$NewUserName		
    	)
    	
    	[string]$computer=$env:ComputerName
    	
    	
    	If($Group -And $OldUserName -And $NewUserName ) {
    		$LocalGroup = [ADSI]"WinNT://$computer/$Group,group"
    	
    		$LocalGroup.Add("WinNT://$computer/$NewUserName")
    	
    		$LocalGroup.Remove("WinNT://$OldUserName")
    	}
    	Else {
    			Write-Warning " ReplaceUserInGroup : Some or all the parameters are empty"
    	}
    	
    	
    }

The problem with this script is ,it will fail if the OldUserName doesn't exist in the local group.

I would like to check whether the user exists in the group before removing the user from localgroup.

In other words I would like to wrap Remove function line in some if condition like belows.
    
    If (UserName exists in Localgroup) {
        $LocalGroup.Remove("WinNT://$OldUserName")
    }

How to check the user existence?