I need to add properties in security.properties files using powershell script to make automate

Anonymous
2023-11-15T19:06:17+00:00

Hi I have some servers and we have two properties file `1.security.properties and glb.properties.

In those files i have to add environments like if our product is upsEnvironment=ups

condition is if already environment/properties exist in server no need to add if not script needs to add.

Please help me on this

Windows for business Windows Server User experience PowerShell

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question. To protect privacy, user profiles for migrated questions are anonymized.

0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Anonymous
    2023-11-16T07:02:44+00:00

    Hi,

    What is the format of the properties files? If it's plain text you can use the out-file cmdlet to write to the files.

    Out-File (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Learn

    0 comments No comments
  2. Anonymous
    2023-11-16T13:53:57+00:00

    please help me for this script

    Requirements : 1. I need compare two file contents and if already exist then script should skip otherwise we need to add content to the file

    $FilePath = "C:\test\security.properties.txt"

    $FileContents = Get-Content -Path $FilePath

    $i = 1

    # Read the file line by line

    ForEach ($Line in $FileContents) {

        # Process each line here

        Write-Host "Line# $i :" $Line

        $i++

    if($i -match $([string]$akm))

        {

        $file = "C:\test\security.properties.txt"

            Add-Content $file "absEnvironment=abs"

        }

        }

    0 comments No comments
  3. Anonymous
    2023-11-17T07:56:05+00:00

    This script does not compare files. Do you want to make sure 1.security.properties and glb.properties are identical? What is $akm? Please note that the regular expression should be on the right-hand side of the -match operator.

    0 comments No comments