SOLVED Env variable not getting created with Script in SCCM

Status
Not open for further replies.

leo815

Member
15
2
1
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?

 
  • Like
Reactions: sanpapp9
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
 
  • Like
Reactions: sanpapp9
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/
 
Status
Not open for further replies.