Jens-Urban Posted February 18, 2014 Report post Posted February 18, 2014 Ok, I am trying to run a Custom Powershellscript and I need to access some custom MDTvariables. This should be simple but I am burning TIME here because I fail at some point . My Environment: SCCM 2007 SP2 R3 with integrated MDT 2012 Update 1 This is what I try to do, am I doing something stupid here? I create a Client MDT Task Sequence. In Customsettings.ini I declare some custom variables, ZTIGather seems to pick them up according the ZTIGather.log. Properties=AutoLogonUserName, AutoLogonDomainName, RunOnceCMD, RunOncePsScript [Default] AutoLogonUserName=testuser AutoLogonDomainName=testdomain RunOnceCMD= RunOncePsScript=C:\Windows\MEDIA\AutoLogon4InstCheck\RunOnceTestBox.ps1 In the full windowsphase in the Task Sequence I add a built in "Run PowerShell Script" and point it to my scriptfile in %SCRIPTROOT%. No parameters, scriptinput should come from my custom MDT variables... Here is my Powershellscript(i'm trying to add some registrysettings for autologon and runonce). I try to populate the scriptparameters with for exampel $TSEnv:AutoLogonUserName , the TSENV PSDrive should be automatically populated when using the built in "Run Powershell Script" action in the Task Sequence. $TSEnv:AutoLogonPassword is set as a collection variable in the SCCMconsole to hide it. [cmdletbinding()] param ( [parameter(mandatory=$true)] [string] $AutoLogonUserName = $TSEnv:AutoLogonUserName, [parameter(mandatory=$true)] [string] $AutoLogonPassword = $TSEnv:AutoLogonPassword, [parameter(mandatory=$true)] [string] $AutoLogonDomainName = $TSEnv:AutoLogonDomainName, [int] $AutoLogonCount = 1, [string] $RunOnceCMD = $TSEnv:RunOnceCMD, [string] $RunOncePsScript = $TSEnv:RunOncePsScript, [switch] $AutoAdminLogonDisable ) begin { [string] $WinlogonPath = "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" [string] $WinlogonBannerPolicyPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" [string] $RunOnceKey = "HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce" [string] $Enable = 1 [string] $Disable = 0 #Import-Module ZTIUtility #disable in SCCM/MDT Production, only for testing. } process { If($AutoAdminLogonDisable -eq $true) { Set-ItemProperty -Path $WinlogonPath -Name AutoAdminLogon -Value $Disable -Force Set-ItemProperty -Path $WinlogonPath -Name DefaultPassword -Value $null -Force #Clear password from registry, best practise because it is stored unencrypted. } Else { Set-ItemProperty -Path $WinlogonPath -Name AutoAdminLogon -Value $Enable -Force Set-ItemProperty -Path $WinlogonPath -Name DefaultPassword -Value $AutoLogonPassword -Force } Set-ItemProperty -Path $WinlogonPath -Name DefaultUserName -Value $AutoLogonUserName -Force Set-ItemProperty -Path $WinlogonPath -Name DefaultDomainName -Value $AutoLogonDomainName -Force Set-ItemProperty -Path $WinlogonPath -Name AutoLogonCount -Value $AutoLogonCount -Force Set-ItemProperty -Path $RunOnceKey -Name RunPSScript1 -Value "C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -noprofile -sta -WindowStyle Hidden -executionpolicy bypass -nologo -file $RunOncePsScript" -Force } end { } This method fails because the MDTvariables seems to be empty or non existent when the script runs? The logfile from the script is created in the CCM\logs folder so it is indeed started. What am I doing wrong here, this should be SIMPLE Quote Share this post Link to post Share on other sites More sharing options...