0

Good morning :S.

I can enter into a PSSession and execute cmdlets just fine, however, as soon as I specify an account to use, it just throws back an access is denied error. I've even tested with the same account and password that established the PSSession. This works locally just fine.

I am trying to integrate this into an SCCM application, so there isn't a whole lot of wiggle room.

EDIT: I put an easier code that doesn't work either below:

$username = 'DOMAIN\Username'
$password = 'P@ssword'

$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential $username, $securePassword
Start-Process Notepad.exe  -Credential $credential 
#Execute variable 
$myCommand = "'C:\Program Files (x86)\PGP Corporation\PGP Desktop\pgpwde' --status --disk 0"

#Credential Variables
$username = 'DOMAIN\USERNAME'
$Password = ConvertTo-SecureString -String 'P@ssword' -Force -AsPlainText
$credential = New-Object System.Management.Automation.PsCredential -ArgumentList $username, $Password

#Expression Variable
$expression = @"
    try
    {
        & $myCommand | Out-File `C:\test.txt -Force
    }
    catch
    {
        `$_.Exception.Message | Out-File `C:\ERROR.txt -Force
    }
"@

#Execute 
Start-Process powershell.exe -ArgumentList "-c $expression" -Credential $credential
My9to5
  • 93
  • 8
  • Are you getting the "Access Denied" on `C:\ERROR.txt` or on your PS Host? – Santiago Squarzon Jul 26 '21 at 15:39
  • @SantiagoSquarzon No, there is no output at all. It blocks from running the ```Start-Process...``` – My9to5 Jul 26 '21 at 15:48
  • Try adding `-Verb RunAs` to `Start-Process`. Sounds like `$username` doesn't have permissions to run as locally. You could use this link to troubleshoot your issue: https://learn.microsoft.com/en-us/troubleshoot/windows-server/shell-experience/access-denied-runas-command-run-as-administrator. Also this post may point you in the right direction: https://stackoverflow.com/questions/28989750/running-powershell-as-another-user-and-launching-a-script/34307483 – Santiago Squarzon Jul 26 '21 at 15:56
  • I'll try that, but I am admin on the box – My9to5 Jul 26 '21 at 16:00
  • Yeah, your user might be a local admin but the user you're trying to impersonate might not be. – Santiago Squarzon Jul 26 '21 at 16:35
  • I added my credentials into the script to test, yet that didn't work. – My9to5 Jul 26 '21 at 16:54

0 Answers0