• Recent
  • Unsolved
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login
  • Recent
  • Unsolved
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login

Run script after OOBE

Scheduled Pinned Locked Moved Unsolved
Windows Problems
2
6
186
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R
    robertkwild
    last edited by Apr 29, 2025, 2:22 PM

    ok ive done this and it works

    <component name="Microsoft-Windows-Deployment" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="NonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                <RunSynchronous>
                    <RunSynchronousCommand wcm:action="add">
                        <Description>firstlogon</Description>
                        <Order>1</Order>
                        <Path>C:\Users\admin\sysprep\firstlogon.bat</Path>
                    </RunSynchronousCommand>
                </RunSynchronous>
            </component>
    

    and my bat is just this

    @echo off
    
    C:\Users\admin\sysprep\SophosSetup.exe --quiet
    
    rmdir /Q /S C:\Users\admin\sysprep
    

    this works but when i try to run a powershell command that needs admin it cant do it ie

    powershell.exe -ExecutionPolicy Bypass -File path-to-ps1

    in there i just have this

    Set-LocalUser -Name “user” -PasswordNeverExpires $true

    but everytime after the sysprep and it loads into windows it hasnt done it as it hasnt got admin privs

    so how come cmd had admin but ps1 doesnt?

    any idea please

    thanks,
    rob

    R R 2 Replies Last reply Apr 29, 2025, 4:55 PM Reply Quote 0
    • R
      rodluz Developer @robertkwild
      last edited by Apr 29, 2025, 4:55 PM

      @robertkwild This isn’t a FOG issue at all but I would look into running your sysprep scripts in the SetupComplete.cmd file. I’ve never had any issues with admin privileges when running powershell scripts from it.

      https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/add-a-custom-script-to-windows-setup?view=windows-11

      Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

      Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

      Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

      R 1 Reply Last reply Apr 29, 2025, 5:36 PM Reply Quote 0
      • R rodluz moved this topic from FOG Problems on Apr 29, 2025, 4:56 PM
      • R
        robertkwild @rodluz
        last edited by Apr 29, 2025, 5:36 PM

        @rodluz thanks but doesnt this need a VL key to run those scripts?

        R 1 Reply Last reply Apr 29, 2025, 6:18 PM Reply Quote 0
        • R
          rodluz Developer @robertkwild
          last edited by Apr 29, 2025, 6:18 PM

          @robertkwild I don’t think so. A couple years ago, I imaged a Windows 11 Home machine without any license key and used the SetupComplete.cmd script without any issue.
          It won’t run it if using an OEM key, though.

          Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

          Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

          Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

          R 1 Reply Last reply Apr 30, 2025, 8:45 PM Reply Quote 0
          • R
            robertkwild @rodluz
            last edited by Apr 30, 2025, 8:45 PM

            @rodluz

            solved…

            https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-R2-and-2012/dn789190(v=ws.11)

            i used a computer startup script

            script name:
            C:\Users\admin\sysprep\firstlogon.ps1

            script parameters:
            powershell -ep Bypass

            and heres the script (just made a rough one to test and every command ran as when i logged in after the pc syspreped all commands worked)

            start-process 'C:\Users\admin\sysprep\Firefox Setup 138.0.exe' /S -wait
            
            Remove-ItemProperty -Path "HKLM:\SOFTWARE\Wow6432Node\AdventNet\DesktopCentral\DCAgent\" -Name "ImagedComputer" -Force
            
            Remove-Item -Path "HKLM:\SOFTWARE\Wow6432Node\AdventNet\DesktopCentral\DCAgent\SystemDetails" -Force
            
            Set-LocalUser -Name "user01" -PasswordNeverExpires $true
            Set-LocalUser -Name "it" -PasswordNeverExpires $true
            
            remove-item -path C:\Users\admin\sysprep -recurse -force
            
            
            1 Reply Last reply Reply Quote 0
            • R
              robertkwild @robertkwild
              last edited by May 2, 2025, 1:52 PM

              @rodluz

              ok scrap the local GPO done this and it works

              reg add HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce /v firstlogon /t REG_SZ /d powershell -noexit -ep bypass c:\users\admin\sysprep\firstlogon.ps1 /f
              
              1 Reply Last reply Reply Quote 0
              • 1 / 1
              1 / 1
              • First post
                5/6
                Last post

              211

              Online

              12.0k

              Users

              17.3k

              Topics

              155.2k

              Posts
              Copyright © 2012-2024 FOG Project