Need help with powershell script. I am writing a powershell script to grab an accounts password via AIM service and then pass that credential to be used in PSCredential.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements

Welcome Idira to LIVEcommunity!

Our community just got stronger! Explore new identity security resources, connect with experts, and discover more ways to learn and collaborate.

Meet Idira

Need help with powershell script. I am writing a powershell script to grab an accounts password via AIM service and then pass that credential to be used in PSCredential.

L0 Member

I can successfully grab the password, but keep getting an invalid username/password when trying to use it in PSCredential. I can copy and paste the password from the script and login via RDP. so i know the password is correct.

 

 

#Variables $CCPHost = "aimservice.com" $appID = "app" $safe = "safe" $accountObject = "serviceaccount" $username = "xxxxxx"   #URL for grabbing info $uriString = "https://" + $CCPHost + "/AIMWebService/api/Accounts?AppID=" + $appID + "&Query=Safe=" + $safe + ";Object=" + $accountObject   #grab all info presented via url $content = Invoke-RestMethod -Method Get -Uri $uriString -ContentType application/json|Select-Object -Property * $pass = ($content).content $password = $pass | ConvertTo-SecureString -asPlainText -Force   $mycreds = New-Object Management.Automation.PSCredential ("[email protected]", $password)   Write-Host "Removing $user access from $path" -foregroundcolor Red Start-Process powershell.exe -Credential $mycreds -ArgumentList "icacls $path /remove $user /T"

Output:

Start-Process : This command cannot be run due to the error: The user name or password is incorrect. At C:\Scripts\FullPermissions.ps1:33 char:1 + Start-Process powershell.exe -Credential $mycreds -ArgumentList "icac ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

 

3 REPLIES 3

L7 Applicator

You aren't really doing any validation on whether the "Invoke-RestMethod" even worked. Check it's return code and return value.

L0 Member

Sorry, I did include "write-host $pass" and then copy $pass into a RDP window to login. so i can confirm the password is correct.

If the REST API call to the AAM CCP URL returns the target account's correct username and password, but the action of actually using the target account credentials fails.... then it is not a CyberArk issue.

 

If you try to interactively "run-as" powershell.exe with the serviceusers credentials, it will probably fail also. Sounds like a (logon) permissions issue on your Windows machine.

  • 777 Views
  • 3 replies
  • 0 Likes
Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!