[英]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.