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 SUBSCRIPTION NUMBERS, LICENSE 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.
User avatar
zeograz
Posts: 31
Joined: Thu Jan 17, 2008 2:55 am

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

Post by zeograz » Mon Oct 07, 2019 7:42 am

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
Site Admin
Posts: 351
Joined: Sun Mar 03, 2013 12:42 pm

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

Post by mxtrinidad » Mon Oct 07, 2019 8:00 am

Ah! I see now. Let's take a look at this issue and get back to you.
Thanks

User avatar
mxtrinidad
Site Admin
Posts: 351
Joined: Sun Mar 03, 2013 12:42 pm

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

Post by mxtrinidad » Mon Oct 07, 2019 8:20 am

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: 7049
Joined: Tue May 29, 2007 4:43 pm

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

Post by Alexander Riedel » Mon Oct 07, 2019 8:26 am

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: 7049
Joined: Tue May 29, 2007 4:43 pm

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

Post by Alexander Riedel » Mon Oct 07, 2019 8:28 am

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
Site Admin
Posts: 351
Joined: Sun Mar 03, 2013 12:42 pm

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

Post by mxtrinidad » Mon Oct 07, 2019 8:37 am

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 270 times

User avatar
zeograz
Posts: 31
Joined: Thu Jan 17, 2008 2:55 am

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

Post by zeograz » Mon Oct 07, 2019 1:10 pm

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 228 times
Thanks!
Mark

User avatar
zeograz
Posts: 31
Joined: Thu Jan 17, 2008 2:55 am

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

Post by zeograz » Wed Oct 09, 2019 5:13 am

Is anyone else able to duplicate/refute the error in this version?
Thanks