-
-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Running powershell script with admin rights #745
Comments
Sadly not at the moment.
I may be able to offer a workaround though. I haven't tested this but I think this could potentially work: What you can do is create a task in Windows Task Scheduler beforehand using its UI and configure your powershell script to run as elevated there. Then it should be possible to call that task in ADM without administrator rights within powershell: https://learn.microsoft.com/en-us/powershell/module/scheduledtasks/start-scheduledtask?view=windowsserver2019-ps The flow would be something like this
|
@Spiritreader Thanks for your suggested workaround. I have successfully created the scheduled tasks. Scripts:
- Name: Powershell Example
Command: powershell
ArgsLight: [ -Command "Start-ScheduledTask -TaskName NucLedDay" ]
ArgsDark: [ -Command "Start-ScheduledTask -TaskName NucLedNight" ] It seems you had extra quotes around the argument and it fails:
|
ok, it seems I got it working with following syntax: Enabled: true
Component:
Scripts:
- Name: Set NUC brightness
Command: powershell
ArgsLight:
- -Command
- "Start-ScheduledTask -TaskName NucLedDay"
ArgsDark:
- -Command
- "Start-ScheduledTask -TaskName NucLedNight"
AllowedSources: [Any] |
the example you provided doesn't seem like it was from our documentation. This is the original example: - Name: Powershell Example
Command: powershell
ArgsLight: [C:\test.ps1, -message light -emotion 'happy']
ArgsDark: [C:\test.ps1, -message dark -emotion 'happy']
AllowedSources: [Any] There are two "arguments", one is the script path, the other one are the arguments as a whole. This (what you posted earlier) is incorrect syntax: Scripts:
- Name: Powershell Example
Command: powershell
ArgsLight: [ -Command "Start-ScheduledTask -TaskName NucLedDay" ]
ArgsDark: [ -Command "Start-ScheduledTask -TaskName NucLedNight" ] It uses one single argument but also quotes, which powershell won't understand. What you probably meant to do is this: Enabled: true
Component:
Scripts:
- Name: Set NUC brightness
Command: powershell
ArgsLight: ["-Command", "Start-ScheduledTask -TaskName NucLedDay"]
ArgsDark: ["-Command", "Start-ScheduledTask -TaskName NucLedNight"]
AllowedSources: [Any] but it works either way. Your way is just the long way of defining lists in yaml, as it contracts to the bracket style if you minify it. Never mind that though, I'm glad you got it working! :) |
I'm trying to change the brightness of my NUC leds at night and the only way I was able to do that is through WMI
I can call that from a powerwhell script, but it only works with admin permissions. Is there anything I can do?
The text was updated successfully, but these errors were encountered: