Menu

Run script after OOBE

robina80
2025-04-29
2025-05-02
  • robina80

    robina80 - 2025-04-29

    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

     
  • robina80

    robina80 - 2025-04-30

    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
  • Steven Shiau

    Steven Shiau - 2025-04-30

    Thanks for sharing that,

    Steven

     
  • robina80

    robina80 - 2025-05-02

    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

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.