Psf Out-Gridview -Passthru | Restart-Service produces error

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 4 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
zeograz
Posts: 31
Last visit: Tue Aug 18, 2020 12:31 pm

Psf Out-Gridview -Passthru | Restart-Service produces error

Post by zeograz »

Product, version and build: Powershell Studio 5.6.167.0
32 or 64 bit version of product: 64-Bit
Operating system: Win 10 Ver 1809
64 bit OS: 64-Bit


$buttonRUN_Click={

(Get-Service | where { $_.Status -eq 'Running' }) | sort | Out-GridView -outputmode Single -Title "Restart Service" | Restart-Service
# (Get-Service | where { $_.Status -eq 'Running' }) | sort | Out-GridView -Passthru -Title "Restart Service" | Restart-Service (Produces same error in
Powershell studio when running from form)
}

Produces this error (after selecting a service to restart in ogv window), when run from Powershell Studio Form (but not when running in regular Powershell window on same system):

>> Running (Confirmation.psf) Script...
>> Platform: V5 64Bit (STA) (Forced)
ERROR: Restart-Service : Service 'World Wide Web Publishing Service (W3SVC)' cannot be stopped due to the following error: Cannot open W3SVC service on computer '.'.
Confirmation.psf (867, 4): ERROR: At Line: 867 char: 4
ERROR: + Restart-Service
ERROR: + ~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : CloseError: (System.ServiceProcess.ServiceController:ServiceController) [Restart-Service], ServiceCommandException
ERROR: + FullyQualifiedErrorId : CouldNotStopService,Microsoft.PowerShell.Commands.RestartServiceCommand
ERROR:
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: Psf Out-Gridview -Passthru | Restart-Service produces error

Post by mxtrinidad »

Ah! I see now. Let's take a look at this issue and get back to you.
Thanks
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: Psf Out-Gridview -Passthru | Restart-Service produces error

Post by mxtrinidad »

OK! The issue you're experiencing is due to admin rights.

You need to open PowerShell Studio as an Administrator in order for the restart service to work in the form.
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 20
Been upvoted: 37 times

Re: Psf Out-Gridview -Passthru | Restart-Service produces error

Post by Alexander Riedel »

This is usually a permission problem and sounds similar to this:
https://serverfault.com/questions/35742 ... powershell
Your 'regular' Powershell console may run in admin mode (it is easy to miss that caption indicator), so check that.
It is also possible that the threading model interferes, but the error message points more towards permissions.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 20
Been upvoted: 37 times

Re: Psf Out-Gridview -Passthru | Restart-Service produces error

Post by Alexander Riedel »

Also, you do not need to run PowerShell Studio as admin, there is a switch on the ribbon to run your scripts elevated.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: Psf Out-Gridview -Passthru | Restart-Service produces error

Post by mxtrinidad »

Easy to forget when you work all the time as an admin and already have control of your system.
PowerShellStudio_Elevation_Button_2019-10-07_11-34-46.png
PowerShellStudio_Elevation_Button_2019-10-07_11-34-46.png (31.88 KiB) Viewed 2549 times
User avatar
zeograz
Posts: 31
Last visit: Tue Aug 18, 2020 12:31 pm

Re: Psf Out-Gridview -Passthru | Restart-Service produces error

Post by zeograz »

Already tried, using that toggle switch (unfortunately get same error).

Also, simply just running the command in console window of Powershell Studio results in same error, just so you're aware.

Execution Policy verified as unrestricted in the Powershell Studio console window. However, strangely even with Elevated toggle on, same error.

Outside of Powershell Studio the error does not occur in Powershell Admin window.

Don't know if it helps, but even trying to set the execution policy (even though already verified it's unrestricted) in the Powershell Studio console window produces this error related to a Powershell registry key (also tried it after toggling the Elevated switch and restarting Powershell Studio):
PowershellStudioError.PNG
PowershellStudioError.PNG (64.31 KiB) Viewed 2507 times
Thanks!
Mark
User avatar
zeograz
Posts: 31
Last visit: Tue Aug 18, 2020 12:31 pm

Re: Psf Out-Gridview -Passthru | Restart-Service produces error

Post by zeograz »

Is anyone else able to duplicate/refute the error in this version?
Thanks
This topic is 4 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.