%ScriptRoot% launches a very simple script that doesn't work
Hi all
I'm trying to run a simple script from the script directory.
Copy-Item -Path ".\Scripts" -Destination "C:\Windows\Setup" -Recurse -Force
It copies locally to the C:\Windows\Setup\ folder the script directory which contains other scripts.
It works under MDT, no problem, but under PSD, it doesn't!
What am I doing wrong?
xcopy works, use the "run command line" task sequence step instead.
xcopy [source] [destination] /option
Example:
xcopy "%ScriptRoot%\CustomStartMenu\Win11\start2.bin" "C\Users\Default\AppData\Local\Packages\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\LocalState" /y
No, that doesn't work either!
The task sequence stops and I get an error in the PSD: "Task sequence failed, Return Code is -2147467259"
In the smsts.log, I get this error:
I don't know what to do anymore?
%ScriptRoot% is not present in the Variables.dat. %DeployRoot% does not work but is initialized in the file
but it crashes every time the task sequence starts...
Task sequence failed, Return Code is -2147467259
I'm tired of searching... I'm reinstalling the entire server!
it works, but looks like you are using a SMB share path ( \ \Servername\path ) instead of %ScriptRoot% variable in your command line field, which isn't supported with PSD.
Also, try without the \ * or at least without the asterisk * after the source path
I'm reinstalling the server. I'll keep you posted! Thank you for your help!
It doesn't work...
result on the workstation
smsts.log
I see you are trying to move a whole folder's contents (recursive) from your deployment share to the computer being imaged.
Unfortunately, xcopy cannot do this in PSD. You will need to use something like Invoke-WebRequest to download a folder's contents from the web server the PS deployment share is being hosted on, to a local directory on the computer.
You will also need to pass windows credentials along with the invoke-webrequest, but you could also enable Anonymous Authentication along side Windows Authentication (Windows authentication is needed otherwise it breaks the PE environment authentication). If you choose to enable Anonymous Authentication for your deployment share, make sure you only allow it for directories that don't have any sensitive data in them.
I use this powershell script to achieve this - Start-DirDownload.ps1
If you want items to stream faster, hide the progress bar by entering $ProgressPreference = 'SilentlyContinue' after the first Invoke-WebRequest entry you see in the script.
Thank you very much for your help!
The scripts are finally copied to the correct location: C:\Windows\Setup\Scripts
But these scripts then run from the local directory, and it doesn't work...
Under PSD :
Under PSD :
No scripts run (they run but do nothing). These scripts work under MDT with the same parameters , and they work when launched manually.
Under MDT :
This is going to drive me crazy....
Good to hear the directory download script at least worked!
What are the reason(s) you are trying to run the script from a directory local in Windows, but using the deployment process to execute it?
Are they possibly designed in a way where you could just run the script from the deployment share (just entering DefaultUser.ps1 in the "Powershell Script" field in the task step), which then should process locally on the computer being imaged anyway?
Because it's easier to do it locally (no network issues, no rights issues, etc.)...
And because we can reapply it whenever we want!
And because I prefer it to be local for the support teams, it saves me from giving them access to the network share!
I have a different way of doing it. Install it as an application with the needed contents in your case the script folder followed with a bat script that has the copy command to copy your scripts folder to the needed location. Then when you scope the application out in the Applications just specify the bat file as the install command. Add to your task sequence and d4d. No need to mess with importing or using smb shares or none of that mess.
@Valceen PSD itself has a local caching machanism already builtin. It creates copies of several folders below your deployment share in C:\MININT\Cache. I don´t know exaclty which folders, but at least "Scripts" and "Tools", including their subfolders, are there.
Just name the script to run and it should be fine.
Maybe you also need to update the PSDPowershell.ps1 script with the one I posted here, so that relative paths are handled correctly.
@daooze is correct PSD works by copying the contents over HTTP/HTTPS to the local cache folder, then it executes it from there. You could put it in the scripts folder, and it should copy the contents over. Then it sets the environment variables to that location. PSD does not work well with UNC paths anymore...
But I noticed in your screenshots your task sequences look like MDT task sequences. While this is the template to use for MDT version, it is NOT the one to for PSD. The PSD Client Standard one is simpler. Are you using the PSD Task Sequence templates? Based on screenshots, those look like MDT Templates.
Here is what a PSD Client/Server Standard Task Sequence will look like.
YOU MUST USE THESE when using PSD! While this is not ideal, it does mean you must create new TS using that template (DO NOT COPY from other deploymentshares). You can verify by looking here:
The reason for this is, PSD does not use the PHASE property where MDT did and some other things. Behind the scenes, the TS steps are wsf/vbs scripts and PSD replaces them with ps1, but not all; it is not 1:1.
But with all that I am running a PSD task sequence that should create two shortcuts via a ps1 script on the desktop. I am testing both Run PowerShell script and Run command line to see if they both honor %SCRIPTROOT%
I will show the results after its complete...
After testing this. I see two results.
While it did copy them to the script folder; i have something flawed in the quick script i wrote....
- Running the command line will translate %SCRIPTROOT% to literal path (eg. C:\MININT\Cache\Scripts). But Mine was stuck runing because I was dumb and running parameters in start in box
- Running the PowerShell step will translate it even in the parameters
Just set your your files that you want copied over in the scripts folder. Use a command line sequence in the TS to run your copy files powershell script (e.g. powershell -ExecutionPolicy Bypass -File "%scriptroot%\script.ps1"
I'd given up! And I came back a few weeks later and I certainly have the solution thanks to you! I'm re-installing the PSD platform and testing again. Thanks everyone. I'll get back to you in a few days!
I rebuilt a PSD server ! And it still doesn't work!
I followed @Daooze's recommendations... I replaced the PSDPowershell.ps1 file with @Daooze's.
Then I launched my scripts from %SCRIPTROOT%... But it doesn't work. The script starts and stops there:
I'll give you the task sequences in XML. rename it to xml ts.txt
I also tested with the original PSDPowershell.ps1 but I have the same errors!
The same scripts work with MDT!
In short, nothing works with PSD.
Plus this error occurs at any time, during or before the "Install Operating System"...
I'm going crazy!
When looking at the Tx in notepad, i think i see what is going on and may be the issue:
A default run action by PSD does this:
Where in yours I see that your just calling the ps1 file.
Try doing:
powershell -file %SCRIPTROOT%\Copy-Utilisateur.ps1
I also noticed the path. Are the scripts you have under the scripts directory or under script folder in the scripts directory?
"under script folder in the scripts directory" I renamed it to "Perso" to avoid problems.
I run the scripts as you told me and it works (I have to edit one script at this stage and it seems to work if I check the "Continue on error" box). But it's at the end that it goes to waste.
Finally, I have a script that places the machine in the domain (my PSD server is in a workgroup)....
When I reboot, I log into the domain and I get this error because the deployment share is no longer accessible!