简体   繁体   English

使用脚本打开另一个 powershell 实例,同时将 arguments 传递给新实例

[英]opening another instance of powershell with a script while passing the arguments to the new instance

So I have two scripts, Main_Script.ps1 and Loki.ps1.所以我有两个脚本,Main_Script.ps1 和 Loki.ps1。 I am trying to get the main script to call the Loki script in a new window while passing the variables from the main to the new window. So far I have gotten the script to open the second script and pass the variables but am unable to open a new instance.我试图让主脚本在新的 window 中调用 Loki 脚本,同时将变量从主脚本传递到新的 window。到目前为止,我已经获得了打开第二个脚本并传递变量的脚本,但无法打开一个新实例。 I have been through countless other posts to no avail.我浏览了无数其他帖子都无济于事。 Below is the code for main and Loki.下面是 main 和 Loki 的代码。 The Loki Scanner can be downloaded from https://github.com/Neo23x0/Loki . Loki 扫描器可以从https://github.com/Neo23x0/Loki下载。 The variables are Scan_Drive which is the drive I want to scan.变量是 Scan_Drive,这是我要扫描的驱动器。 Machine_id which is what I want to name the output. Output_dir the output directory.其中machine_id是我要命名的output。output_dir是output目录。 Resource_Drive the drive where I put Loki. Resource_Drive 我放置 Loki 的驱动器。 If there are any questions please let me know.如果有任何问题,请告诉我。 It functions now just not how I want and I do not know how to get there.它现在的功能不是我想要的,我不知道如何到达那里。 Assistance is greatly appreciated.非常感谢您的帮助。 I will adapt the answer to run other tools simultaneously.我将调整答案以同时运行其他工具。

Main_Script.ps1主脚本.ps1

[CmdletBinding()]
param(
    [Parameter(Mandatory=$true)][string] $Scan_drive,
    [Parameter(Mandatory=$true)][string] $Machine_id,
    [Parameter(Mandatory=$true)][string] $Output_dir,
    [Parameter(Mandatory=$true)][string] $Resource_drive
)

$Main_ScriptSplat = @{
"Resource_drive" = $Resource_drive
"Scan_drive" = $Scan_drive
"Machine_id" = $Machine_id
"wp_dir" = $Output_dir
}
   
mkdir ${Output_dir}:\${Machine_id}\

mkdir ${Output_dir}:\${Machine_id}\AV\

Write-Host "============================="
Write-Host "=         Loki           ="
Write-Host "============================="
Write-Host ""

& "$PSScriptRoot\Loki.ps1" @Main_ScriptSplat 

Loki.ps1洛基.ps1

param(
    $Scan_drive, $Machine_id, $Output_dir, $Resource_drive

)


$loki_folder = "${Resource_drive}:\loki"
$loki_bin = "${loki_folder}\loki.exe"


Write-Host "============================="
Write-Host "=         Loki           ="
Write-Host "============================="
Write-Host ""
& "${loki_bin}" -p ${Scan_drive}: --noprocscan --dontwait --intense -l 
"${Output_dir}:\${Machine_id}\AV\${Machine_id}.${Scan_drive}.loki.txt"  

You can call the PowerShell executable as a subprocess and hand in and out complex objects:您可以将PowerShell可执行文件作为子进程调用,并传入和传出复杂对象:

$verbs = Get-Verb
$verbs | Get-Member # [Microsoft.PowerShell.Commands.MemberDefinition]
$output = PowerShell -Command {
    Param(
        [Parameter(Mandatory)] $vs
    )
    $vs | Select -First 5 | Write-Output
} -Args @(,$verbs)
$output | Get-Member # [PSCustomObject]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将具有复杂参数的脚本块传递给新的 Powershell 实例 - Passing a Scriptblock with complex Arguments to a New Powershell Instance 将对象传递给新的 PowerShell 实例 - Passing objects to new PowerShell instance 新实例中的 PowerShell 启动脚本 - PowerShell launch script in new instance 在新的,干净的PowerShell实例中调用PowerShell脚本(从另一个脚本中) - Call a PowerShell script in a new, clean PowerShell instance (from within another script) 通过传递参数从另一个PowerShell脚本调用一个PowerShell脚本 - Invoke one PowerShell script from Another PowerShell script with passing arguments Foreach每个循环都使用参数启动一个新的Powershell实例吗? - Foreach launch a new powershell instance per loop with arguments? 在Powershell脚本中传递可选参数 - Passing optional arguments in Powershell script 将参数传递给从 powershell 5 调用的 powershell 7 脚本 - Passing arguments to powershell 7 script invoked form powershell 5 返回用户定义类的实例的 powershell 函数将导致构造函数返回一个新的另一个实例 - powershell function returning an instance of user defined class will cause returning a new another instance by constructor 在传递变量的同时将PowerShell脚本启动到新窗口中 - Launch PowerShell script into new window while passing variables
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM