I am trying to execute a Powershell script via the runonce reg-key, each time it is executed, the script is opened in notepad instead of executing. Not sure what i can change
Associated PS1 files with Powershell
Added the top line to start the script with admin privileges.
added -ExecutionPolicy bypass -file the Powershell line
All which do not solve the problem, Does anyone have a suggestions.
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit } Set-Location -Path C:\Windows\Admin $LogFile = "C:\Windows\Admin\SetupLog.txt" if (-not (Test-Path LogFile)) { Echo "Clearing ALL systems Events" wevtutil el | Foreach-Object {wevtutil cl "$_"}& "C:\Program Files\CCleaner\CCleaner64.exe" /auto ipconfig /release Out-File -FilePath LogFile add-content LogFile "Phase01 $((Get-Date).ToString()) `t Windows events Logs have been cleared." Set-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce" -Name "NewSetup" -Value "C:\Windows\System32\WindowsPowerShell\v1.0\Powershell.exe -ExecutionPolicy bypass -file `"C:\Windows\Admin\VMSetup.ps1`" -windowstyle hidden" shutdown /s /t 0 /c "Image Ready" } else{ Echo "These is nothing to do For PHASE ONE" } dsmove CN=$Env:computername,CN=Computers,DC=DOMAIN,DC=local -d DOMAIN.local -newparent OU=VDIComputers,DC=DOMAINE,DC=local -u USERNAME@DOMAINE.local -p PASSWORD add-content LogFile "Phase02 $((Get-Date).ToString()) `t Registed MS Windows and MS Office"
Any assistance would be greatly appreciated. thank you in advance.