如何在新的Powershell.exe控制台中加载函数
我有一个需要sta模式的函数(函数1)。我想从非sta模式poshconsole调用此函数。当我的个人资料中有function1时,此选项起作用如何在新的Powershell.exe控制台中加载函数,powershell,Powershell,我有一个需要sta模式的函数(函数1)。我想从非sta模式poshconsole调用此函数。当我的个人资料中有function1时,此选项起作用 $command = "function1 'MyArguments'" powershell -sta -command $command 但是,如果配置文件中没有函数1,并且我调用 powershell -sta -noprofile -command $command 我可以通过powershell.exe调用执行多个命令吗?或者我可以移交c
$command = "function1 'MyArguments'"
powershell -sta -command $command
但是,如果配置文件中没有函数1,并且我调用
powershell -sta -noprofile -command $command
我可以通过powershell.exe调用执行多个命令吗?或者我可以移交customprofilepath吗 您可以用分号(;)分隔多个命令,例如,点源包含函数的脚本,然后调用函数:
powershell -sta -noprofile -command ". c:\functions.ps1 ; function1 'MyArguments'"
有一些处理STA的方法:
function1“我的参数”
powershell -sta -noprofile -command '<pathToYourScript>.ps1; function1 args'
powershell-sta-noprofile-command'.ps1;函数1 args'
我试图同时使用-file
参数和-command
参数,但这不起作用。如果正在运行,则可以使用调用单元,例如:
PS> Invoke-Apartment -Apartment STA `
-Expr {[Threading.Thread]::CurrentThread.ApartmentState}
STA