Fix my account + PSStudio 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 10 years and 10 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
nodgiles
Posts: 11
Last visit: Mon Aug 10, 2015 2:26 pm

Fix my account + PSStudio error

Post by nodgiles »

I have been a primal forms, and now PowerShell studio, user for a couple of years now. I still can not access the support forums although I have asked to have this access to be provided several times. Yes, I have already registered my product.

Once again I will post my question here since its the only access I'm allowed for this paid product.

This script returns access denied when I try to run it. If I run the EXACT same script from the built-in ISE or using powerGUI, I receive no errors and I am presented with the output I expect.
PowerShell Code
Double-click the code block to select all.
$runuser = "domain\username"
	$password = Get-Content "\\server\c$\powershell\restricted\settings.txt"
	$cred = New-Object System.Management.Automation.PSCredential -ArgumentList @($runuser,(Convertto-SecureString -String $password -AsPlainText -Force))
	$connection = $cred 
	$session = New-PSSession "domaincontroller" -credential $cred 

    invoke-command -Session $session -scriptblock {param ($session, $groups) Add-PSSnapin Quest.ActiveRoles.ADManagement 
       
    $groups = get-qadgroup -sizelimit 0 | Where-Object {$_.GroupType -match 'Security'} | select-object name | Sort-Object name 
	$groups | Out-File "\\server\c$\powershell\test.txt"
    } -argumentlist $session, $groups
	
	$gnames = Get-Content "\\server\c$\powershell\test.txt"
	Write-Host $gnames
User avatar
nodgiles
Posts: 11
Last visit: Mon Aug 10, 2015 2:26 pm

Re: Fix my account + PSStudio error

Post by nodgiles »

Even more interesting now after some troubleshooting.

If I highlight the portion of the script noted above, right click and select "run in console", its works! If I highlight the same portion of the script and say "run selection" it fails with access denied. Also if I compile the script to an exe and try to run it, it fails with access denied.
User avatar
J A Reif
Posts: 241
Last visit: Fri Mar 22, 2024 8:12 am
Answers: 1
Has voted: 1 time
Been upvoted: 1 time

Re: Fix my account + PSStudio error

Post by J A Reif »

I have fixed your account and will be moving this post to the Powershell Studio forum where your issue can be properly addressed. You may need to log out and back in order for your account changes to take effect. Sorry for the inconvenience.
June Alane Reif
SAPIEN Technologies, Inc.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Fix my account + PSStudio error

Post by davidc »

It might be PowerShell.exe has permission to access the file yet PowerShell Studio does not. Have you tried to run the script with elevation? You can select the option in the Ribbon, using the platform combobox.

Which line exactly causes the error?

David
David
SAPIEN Technologies, Inc.
User avatar
nodgiles
Posts: 11
Last visit: Mon Aug 10, 2015 2:26 pm

Re: Fix my account + PSStudio error

Post by nodgiles »

The script errors on the out-file with access denied.

I found the problem. It's a powershell version issue. The script works fine in v3 but does not run in v2. I had PSS set to version 2 but am working on a server2012 box so that's why the results were different in the ISE.
This topic is 10 years and 10 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.