run block of PS1 as user and not admin

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

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 2 years and 11 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.
Locked
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

run block of PS1 as user and not admin

Post by localpct »

I'm trying to list the managed credentials (cmdkey) but I have to start the PS1 as admin

so just one block of code I need to run as user
  1. $targets = (cmdkey /list | Select-String -Pattern "target") -split "Target: "
  2. foreach($t in $targets){
  3.     #show me what is being deleted
  4.     $t
  5.     #Delete
  6.     & cmdkey.exe /delete:$t | out-null
  7. }  
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: run block of PS1 as user and not admin

Post by jvierra »

You can only run as admin or user but not both. A process can only run in one mode. To switch security contexts you must end the process and restart it in the other mode.
This topic is 2 years and 11 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.
Locked