将剪贴板中的文本导入Powershell中的提示

将剪贴板中的文本导入Powershell中的提示,powershell,clipboard,Powershell,Clipboard,我要做的是从一个已经打开的PS实例打开一个提升的PS实例,然后通过管道将命令从剪贴板传递到提示符,而不仅仅是窗口 1)2)。 将第一个与第二个相结合将得到所需的结果。 以下脚本将带有一行程序的字符串复制到剪贴板,从剪贴板接收一行程序,并将其传递给powershell.exe执行,后者以提升的权限启动。 警告:小心使用双引号 $re = '^\S+\s+\S+\s+S-1-5-32-544' "whoami.exe /groups | Select-String \""${re}\""" | cl

我要做的是从一个已经打开的PS实例打开一个提升的PS实例,然后通过管道将命令从剪贴板传递到提示符,而不仅仅是窗口

1)
2)。
将第一个与第二个相结合将得到所需的结果。
以下脚本将带有一行程序的字符串复制到剪贴板,从剪贴板接收一行程序,并将其传递给powershell.exe执行,后者以提升的权限启动。
警告:小心使用双引号

$re = '^\S+\s+\S+\s+S-1-5-32-544'
"whoami.exe /groups | Select-String \""${re}\""" | clip.exe
Add-Type -AssemblyName System.Windows.Forms
$dummy = New-Object System.Windows.Forms.TextBox
$dummy.Multiline = $true
$dummy.Paste()
$command = $dummy.Text
$args = '-NoLogo', '-NoProfile', '-NoExit', "-Command ${command}"
Start-Process -FilePath powershell.exe -Verb runas -ArgumentList $args
以下脚本演示了可以传递多行脚本块。
脚本将自动启动三次并停止

& ($b = {
Write-Host $b
$re = '^\S+\s+\S+\s+S-1-5-32-544'
whoami.exe /groups | Select-String $re
if( $b -match 'return\s\}###' ) { return }
'&($b = {' + ($b -replace 'return\s\}', '$0#') + '})' | clip.exe
Add-Type -AssemblyName System.Windows.Forms
$dummy = New-Object System.Windows.Forms.TextBox
$dummy.Multiline = $true
$dummy.Paste()
$command = $dummy.Text
$args = '-NoLogo', '-NoProfile', '-NoExit'
$args += '-Command {0}' -f $command
Start-Process -FilePath powershell.exe -Verb runas -ArgumentList $args
})
1) )
2)。
将第一个与第二个相结合将得到所需的结果。
以下脚本将带有一行程序的字符串复制到剪贴板,从剪贴板接收一行程序,并将其传递给powershell.exe执行,后者以提升的权限启动。
警告:小心使用双引号

$re = '^\S+\s+\S+\s+S-1-5-32-544'
"whoami.exe /groups | Select-String \""${re}\""" | clip.exe
Add-Type -AssemblyName System.Windows.Forms
$dummy = New-Object System.Windows.Forms.TextBox
$dummy.Multiline = $true
$dummy.Paste()
$command = $dummy.Text
$args = '-NoLogo', '-NoProfile', '-NoExit', "-Command ${command}"
Start-Process -FilePath powershell.exe -Verb runas -ArgumentList $args
以下脚本演示了可以传递多行脚本块。
脚本将自动启动三次并停止

& ($b = {
Write-Host $b
$re = '^\S+\s+\S+\s+S-1-5-32-544'
whoami.exe /groups | Select-String $re
if( $b -match 'return\s\}###' ) { return }
'&($b = {' + ($b -replace 'return\s\}', '$0#') + '})' | clip.exe
Add-Type -AssemblyName System.Windows.Forms
$dummy = New-Object System.Windows.Forms.TextBox
$dummy.Multiline = $true
$dummy.Paste()
$command = $dummy.Text
$args = '-NoLogo', '-NoProfile', '-NoExit'
$args += '-Command {0}' -f $command
Start-Process -FilePath powershell.exe -Verb runas -ArgumentList $args
})