Mikhail Malorodov
asked on
Sccm task sequence error
Hello,
I am trying to run a powershell script that runs via sccm task sequencer via "task sequence media" option.
The goal is to recieve user input right after the os installation to change computer name since the step after that is to add that computer to the domain.
After i create the media (USB), i run it and when it reaches the script part i get an error :
i.e.
if i disable this step , everything else works fine, including adding the pc to the domain - only it recives random name.
I am trying to run a powershell script that runs via sccm task sequencer via "task sequence media" option.
The goal is to recieve user input right after the os installation to change computer name since the step after that is to add that computer to the domain.
After i create the media (USB), i run it and when it reaches the script part i get an error :
i.e.
if i disable this step , everything else works fine, including adding the pc to the domain - only it recives random name.
what command / task are you running for the user to enter the username? show us the script you are running
ASKER
this is what i enter at the sccm (task sequence) - powershell.exe -command “set-ExecutionPolicy Unrestricted; cpi %SCRIPTROOT%\OSDComputerNa mePrompt.p s1 -destination c:\; c:\OSDComputerNamePrompt.p s1; ri c:\*.ps1; set-ExecutionPolicy restricted”
And this is the script within OSDComputerNamePrompt.ps1 :
function Load-Form {
$Form.Controls.Add($TBComp uterName)
$Form.Controls.Add($GBComp uterName)
$Form.Controls.Add($Button OK)
$Form.Add_Shown({$Form.Act ivate()})
[void] $Form.ShowDialog()
}
function Set-OSDComputerName {
$ErrorProvider.Clear()
if ($TBComputerName.Text.Leng th -eq 0) {
$ErrorProvider.SetError($G BComputerN ame, "Please enter a computer name")
}
else {
if ($TBComputerName.Text.Leng th -gt 15) {
$ErrorProvider.SetError($G BComputerN ame, "Computer name cannot be more than 15 characters")
}
else {
$OSDComputerName = $TBComputerName.Text.Repla ce("[","") .Replace(" ]","").Rep lace(":"," ").Replace (";","").R eplace("|" ,"").Repla ce("=","") .Replace(" +","").Rep lace("*"," ").Replace ("?","").R eplace("<" ,"").Repla ce(">","") .Replace(" /","").Rep lace("\"," ").Replace (",","")
$TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironmen t
$TSEnv.Value("OSDComputerN ame") = "$($OSDComputerName)"
$Form.Close()
}
}
}
[void][System.Reflection.A ssembly]:: LoadWithPa rtialName( "System.Dr awing")
[void][System.Reflection.A ssembly]:: LoadWithPa rtialName( "System.Wi ndows.Form s")
$Global:ErrorProvider = New-Object System.Windows.Forms.Error Provider
$Form = New-Object System.Windows.Forms.Form
$Form.Size = New-Object System.Drawing.Size(285,14 0)
$Form.MinimumSize = New-Object System.Drawing.Size(285,14 0)
$Form.MaximumSize = New-Object System.Drawing.Size(285,14 0)
$Form.StartPosition = "CenterScreen"
$Form.SizeGripStyle = "Hide"
$Form.Text = "Enter Computer Name"
$Form.ControlBox = $false
$Form.TopMost = $true
$TBComputerName = New-Object System.Windows.Forms.TextB ox
$TBComputerName.Location = New-Object System.Drawing.Size(25,30)
$TBComputerName.Size = New-Object System.Drawing.Size(215,50 )
$TBComputerName.TabIndex = "1"
$GBComputerName = New-Object System.Windows.Forms.Group Box
$GBComputerName.Location = New-Object System.Drawing.Size(20,10)
$GBComputerName.Size = New-Object System.Drawing.Size(225,50 )
$GBComputerName.Text = "Computer name:"
$ButtonOK = New-Object System.Windows.Forms.Butto n
$ButtonOK.Location = New-Object System.Drawing.Size(195,70 )
$ButtonOK.Size = New-Object System.Drawing.Size(50,20)
$ButtonOK.Text = "OK"
$ButtonOK.TabIndex = "2"
$ButtonOK.Add_Click({Set-O SDComputer Name})
Load-Form
And this is the script within OSDComputerNamePrompt.ps1 :
function Load-Form {
$Form.Controls.Add($TBComp
$Form.Controls.Add($GBComp
$Form.Controls.Add($Button
$Form.Add_Shown({$Form.Act
[void] $Form.ShowDialog()
}
function Set-OSDComputerName {
$ErrorProvider.Clear()
if ($TBComputerName.Text.Leng
$ErrorProvider.SetError($G
}
else {
if ($TBComputerName.Text.Leng
$ErrorProvider.SetError($G
}
else {
$OSDComputerName = $TBComputerName.Text.Repla
$TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironmen
$TSEnv.Value("OSDComputerN
$Form.Close()
}
}
}
[void][System.Reflection.A
[void][System.Reflection.A
$Global:ErrorProvider = New-Object System.Windows.Forms.Error
$Form = New-Object System.Windows.Forms.Form
$Form.Size = New-Object System.Drawing.Size(285,14
$Form.MinimumSize = New-Object System.Drawing.Size(285,14
$Form.MaximumSize = New-Object System.Drawing.Size(285,14
$Form.StartPosition = "CenterScreen"
$Form.SizeGripStyle = "Hide"
$Form.Text = "Enter Computer Name"
$Form.ControlBox = $false
$Form.TopMost = $true
$TBComputerName = New-Object System.Windows.Forms.TextB
$TBComputerName.Location = New-Object System.Drawing.Size(25,30)
$TBComputerName.Size = New-Object System.Drawing.Size(215,50
$TBComputerName.TabIndex = "1"
$GBComputerName = New-Object System.Windows.Forms.Group
$GBComputerName.Location = New-Object System.Drawing.Size(20,10)
$GBComputerName.Size = New-Object System.Drawing.Size(225,50
$GBComputerName.Text = "Computer name:"
$ButtonOK = New-Object System.Windows.Forms.Butto
$ButtonOK.Location = New-Object System.Drawing.Size(195,70
$ButtonOK.Size = New-Object System.Drawing.Size(50,20)
$ButtonOK.Text = "OK"
$ButtonOK.TabIndex = "2"
$ButtonOK.Add_Click({Set-O
Load-Form
powershell.exe -executionpolicy bypass -command %SCRIPTROOT%\OSDComputerNamePrompt.ps1
https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Core/About/about_PowerShell_exe?view=powershell-5.1
ASKER
Can you please elaborate ?
you can also do it directly in the task sequence
https://social.technet.microsoft.com/Forums/windows/en-US/7db09095-fe2a-424d-a87d-7ecbafd9f070/run-powershell-script-using-a-task-sequence?forum=configmanagerosd
https://social.technet.microsoft.com/Forums/windows/en-US/7db09095-fe2a-424d-a87d-7ecbafd9f070/run-powershell-script-using-a-task-sequence?forum=configmanagerosd
ASKER
I am already using it as a task sequence, but i am getting an error when the script starts to run via the task sequencer.
please review my original post at the top again.
please review my original post at the top again.
Hello,
Is there anything showing in the smsts.log that might indicate why it is failing? Are you able to post a snapshot of the task sequence, specifically the step that is running the powershell script?
Is there anything showing in the smsts.log that might indicate why it is failing? Are you able to post a snapshot of the task sequence, specifically the step that is running the powershell script?
ASKER
i dont see how \ where i get the smsts log file since i run the installation via USB into a blank SSD. (cant find any on the USB).
Capture.PNG
Capture.PNG
I would suggest that rather than using the 'Run command Line' step, you try using the 'Run PowerShell Script' step instead (as David suggested above):
This allows you to add a script from a package or add a script directly without the need of a package (don't forget to change the execution policy setting!):
Also, I would try running the step after the format and partition step but before the Apply OS step.
As for the smsts.log, that could be in one of several places. See the link below:
https://www.ronnipedersen.com/2014/08/12/sccm-2012-r2-smsts-log-located/
This allows you to add a script from a package or add a script directly without the need of a package (don't forget to change the execution policy setting!):
Also, I would try running the step after the format and partition step but before the Apply OS step.
As for the smsts.log, that could be in one of several places. See the link below:
https://www.ronnipedersen.com/2014/08/12/sccm-2012-r2-smsts-log-located/
ASKER
I have tried moving it to a step before the OS step + running powershell script - still getting the error.
regarding the log file - the SSD is empty so there are no files there.
regarding the log file - the SSD is empty so there are no files there.
try reducing your script to
$computername = Read-host -Prompt "Input the Computer Name"
Set-OSDComputerName = $computername
ASKER
Tried that 2 lines script , still getting error.
what is the error?
ASKER
Same error as at the start of this post.
Do you have Command Support enabled on the Boot Image (Boot Image properties -> Customization tab)? If so you can hit F8 when the error occurs to bring up a command prompt. From there you should be able to get to the WinPE drive (possibly x:\) where the smsts.log should be.
ASKER
"Do you have Command Support enabled on the Boot Image (Boot Image properties -> Customization tab)? "
I have enabled it and yet the f8 key does nothing at any phase during the task sequence run.
I have enabled it and yet the f8 key does nothing at any phase during the task sequence run.
Do you have to use powershell? We use a batch file for the same thing that works well for us.
ASKER
No i dont have to use powershell.
Can you share your batch file solution please ?
Can you share your batch file solution please ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes ! the vbs script worked like a charm !
Many thanks ! :)
Many thanks ! :)