是不是;“符文”;在Windows Powershell中,没有GUI就无法工作?

是不是;“符文”;在Windows Powershell中,没有GUI就无法工作?,powershell,Powershell,我正在使用AWS SSM连接到AWS中部署的Microsoft AD,但似乎从CLI管理任何东西都非常困难,因为默认的SSM登录用户是SSM user,因此我无法在域上运行任何命令并查看其输出 例如: PS C:\> runas /userd:administrator@id.wrksp.mydomain.com "cmd.exe /c net users /domain" Enter the password for administrator@id.wrksp.my

我正在使用AWS SSM连接到AWS中部署的Microsoft AD,但似乎从CLI管理任何东西都非常困难,因为默认的
SSM
登录用户是
SSM user
,因此我无法在域上运行任何命令并查看其输出

例如:

PS C:\> runas /userd:administrator@id.wrksp.mydomain.com "cmd.exe /c net users /domain"
Enter the password for administrator@id.wrksp.mydomain.com:
Attempting to start cmd.exe /c net users /domain as user "administrator@id.wrksp.mydomain.com" ...
PS C:\>
这不管用

通过RDP连接到服务器也不起作用,因为Micrsooft错误会导致黑屏问题,如下所示:

尝试在这里的建议,以及在编辑注册表设置等注册表更新,但没有运气。我的意思是这是一个全新的形象,所以我不明白为什么这仍然是一个问题


关于获得一个实际工作的GUI或者能够在powershell中运行这些命令,您有什么想法吗?

继续我的评论

您正在PowerShell中运行cmd.exe行

runas /userd:administrator@id.wrksp.mydomain.com "cmd.exe /c net users /domain"
。。。这并不意味着它是一个超级地狱。PowerShell为提升的/其他用户凭据提供了-RunAs开关/参数

如果您在PowerShell控制台主机中执行cmd.exe操作,则必须正确调用它。其中包括正确引用、字符串终止等

此外,如果您试图对远程主机执行此操作,则您所执行的操作是无效的。您必须正确启用PowerShell远程处理,建立远程会话,然后调用该会话

下面详细介绍了在Powershell中运行外部命令的方法:

•PowerShell:运行可执行文件

例如:

5. The Call Operator &

Why: Used to treat a string as a SINGLE command. Useful for dealing with spaces.

In PowerShell V2.0, if you are running 7z.exe (7-Zip.exe) or another command that starts with a number, you have to use the command invocation operator &.

The PowerShell V3.0 parser do it now smarter, in this case you don’t need the & anymore .

Details: Runs a command, script, or script block. The call operator, also known as the "invocation operator," lets you run commands that are stored in variables and represented by strings. Because the call operator does not parse the command, it cannot interpret command parameters

Example:

& 'C:\Program Files\Windows Media Player\wmplayer.exe' "c:\videos\my home video.avi" /fullscreen
Things can get tricky when an external command has a lot of parameters or there are spaces in the arguments or paths!

With spaces you have to nest Quotation marks and the result it is not always clear! 

In this case it is better to separate everything like so:

$CMD = 'SuperApp.exe'
$arg1 = 'filename1'
$arg2 = '-someswitch'
$arg3 = 'C:\documents and settings\user\desktop\some other file.txt'
$arg4 = '-yetanotherswitch'
 
& $CMD $arg1 $arg2 $arg3 $arg4
 
# or same like that:
 
$AllArgs = @('filename1', '-someswitch', 'C:\documents and settings\user\desktop\some other file.txt', '-yetanotherswitch')
 
& 'SuperApp.exe' $AllArgs


7. Start-Process  (start/saps)
Technet Jump

Why: Starts a process and returns the .Net process object Jump if -PassThru is provided. It also allows you to control the environment in which the process is started (user profile, output redirection etc). You can also use the Verb parameter (right click on a file, that list of actions) so that you can, for example, play a wav file.

Details: Executes a program returning the process object of the application. Allows you to control the action on a file (verb mentioned above) and control the environment in which the app is run. You also have the ability to wait on the process to end. You can also subscribe to the processes Exited event.

Example:

#starts a process, waits for it to finish and then checks the exit code.
$p = Start-Process ping -ArgumentList "invalidhost" -wait -NoNewWindow -PassThru
$p.HasExited
$p.ExitCode



#to find available Verbs use the following code.

$startExe = new-object System.Diagnostics.ProcessStartInfo -args PowerShell.exe

$startExe.verbs
或您的命令:

# Start Powershell with a differnet use credential - showing the current user as an example
Start-Process powershell -Credential -Credential "$env:USERNAME@$env:USERDNSDOMAIN" -ArgumentList "-NoExit","-Command  &{ cmd.exe /c net users /domain }" -PassThru -Wait
您还必须了解以下内容:

关于命令优先级

如果未指定路径,PowerShell将使用以下优先级 在对当前文件中加载的所有项目运行命令时进行排序 会议:

1-别名

2-功能

3-Cmdlet

4-外部可执行文件(程序和非PowerShell脚本)


我不完全清楚您想在这里做什么,因为我并不真正使用AWS,但是如果您想在远程服务器上的PowerShell中调用命令,那么我会查看或。如果您想在远程计算机上创建命令窗口,最简单的方法是使用PSTools中的
psexec
,从Microsoft下载。仅供参考:浏览器在无GUI(核心)服务器上不可用是正常的,这不是错误。您所发布的问题与编码问题无关,并且在我看来超出了范围。至于Windows Powershell中的“Runas”在没有GUI的情况下是否无法工作?,它用于您想要启动的任何类型的Powershell会话。您使用的命令不是Powershell,而是cmd.exe命令。这不是从PowerShell运行可执行文件的方法。为PowerShell运行可执行文件是一件经过充分讨论和记录的事情。为什么不使用AWS PowerShell模块,从而完全避免了对cmd.exe的需要?感谢您的帮助。我试过你的建议,但没有结果。命令刚刚挂起。我基本上是通过AWS SSM连接到一个Windows广告服务器,它将我置于一个powershell中。我正在尝试从powershell提示符运行“net/domain”命令,但使用的是域管理员帐户。如果您登录到Windows服务器,AWS直接将您放入powershell,则没有任何东西可以阻止您使用cmd.exe执行所需操作。只需在PS控制台主机中键入cmd即可切换到cmd.exe shell。完成后,只需键入exit。如果需要运行提升,那么也可以这样做。我遇到了与Powershell相同的问题,即检索命令的输出。它只是位于“尝试启动xyz命令…”处,就是这样。即使重定向输出,似乎也不会生成任何文件。我想这可能是另一个问题,但尽管如此,这里的回答还是非常有用!嗯。。这很奇怪。StdOut应该给你结果。我不再需要处理AWS实例,因此无法重新编写您正在尝试的内容。您是否尝试过先将PS提升到admin,然后启动cmd.exe,或者通过这种方式从PS提升到cmd.exe
start process-FilePath cmd.exe-Verb RunAs
,除非您已经以管理员身份登录,否则系统将提示您输入凭据。尽管有AWS,但是对于这个
“正在尝试启动xyz命令…”
,这通常表示资源找不到/无法访问,或者身份验证双跳问题等等。是的,我尝试在cmd中使用
运行方式提升,在PowerShell中也尝试了
动词运行方式,但两者的结果都是一样的“正在尝试启动xyz”错误,即使我只是让它运行
ipconfig>C:\results.txt
或其他文件夹。我可能需要在RDP GUI中进一步处理这个问题