如何使用 ascii 在 powershell 中运行 base64 代码? [英] How to run base64 code in powershell with ascii?

查看:69
本文介绍了如何使用 ascii 在 powershell 中运行 base64 代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过 Base64 编码的 字符串 在 Powershell 中运行命令 mkdir C:Temp555.

I would like to run command mkdir C:Temp555 in Powershell via a Base64-encoded string.

这段代码应该可以工作

$4 = "bWtkaXIgQzpcVGVtcFw1NTU="

$code = [Text.Encoding]::Utf8.GetString([Convert]::FromBase64String($4))

powershell $code

但是如果我将 $code 转换为 ASCII,我该如何运行它,因为这个不起作用:

but if i convert $code to ASCII, how can I run it like that, because this one won't work:

$4 = "bWtkaXIgQzpcVGVtcFw1NTU="

$code = [char]091+[char]084+[char]101+[char]120+[char]116+[char]046+[char]069+[char]110+[char]099+[char]111+[char]100+[char]105+[char]110+[char]103+[char]093+[char]058+[char]058+[char]085+[char]116+[char]102+[char]056+[char]046+[char]071+[char]101+[char]116+[char]083+[char]116+[char]114+[char]105+[char]110+[char]103+[char]040+[char]091+[char]067+[char]111+[char]110+[char]118+[char]101+[char]114+[char]116+[char]093+[char]058+[char]058+[char]070+[char]114+[char]111+[char]109+[char]066+[char]097+[char]115+[char]101+[char]054+[char]052+[char]083+[char]116+[char]114+[char]105+[char]110+[char]103+[char]040+[char]036+[char]052+[char]041+[char]041

powershell $code

因为最后一个代码不起作用,而第一个代码起作用,请帮忙?

because the last code doesn't work while the first one does, any help please?

推荐答案

可以通过CommandInvocationIntrinsics类方法InvokeScript将字符串作为脚本执行.

A string can be executed as a script through the CommandInvocationIntrinsics class method InvokeScript.

powershell $executioncontext.InvokeCommand.InvokeScript($code)

请参阅 InvokeScript 方法了解更多信息.

See InvokeScript Method for more information.

这篇关于如何使用 ascii 在 powershell 中运行 base64 代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆