0

I want the below environment variable to be queried in remote server if (($ImageName -like "devel") -or ($ImageName -like "hosted")) and I want to create a condition that if below variable with below variable value found on server then "ADE instalation is success" else " ADE instalation is failed"

variable name :ADE_INFRA

variable value : \\scavere01-zfs.us.oim.com\ade_infra


variable name :ADE_PACKAGES

variable value : \\scavere01-zfs.us.oim.com\packages\windows

I have created script like below, but the script dont give any output. I am not sure whether this is the correct methord to call and read system variables. Can any one help ?

if (($ImageName -like "*devel*") -or ($ImageName -like "*hosted*"))

{

$env= (gci env:*).GetEnumerator() | Sort-Object Name | Out-String

if (ADE_INFRA -eq "\\scavere01-zfs.us.oim.com\ade_infra" -And ADE_PACKAGES -eq "\\scavere01-zfs.us.oim.com\packages\windows")

        {

        $ADE = "ADE Installation Success"

        echo "ADE = ADE Installation Success"

        }

        if (ADE_INFRA -eq $null -And ADE_PACKAGES -eq $null)

        {

        $ADE = "ADE Installation Failed"


        echo "ADE = ADE Installation Failed"
        }
}
5
  • Look at Invoke-Command and gci env: Commented Apr 6, 2017 at 10:29
  • 1
    I read it over and over, again and again, but can't figure out what you are trying to ask. Commented Apr 6, 2017 at 10:29
  • 2
    Possible duplicate of Can't access Environment Variable from Remote Server with PowerShell Commented Apr 6, 2017 at 10:31
  • the thing is I am writing a script where which ever machine image name is like "devel" or "hosted" ,then the script should check the remote server has the above environment variable. if they found with the above value the "ADE check is successful" and if didn't find then "ADE check is failed" Commented Apr 6, 2017 at 10:35
  • I've withdrawn my duplicate flag as OP has added their own code. Commented Apr 6, 2017 at 12:08

1 Answer 1

0

This should fix the issues you were having with your code:

if (($ImageName -like "*devel*") -or ($ImageName -like "*hosted*"))
{
    $ADE_INFRA = (gci env:ADE_INFRA).value
    $ADE_PACKAGES = (gci env:ADE_PACKAGES).value

    if ($ADE_INFRA -eq "\\scavere01-zfs.us.oim.com\ade_infra" -And $ADE_PACKAGES -eq "\\scavere01-zfs.us.oim.com\packages\windows")
    {
        $ADE = "ADE Installation Success"
    }
    else
    {
        $ADE = "ADE Installation Failed"
    }

    Write-Host "ADE = $ADE"
}
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.