SCCM | Intune | Windows 365 | Windows 11 Forums

Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members. Please post your questions in the correct category.

SOLVED Env variable not getting created with Script in SCCM

Status
Not open for further replies.

leo815

Member
Messages
20
Solutions
2
Points
3
Hi team,

I am currently working on a software prerequisites deployment and I have a following script that doesn't create the user environment variable but creates the C:\Scratch folder. I have even tried replacing the first line in the script with setx VALUE KEY but still doesn't work. I can get setx and [System.Environment] power shell command to work directly on the PC but need it to deploy via script as I want to create this environment variable and create c:\scratch folder in one hit.
Any assistance would be appreciated. Thanks.

[System.Environment]::SetEnvironmentVariable('VALUE,'KEY',[System.EnvironmentVariableTarget]::User)
$f1 = "C:\SCRATCH"
New-Item $f1 -Type Directory
$rule=new-object System.Security.AccessControl.FileSystemAccessRule ("BUILTIN\Users","FullControl","ContainerInherit,ObjectInherit","None","Allow")
$FolderACL = Get-ACL -Path $f1
$FolderACL.SetAccessRule($rule)
Set-ACL -Path $f1 -AclObject $FolderACL
 
How exactly are you deploying this? Did you test your script using the local system account? are you deploying to to the user or the device?

 
I am deploying script via SCCM script.
I have tested the following 2 scripts separately and they work on their own but when I combine it with the C:\scratch folder, only the scratch folder gets created but not the environment variable.
1) [System.Environment]::SetEnvironmentVariable('VALUE,'KEY',[System.EnvironmentVariableTarget]::User)
2) setx VALUE KEY
 
I am deploying script via SCCM script.
I have tested the following 2 scripts separately and they work on their own but when I combine it with the C:\scratch folder, only the scratch folder gets created but not the environment variable.
1) [System.Environment]::SetEnvironmentVariable('VALUE,'KEY',[System.EnvironmentVariableTarget]::User)
2) setx VALUE KEY
Did you test the script using the local system account? https://www.recastsoftware.com/resources/how-to-access-the-local-system-account/
 
This is now resolved by running the following command

setx LICENSE_PATH LICENSENUMBER /M

Thanks team.
 
Solution
Status
Not open for further replies.
Back
Top