Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first login scripts #121

Open
lapo70 opened this issue Nov 28, 2024 · 8 comments
Open

first login scripts #121

lapo70 opened this issue Nov 28, 2024 · 8 comments

Comments

@lapo70
Copy link

lapo70 commented Nov 28, 2024

either cmd or powershell script can copy file to first login users desktop. Can You help?
Copy-Item "d:\computerregistration.exe" -Destination "$env:USERPROFILE\Desktop"
copy-Item "d:\computerregistration.cmd" -Destination "$env:USERPROFILE\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

@cschneegans
Copy link
Owner

Your second Copy-Item call is missing a closing quote character. When you inspect C:\Windows\Setup\Scripts\FirstLogon.log, you should see a error message similar to this one:

Invoke-Expression: The string is missing the terminator: ".

@lapo70
Copy link
Author

lapo70 commented Nov 28, 2024

Thanks, I just forget to put it in my request. It is there in script. firstlogon.log is empty. Firstlogon.ps1 looks like this:
$scripts = @(
{
Set-ItemProperty -LiteralPath 'Registry::HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name 'AutoLogonCount' -Type 'DWord' -Force -Value 0;
};
{
cmd.exe /c "rmdir C:\Windows.old";
};
);

& {
[float] $complete = 0;
[float] $increment = 100 / $scripts.Count;
foreach( $script in $scripts ) {
Write-Progress -Activity 'Running scripts to finalize your Windows installation. Do not close this window.' -PercentComplete $complete;
& $script;
$complete += $increment;
}
} *>&1 >> "C:\Windows\Setup\Scripts\FirstLogon.log";

@cschneegans
Copy link
Owner

Thanks, I just forget to put it in my request. It is there in script.

Well, I had checked my webserver logs (searched for »d:\computerregistration.cmd«), and the closing quote character was missing there as well.

The FirstLogon.ps1 file you posted looks incomplete – there should be a call to a custom .ps1 file in there. This link will configure the form and add the missing quote character to your script. The resulting FirstLogon.ps1 file will look like this:

$scripts = @(
  {
    Set-ItemProperty -LiteralPath 'Registry::HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name 'AutoLogonCount' -Type 'DWord' -Force -Value 0;
  };
  {
    cmd.exe /c "rmdir C:\Windows.old";
  };
  {
    Get-Content -LiteralPath 'C:\Windows\Setup\Scripts\unattend-01.ps1' -Raw | Invoke-Expression;
  };
);

& {
  [float] $complete = 0;
  [float] $increment = 100 / $scripts.Count;
  foreach( $script in $scripts ) {
    Write-Progress -Activity 'Running scripts to finalize your Windows installation. Do not close this window.' -PercentComplete $complete;
    & $script;
    $complete += $increment;
  }
} *>&1 >> "C:\Windows\Setup\Scripts\FirstLogon.log";

Note the call to C:\Windows\Setup\Scripts\unattend-01.ps1, which in turn will contain your two Copy-Item commands.

@lapo70
Copy link
Author

lapo70 commented Nov 29, 2024

Thanks. Sorry about taking too much of your time but "this link" does not change anything. I just don't know where to put unattend-01.ps1 on the form and on installation media (USB) and how command to call it should look like. In form it looks like below. I hope You have time to explain.
Run
Copy-Item "d:\computerregistration.exe" -Destination "$env:USERPROFILE\Desktop";
Copy-Item "d:\computerregistration.cmd" -Destination "$env:USERPROFILE\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup";
as a
.ps1
file.
Run
setx.exe DIRCMD "/A /O:GN /C /N"
as a
.cmd
file.

@cschneegans
Copy link
Owner

The link I posted earlier will configure the form as you did initially, but adds the missing quote character. Check the corresponding textarea control to confirm this:

image

When you then click the View .xml file or Download .xml file button, you will get an .xml file that

  • has your PowerShell code embedded in a <File path="C:\Windows\Setup\Scripts\unattend-01.ps1" transformation="Text">…</File> element,
  • calls this script file using the Get-Content -LiteralPath 'C:\Windows\Setup\Scripts\unattend-01.ps1' -Raw | Invoke-Expression; statement.

You do not have to create the unattend-01.ps1 file yourself.

@lapo70
Copy link
Author

lapo70 commented Nov 29, 2024 via email

@lapo70
Copy link
Author

lapo70 commented Nov 29, 2024

Thanks. Sorry about taking too much of your time but "this link" does not change anything. I just don't know where to put unattend-01.ps1 and how command to call it should look like.

@cschneegans
Copy link
Owner

You don't have to save or call unattend-01.ps yourself – this is handled by the autounattend.xml file automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants