NEW在SC Env变量没有得到创建脚本CM

leo815

leo815

Member
13
0
1
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
Garth

Garth

Well-Known Member
Staff member
1,842
157
63
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?

OP
leo815

leo815

Member
13
0
1
  • Thread Starter
  • #3
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

Forum statistics

Threads
5,757
Messages
22,445
Members
12,610
Latest member
bhopalcab