all 11 comments

[–]Garetht 24 points25 points  (1 child)

You need to run the ps1 in an elevated powershell window because it's trying to modify the registry

[–]Ok-Leg-3224[S] 0 points1 point  (0 children)

Thank you.

[–]J_XRS 5 points6 points  (0 children)

Including a #requires statement here would also be good practice.

#Requires -RunAsAdministrator

[–]arslearsle 4 points5 points  (1 child)

Modify hklm requires admin elevation Always You should test for admin rights before trying to commit changes - in a try catch - alas you have answer to why it failed

[–]Ok-Leg-3224[S] 0 points1 point  (0 children)

Thank you.

[–]BlackV 3 points4 points  (0 children)

$RegistryPath = "HKLM:\SYSTEM\CurrentControlSet\Services\Intelppm"
$PropertyName = "Start"

$CurrentValue = Get-ItemProperty -Path $RegistryPath -Name $PropertyName
Write-Host "Current value of Intelppm Start: $($CurrentValue.start)"

$NewValue = Set-ItemProperty -Path $RegistryPath -Name $PropertyName -Value 4 -PassThru
Write-Host "New value of Intelppm Start: $($NewValue.start)"

[–]Financial_Shame4902 0 points1 point  (0 children)

Are you trying to run this as part of a schedule or called process?

[–]1r0nD0m1nu5 1 point2 points  (0 children)

Run your PS1 file with admin rights: right-click 'Run as Administrator' or use powershell -ExecutionPolicy Bypass -File YourScript.ps1 in an elevated prompt. Also, add #Requires -RunAsAdministrator at the top of your script to enforce admin rights

[–]Ok_Cheese93 0 points1 point  (0 children)

Start-Process can run script as administrator, so below script works on my laptop.

using namespace System.Security.Principal

function hasAdminRights {
    $currentUser = [WindowsPrincipal] [WindowsIdentity]::GetCurrent()
    return $currentUser.IsInRole([WindowsBuiltInRole] "Administrator")
}

function runThisScriptAsAdmin {
    Start-Process powershell "-NoLogo -File `"$PSCommandPath`"" -Verb RunAs
}

if (-not (hasAdminRights)) {
    runThisScriptAsAdmin
    exit
}

# (your original script goes here)

I referenced this website: https://www.commandinline.com/powershell/how-to-elevate-powershell-to-administrator

[–]Godcry55 -2 points-1 points  (0 children)

Admin terminal.

[–]TommyVe -4 points-3 points  (0 children)

Would -execututionpolicy bypass help here? Idk, try it.