【发布时间】:2022-01-24 04:32:50
【问题描述】:
我正在编写一个 PowerShell 脚本,并且我还有另一个 PowerShell 脚本。 我知道,如果它存储在路径中,我们可以使用下面的代码
$scriptPath = "D:\Ashish\powershell\script.ps1"
$argumentList = "asdf fgh ghjk"
$output =Invoke-Expression "& `"$scriptPath`" $argumentList"
但我的 PowerShell 存储在对象而不是文件中。我正在使用下面的代码
$argumentList = "asdf fgh ghjk"
$logPath = "C:\AshishG\powershell\script21.txt"
$x = 'Write-Host "Hello script2" return "script2"' #This is my powershell script
//Write code here to call this script($x) with params and store the return value in the other object and also store the logs in $logpath
一种方法是将 PowerShell 存储到 script.ps1,但我认为,应该有某种方法可以从 PowerShell 对象本身调用它?
请分享您的建议。
【问题讨论】: