1

Morning everyone, This is a question specific to product licensing. We have many servers hosting licenses for engineering software that share the same variable name but on different servers. So if for instance I have an existing system variable let's say " $LM_LICENSE_FILE="server1,server2,server3" and $LM_LICENEFILE_NEW = "server4,server5,server6"

I want to append to it only if the new license variable is "different" separated by a semicolon. So if $LM_LICENSE_FILE=$LM_LICENSE _FILE_NEW Do nothing Else LM_LICENSE_FILE= $(LM_LICENSE_FILE) + ";" +(LM_LICENSE_FILE_NEW)

The value I want would be LM_LICENSE_File=server1,server2,server3;server4,servr5,server6

What would be the method to compare and append this path in powershell? Thanks, Carl G.

Researching this and I know very little about powershell outside of searching for what want and modifying. I would assume this would be a string compare and a concatenate if the strings don't match. Just don't know enough about powershell to tell people what I want.

2
  • 1
    Please format your post properly. Commented Apr 11, 2023 at 15:02
  • 1
    Could make a minimal effort at solving the problem, only thing you need for this is an if condition checking for inequality -ne Commented Apr 11, 2023 at 15:08

1 Answer 1

-1

Try following :

$LM_LICENSE_FILE="server1,server2,server3"
$licnesesSplit = $LM_LICENSE_FILE.Split(',')
$LM_LICENEFILE_NEW = "server1, server4,server5,server6"
$licnesesSplitnew = $LM_LICENEFILE_NEW.Split(',')
foreach($license in $licnesesSplitnew)
{
   if(-not $licnesesSplit.Contains($license))
   {
      $LM_LICENSE_FILE += ("," + $license)
   }
}
$LM_LICENSE_FILE
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.