none
Not able to remove duplicate values from before updating html RRS feed

  • Question

  • Hi,

    I have some values in $_.ReplicaFQDN as below

    vpwv0067

    vpwv0068

    vpwv0068

    vpwv0068

    if($_.ReplicaFQDN -match $filecontent[$i]){

     Write-Host "Matching Found"$filecontent[$i]

                            $filecontent[$i] = $filecontent[$i]| Get-Unique

    $strHTMLRowNew = $strCMSHTMLRow -Replace "\<REPLICAFQDN\>",$filecontent[$i]

    }

    Here what is happening is while printing there are no duplicate values i.e. it is showing on console as

    Matching Foundvpwv0067

    Matching Foundvpwv0068

    But in html duplicate values are coming as 

    vpwv0067

    vpwv0068

    vpwv0068

    vpwv0068

    Please let me know how to avoid duplicate values before updating html.

    Regards,

    Sudheer


    Thanks & Regards, Sudheer

    Wednesday, July 24, 2019 4:54 AM

All replies

  • Like this:

    $list = @(
    'vpwv0067'
    'vpwv0068'
    'vpwv0068'
    'vpwv0068'
    )
    $list | Sort-Object -Unique


    \_(ツ)_/

    Wednesday, July 24, 2019 6:10 AM
  • Hi,

    After making the changes as specified still I am getting the duplicate values i.e.

    $list = New-Object System.Collections.ArrayList

    for( $i=0; $i -lt $filecontent.Length; $i++ )
                    {
                        
                        if($_.ReplicaFQDN -match $filecontent[$i])
                        {
                            Write-Host "Matching Found"$filecontent[$i]                        

                            $list.Add($filecontent[$i])                       

                        }
                    }
          foreach($UniqueFQDN in $list | Sort-Object -Unique)
                    {

                        Write-Host "Unique FQDN-"$UniqueFQDN                    
                        $strHTMLRowNew = $strCMSHTMLRow -Replace "\<REPLICAFQDN\>",$UniqueFQDN            

                    }          

    FInally output in html is 

    vpwv0067
    vpwv0068
    vpwv0068
    vpwv0068

    Thanks & Regards, Sudheer

    Wednesday, July 24, 2019 8:04 AM
  • Without knowing what you are trying to do the code is useless.

    Please only post code with the provided code posting tool.

    How to post code in Technet Forums

    $list = New-Object System.Collections.ArrayList
    for ($i = 0; $i -lt $filecontent.Length; $i++) {
        if ($_.ReplicaFQDN -match $filecontent[$i]) {
            Write-Host "Matching Found"$filecontent[$i]
            $list.Add($filecontent[$i])
        }
    }
    $list = $list | sort -Unique
    foreach ($UniqueFQDN in $list){
        Write-Host "Unique FQDN-"$UniqueFQDN
        $strCMSHTMLRow -Replace "\<REPLICAFQDN\>", $UniqueFQDN
    }           
    Without the rest of your code that gets the file and the matches there is no way to know what you are doing wrong.


    \_(ツ)_/

    Wednesday, July 24, 2019 8:18 AM
  • Hi,

    Sorry for not explaining properly.

    Basically I am trying to get the replication status of servers and compare with my txt file which has list of servers.

    If it is matching then I am updating the html file and making sure that there are no duplicate server names

    For this I am posting the relevant methods as below

    For detailed explanation please go through the link as below from where took as reference and modifying as per the need

    https://blogs.technet.microsoft.com/stevemoore/2016/09/29/lync-server-2013skype-for-business-health-check-script/

    ##-----------------------------------------------------------------------
    ## Function: Get-IsLyncServer
    ## Purpose: This function is used to 
    ##-----------------------------------------------------------------------
    function Get-IsLyncServer
    {
    param ([string]$strServer)
    [string] $strResult = "";

    if ((Get-CsManagementStoreReplicationStatus | where {$_.ReplicaFQDN -match $strServer}).Count -gt 0) {
    $strReturn = "True"

        Else {
    $strReturn = "False"
    }
    return $strReturn
    }

    ##-----------------------------------------------------------------------
    ## Function: Get-CMSHTML
    ## Purpose: This function is used to 
    ##-----------------------------------------------------------------------
    function Get-CMSHTML
    {
    [string] $strCMSHTML = "";
    $strCMSHTML = Get-CMSReplicaHead
    $strCMSHTMLRow = Get-CMSReplicaRow

    $strDate = get-date -uFormat "%d-%m-%Y"
    $strCMSHTML = $strCMSHTML -Replace "\<TODAYSDATE\>",$strDate

    $objCMSData = Get-CsManagementStoreReplicationStatus

    $objCMSData | % {        
        
            $filecontent = Get-Content 'C:\lync\scripts\systemstatus\Servers - Copy.txt'
            $list = New-Object System.Collections.ArrayList
                    for( $i=0; $i -lt $filecontent.Length; $i++ )
                    {
                        
                        if($_.ReplicaFQDN -match $filecontent[$i])
                        {
                          
                            $list.Add($filecontent[$i])                       

                        }
                    }
                    
                    foreach($UniqueFQDN in $list | Sort-Object -Unique)
                    {

                        Write-Host "Unique FQDN-"$UniqueFQDN
                        $strHTMLRowNew = $strCMSHTMLRow -Replace "\<REPLICAFQDN\>",$UniqueFQDN
      

                    }
                 
            
    }



    $strCMSHTML = $strCMSHTML + $strHTMLRowNew
    }

    $strCMSHTML = $strCMSHTML + "</table>"

    return $strCMSHTML
    }

    Regards,Sudheer



    Thanks & Regards, Sudheer


    Wednesday, July 24, 2019 9:45 AM
  • Please!

    Please only post code with the provided code posting tool.

    How to post code in Technet Forums


    \_(ツ)_/

    Wednesday, July 24, 2019 10:12 AM
  • Sure,

    I will post the code using the specified tool

    ##-----------------------------------------------------------------------
    ## Function: Get-IsLyncServer
    ## Purpose: This function is used to 
    ##-----------------------------------------------------------------------
    function Get-IsLyncServer
    {
    param ([string]$strServer)
    [string] $strResult = "";
    
    if ((Get-CsManagementStoreReplicationStatus | where {$_.ReplicaFQDN -match $strServer}).Count -gt 0) {
    $strReturn = "True"
    } 
        Else {
    $strReturn = "False"
    }
    return $strReturn
    }
    
    ##-----------------------------------------------------------------------
    ## Function: Get-CMSHTML
    ## Purpose: This function is used to 
    ##-----------------------------------------------------------------------
    function Get-CMSHTML
    {
    [string] $strCMSHTML = "";
    $strCMSHTML = Get-CMSReplicaHead
    $strCMSHTMLRow = Get-CMSReplicaRow
    
    $strDate = get-date -uFormat "%d-%m-%Y"
    $strCMSHTML = $strCMSHTML -Replace "\<TODAYSDATE\>",$strDate
    
    $objCMSData = Get-CsManagementStoreReplicationStatus
    
    $objCMSData | % {        
        
            $filecontent = Get-Content 'C:\lync\scripts\systemstatus\Servers - Copy.txt'
            $list = New-Object System.Collections.ArrayList
                    for( $i=0; $i -lt $filecontent.Length; $i++ )
                    {
                        
                        if($_.ReplicaFQDN -match $filecontent[$i])
                        {
                          
                            $list.Add($filecontent[$i])                       
    
                        }
                    }
                    
                    foreach($UniqueFQDN in $list | Sort-Object -Unique)
                    {
    
                        Write-Host "Unique FQDN-"$UniqueFQDN
                        $strHTMLRowNew = $strCMSHTMLRow -Replace "\<REPLICAFQDN\>",$UniqueFQDN
      
    
                    }
                 
            
    }
    
    
    
    $strCMSHTML = $strCMSHTML + $strHTMLRowNew
    }
    
    $strCMSHTML = $strCMSHTML + "</table>"
    
    return $strCMSHTML
    }


    Thanks & Regards, Sudheer

    Wednesday, July 24, 2019 10:19 AM
  • There is still no way to understand what your issue is. You are missing too many pieces of key information and the code posted has no relations to the issue asked. We have no idea of what is in your variables or how you got them.

    You also need to learn how to format code so it is readable.

    PowerShell Style

    How to post code in Technet Forums


    \_(ツ)_/

    Wednesday, July 24, 2019 7:48 PM