Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting Environmental Variables with Intune and proactive remediations-SysManSquad | Systems Management Squad #20

Open
utterances-bot opened this issue Feb 23, 2023 · 5 comments

Comments

@utterances-bot
Copy link

Setting Environmental Variables with Intune and proactive remediations-SysManSquad | Systems Management Squad

A community blog and subsidiary of WinAdmins.io

https://sysmansquad.com/2021/07/02/setting-environmental-variables-with-intune-and-proactive-remediations/

Copy link

This is great! I am trying to create a System Variable rather than update the TMP or TMP. Wondering if you had anything that would relate to that. Been banging my head trying to take what you have and apply it to a System Variable.

@mcpatrickryan12
Copy link

This is great! I am trying to create a System Variable rather than update the TMP or TMP. Wondering if you had anything that would relate to that. Been banging my head trying to take what you have and apply it to a System Variable.

*Edit, I figured this out now and can update here if folks are interested.

Copy link

I'll be interested to see how you did it. I'm trying to do the same (a system variable from proactive remediation)

@elgrunt0
Copy link

At the end of the [System.Environment]::SetEnvironmentVariable you need to write "Machine" instead of "User"
Example:

Detection

$LICENSE_FILE = [System.Environment]::GetEnvironmentVariable('LM_LICENSE_FILE','Machine')

If (!($LICENSE_FILE -eq '[email protected]')){
    Write-host 'Non-compliant'
    Exit 1
}
Else{
    Write-host'Compliant'
    Exit 0
}

Remediate

[System.Environment]::SetEnvironmentVariable('LM_LICENSE_FILE','[email protected]','Machine')

And of course, set "Run this script using the logged-on credentials" to No, so it runs under system context.

Copy link

And what about to set an environment variable in intune package to deploy during autopilot pre-provisioning?
I explain better:
I have a first package (a powershell) that set an environment variable in all environments
[System.Environment]::SetEnvironmentVariable('NETWORK_CONNECTION','CLOUD','User')
[System.Environment]::SetEnvironmentVariable('NETWORK_CONNECTION','CLOUD','Machine')
[System.Environment]::SetEnvironmentVariable('NETWORK_CONNECTION','CLOUD','Process')

and a second package (a vbs) that check that variable
Dim NetworkConnection : NetworkConnection = WshShell.ExpandEnvironmentStrings("%NETWORK_CONNECTION%")
If UCase(NetworkConnection) = "%NETWORK_CONNECTION%" Then NetworkConnection = "NoValueIsSet"

but is always "NoValueIsSet" :(

Any suggestions?
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants