Link to home
Start Free TrialLog in
Avatar of Mikhail Malorodov
Mikhail MalorodovFlag for Israel

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 :
User generated image
i.e.
if i disable this step , everything else works fine, including adding the pc to the domain - only it recives random name.
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

what command / task are you running for the user to enter the username? show us the script you are running
Avatar of Mikhail Malorodov

ASKER

this is what i enter at the sccm (task sequence) - powershell.exe -command “set-ExecutionPolicy Unrestricted; cpi %SCRIPTROOT%\OSDComputerNamePrompt.ps1 -destination c:\; c:\OSDComputerNamePrompt.ps1; ri c:\*.ps1; set-ExecutionPolicy restricted”


And this is the script within OSDComputerNamePrompt.ps1 :


function Load-Form {
    $Form.Controls.Add($TBComputerName)
    $Form.Controls.Add($GBComputerName)
    $Form.Controls.Add($ButtonOK)
    $Form.Add_Shown({$Form.Activate()})
    [void] $Form.ShowDialog()
}

function Set-OSDComputerName {
    $ErrorProvider.Clear()
    if ($TBComputerName.Text.Length -eq 0) {
        $ErrorProvider.SetError($GBComputerName, "Please enter a computer name")
    }
    else {
        if ($TBComputerName.Text.Length -gt 15) {
            $ErrorProvider.SetError($GBComputerName, "Computer name cannot be more than 15 characters")
        }
        else {
            $OSDComputerName = $TBComputerName.Text.Replace("[","").Replace("]","").Replace(":","").Replace(";","").Replace("|","").Replace("=","").Replace("+","").Replace("*","").Replace("?","").Replace("<","").Replace(">","").Replace("/","").Replace("\","").Replace(",","")
            $TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment
            $TSEnv.Value("OSDComputerName") = "$($OSDComputerName)"
            $Form.Close()
        }
    }
}

[void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

$Global:ErrorProvider = New-Object System.Windows.Forms.ErrorProvider

$Form = New-Object System.Windows.Forms.Form    
$Form.Size = New-Object System.Drawing.Size(285,140)  
$Form.MinimumSize = New-Object System.Drawing.Size(285,140)
$Form.MaximumSize = New-Object System.Drawing.Size(285,140)
$Form.StartPosition = "CenterScreen"
$Form.SizeGripStyle = "Hide"
$Form.Text = "Enter Computer Name"
$Form.ControlBox = $false
$Form.TopMost = $true

$TBComputerName = New-Object System.Windows.Forms.TextBox
$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.GroupBox
$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.Button
$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-OSDComputerName})

Load-Form
Can you please elaborate ?
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.
Avatar of N
N

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?
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
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):

User generated image
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!):

User generated image
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/
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.
try reducing your script to

$computername = Read-host -Prompt "Input the Computer Name" 
Set-OSDComputerName = $computername

Open in new window

Tried that 2 lines script , still getting error.
what is the error?
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.
to use powershell the boot image also has to have .net framework added. This is from MDT which you should probably be using unless you support >1500 machines
User generated image
"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.
Do you have to use powershell?  We use a batch file for the same thing that works well for us.
No i dont have to use powershell.
Can you share your batch file solution please ?
ASKER CERTIFIED SOLUTION
Avatar of N
N

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes ! the vbs script worked like a charm !

Many thanks ! :)