How do I run powershell scripts without admin righ

2020-05-19 00:17发布

If I try to change the execution policy, I get a message that says I can't modify the registry because I'm not an administrator.

It seems like this should be possible, since I can run batch files and other .exe and .com programs.

标签: powershell
5条回答
Summer. ? 凉城
2楼-- · 2020-05-19 00:42

You can try and set the policy of the process itself.

powershell.exe -ExecutionPolicy bypass

查看更多
劫难
3楼-- · 2020-05-19 00:42

The third technique I've found elsewhere on the internet is to use

powershell.exe -EncodedCommand XXXXXXX

where XXXXXXX is the result of

$code = {
     #powershell script goes here.
    }
}

[convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($code))

Ref: http://dmitrysotnikov.wordpress.com/2008/06/27/powershell-script-in-a-bat-file/

查看更多
够拽才男人
4楼-- · 2020-05-19 00:48

If your domain administrator hasn't forbidden it, you can do this:

Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser

This changes the default execution policy for PowerShell sessions run under the current user, rather than setting it for all users on the machine.

If you instead want to change the execution policy for just the current PowerShell session, you can use this command:

Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process

However, if your domain administrator is using the "Turn on Script Execution" group policy, you will not be able to change your execution policy at all. The group policy setting makes the Set-ExecutionPolicy cmdlet ineffective.

查看更多
一夜七次
5楼-- · 2020-05-19 00:51

how about

$script = Get-Content .\test.ps1
Invoke-Expression $script
查看更多
太酷不给撩
6楼-- · 2020-05-19 00:51

if you want to have an easy way to run a script myscript.ps1 from the windows shell then all you need is a bat Runmyscript.bat with the following contents:

type myscript.ps1 | powershell -

So simple it makes me wonder why you can't just run the ps1 in the first place, but there we go.

A generic version that prompts for userinput to type the name of the script would be:

set /p filename="Type name of script here: "
type %filename% | powershell -

I suppose if you wanted to, you could also write a generic vbscript script that opens any file in powershell using a dialogue box using this http://todayguesswhat.blogspot.co.uk/2012/08/windows-7-replacement-for.html

查看更多
登录 后发表回答