none
MDT 2013 and PowerShell Task RRS feed

  • Question

  • Hi Everyone,

    Having searched and tried several solutions on this forum, I'm not getting anywhere so thought I would ask.

    I have a task sequence for installing Windows 10 (1809). It works - the machine deploys. This was the first part of testing. I am now moving on to building it up to how I want it. This involes running a powershell script which I have put in the 'Custom Tasks' part of the task sequence.

    No matter what I do - I cannot get this script to work. The script is located in %SCRIPTROOT% so should work as others do - but it doesn't.

    The command I have to run the script is:

    

    The deployment runs but the script doesn't work. A look at the logs shows me the following errors:

    I am assuming it cannot run because it does not have the correct privileges. I've tried running it via the command line and code I've found on the internet, but I just cannot get it to run.

    If it is privileges - then I build the machines using a service account which has access to the deployment server and access to our software installation (PDQDeploy) server.

    It's got me tearing my hair out and is probably something really easy to fix for those in the know.

    It's all based on this webcast video from PDQDeploy : https://www.youtube.com/watch?v=M4oHCfVD--U

    Thanks all,

    Gareth


    Tuesday, July 9, 2019 1:53 PM

All replies

  • It depends on what the script does. Some PowerShell scripts must be executed locally, so usually you make a run command line task that copies the script to a temp location on the local drive and then you make a run PowerShell script task the executes it from the local drive.

    Judging by the log, it ran your script but throws a security error. It could be due to what I mentioned above.


    Daniel Vega

    Tuesday, July 9, 2019 1:57 PM
  • Hi Daniel,

    Thank you for getting in touch with me. Here is the script I am running:

    netsh advfirewall set allprofiles state off
    ipconfig /registerdns
    
    Invoke-Command -ComputerName ygg-vmanage.school.education.swansea.sch.uk
    			   -ScriptBlock
    			   {ipconfig /flushdns; pdqdeploy.exe Deploy -Package "New PC Setup" -Target $args[0]}
    			   -Arguements $env:COMPUTERNAME 2>&1
    
    start-sleep 30
    while(test-path "C:\Windows\AdminArsenal\PDQDeployRunner\service-1.lock"){
    start-sleep 30
    }

    Thanks

    Gareth

    Tuesday, July 9, 2019 2:11 PM
  • Try copying the script to the local drive and then execute it from there.


    Daniel Vega

    Tuesday, July 9, 2019 2:39 PM
  • Run Command Line - Command Line: powershell.exe -command "Set-ExecutionPolicy Bypass"
    Run PowerShell Script - PowerShell Script: %SCRIPTROOT%\Script.ps1

    Wednesday, July 10, 2019 12:17 AM
  • Hello Gareth,

    Instead of copying the ps1 file directly to scripts directory. Just create a directory inside DeploymentShare\Scripts\<FolderName> and copy the script inside the created directory and execute it.

    The Run Command should be like this

    cmd.exe /c  powershell.exe -executionpolicy bypass -file "%SCRIPTROOT%\<FolderName>\Filename.ps1"

    I will recommend you to execute the script manually before proceeding with Tasksequence to save your troubleshooting time. 

    • Edited by JiteshKumar Wednesday, July 10, 2019 4:19 PM
    Wednesday, July 10, 2019 4:17 PM
  • HI All,

    Still having a nightmare with this and have tried everything people have recommended. I've now split the whole task into smaller bits for trouble shooting.

    1. Copy PSExec to the local machine (this works)
    2. Copy the pdq_deploy script to the local machine (this works)
    3. Run the script - this doesn't work despite the task sequence saying it does.

    Steps 1 and 2 are working fine. Step 3 doesn't work. It looks to work but nothing gets installed via pdqdeploy. The command I am using is:

    powershell.exe -noprofile -command "Set-ExecutionPolicy Bypass LocalMachine"; powershell.exe -file "C:\Windows\pdq_deploy_psexec.ps1"

    Although I have tried several different commands and locations for storing the script. I've tested this line after logging in as a domain admin and it works fine.

    During the deployment the machine looks to be doing something, but nothing gets installed despite the task sequence showing as successful.

    I am assuming it maybe a permissions issue. MDT logs the machine on as an local Administrator - is this the issue?

    I've tried running the command line as a the MDT service Build Account which we use- but this didn't work either. Something is stopping it - but I'm lost to what it could be.

    Do I need to move the command somewhere else? Or somehow get the script running as a different user?

    Thanks everyone so far - appreciate the time taken to comment for me.

    Gareth



    • Edited by gjed Thursday, July 11, 2019 12:55 PM
    Thursday, July 11, 2019 12:53 PM
  • The command which you're using is it executing manually?

    It seems that issue with Command line. Have to tried the command which I have shared. 

    Don’t copy the content inside Window directory, It might be accessibility issue. Try to create custom directory and copy the script, execute it


    • Edited by JiteshKumar Thursday, July 11, 2019 2:00 PM
    Thursday, July 11, 2019 1:56 PM
  • Hi there - so I've changed it all to how you say but am now getting this:

    If I press R then it runs as I expect. However this is part of a deployment so I want it to run silently. I've used your command:

    cmd.exe /c  powershell.exe -executionpolicy bypass -file "%SCRIPTROOT%\MyScripts\pdq_deploy_psexec.ps1"

    I should point out that the file isn't blocked in anyway so not sure why I need to use the cmdlet - I'll add it anyway I guess.

    Thankfully it's Friday. I've been on this since Monday!

    Gareth


    • Edited by gjed Friday, July 12, 2019 10:17 AM
    Friday, July 12, 2019 10:16 AM
  • I think you're attempting to run over network. Can you please run the same command manually based on result later on integrate with TS
    Sunday, July 14, 2019 1:34 PM
  • Hi there - so I've changed it all to how you say but am now getting this:

    If I press R then it runs as I expect. However this is part of a deployment so I want it to run silently. I've used your command:

    cmd.exe /c  powershell.exe -executionpolicy bypass -file "%SCRIPTROOT%\MyScripts\pdq_deploy_psexec.ps1"

    I should point out that the file isn't blocked in anyway so not sure why I need to use the cmdlet - I'll add it anyway I guess.

    Thankfully it's Friday. I've been on this since Monday!

    Gareth


    Did you download that script? If so either run

    gci -recurse C:\FILELOCATION | Unblock-File

    or you can right click on the script, go to properties and look to see if there's a checkbox for "Unblock"


    Daniel Vega

    Tuesday, July 16, 2019 7:09 PM
  • Hi there all,

    As suspected - it was a permissions error. Reverting back to a full admin user sorted it and it now looks as if II have another problem to solve.

    Thanks everyone that helped - learnt a lot.

    Gareth

    Thursday, July 18, 2019 1:55 PM