# Run single line as Admin in script

**URL:** <https://forums.powershell.org/t/run-single-line-as-admin-in-script/14752>\
**Category:** PowerShell Help\
**Created:** [August 3, 2020, 10:55am UTC](https://forums.powershell.org/t/run-single-line-as-admin-in-script/14752 "2020-08-03T10:55:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![izshell](https://avatars.discourse-cdn.com/v4/letter/i/3bc359/32.png) [@izshell](https://forums.powershell.org/u/izshell)\
**Post date:** [August 3, 2020, 10:55am UTC](https://forums.powershell.org/t/run-single-line-as-admin-in-script/14752/1 "2020-08-03T10:55:44Z")

</div>

Hello!

Question two of the day! (Can you tell I’m facing a deadline?)

So I have a script that can run without elevation, however there is one line I need to run as an admin.

Is there a way I can do this without running the entire script (or Powershell ISE) as admin?

---

<div class="post-metadata">

**Author:** ![grokkit](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/grokkit/32/970_2.png) [@grokkit](https://forums.powershell.org/u/grokkit)\
**Post date:** [August 3, 2020, 11:42am UTC](https://forums.powershell.org/t/run-single-line-as-admin-in-script/14752/2 "2020-08-03T11:42:43Z")

</div>

Yes, you can use [Start-Process](https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Management/Start-Process?view=powershell-5.1#syntax) as described in [this StackOverflow discussion](https://stackoverflow.com/questions/7690994/running-a-command-as-administrator-using-powershell). Note that by default this uses the credentials of the user executing the script, so it won’t work for normal users. It either has to be executed by an administrator, or administrator credentials must be supplied with the `-Credential` parameter.

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [August 3, 2020, 11:46am UTC](https://forums.powershell.org/t/run-single-line-as-admin-in-script/14752/3 "2020-08-03T11:46:21Z")

</div>

you can’t run only a line as admin, but you can execute it in a new process with elevated privilege using -Verb parameter.

```
Start-Process PowerShell -ArgumentList "-C &{code requires elevation}" -Verb RunAs
```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:29pm UTC](https://forums.powershell.org/t/run-single-line-as-admin-in-script/14752/4 "2024-05-16T20:29:05Z")

</div>

Closed on May 16, 2024, 8:29pm UTC


