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
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
Thanks for sharing that,
Steven
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
Log in to post a comment.
ok ive done this and it works
and my bat is just this
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
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)
Thanks for sharing that,
Steven
ok scrap the local GPO done this and it works