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.
User avatar
nodgiles
Posts: 11
Joined: Tue Oct 30, 2012 2:49 am

Fix my account + PSStudio error

Post by nodgiles » Mon Apr 29, 2013 2:59 pm

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
Joined: Tue Oct 30, 2012 2:49 am

Re: Fix my account + PSStudio error

Post by nodgiles » Mon Apr 29, 2013 3:10 pm

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. Reif
Posts: 197
Joined: Mon Jan 14, 2013 10:43 am

Re: Fix my account + PSStudio error

Post by J. Reif » Mon Apr 29, 2013 3:18 pm

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
Joined: Thu Aug 18, 2011 4:56 am

Re: Fix my account + PSStudio error

Post by davidc » Mon Apr 29, 2013 3:57 pm

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
Joined: Tue Oct 30, 2012 2:49 am

Re: Fix my account + PSStudio error

Post by nodgiles » Tue Apr 30, 2013 7:14 am

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.