[英]PowerShell : How to run remote command prompt commands as admin from PowerShell?
[英]How to run specific commands/functions of Powershell from Command line?
我有一个PowerShell脚本,其中包含定义的命令列表。 我试图在运行时在Gitlab CI中创建一个构建步骤,执行特定的脚本。 为此,我首先要了解:如何从命令行运行Powershell的特定命令/功能?
我已经阅读了从C#的PowerShell脚本调用特定函数和从C#的 调用Powershell函数
答案是特定于C#的。 有什么办法可以从命令行执行此操作?
代码看起来像这样(myPowerScript.ps1)我的Powershell脚本中有多个功能。 就像这样:
function foo1{
Param($Parameter1,
$Parameter2)#
# Foo1 implementation
}
function foo2{
Param($Parameter1,
$Parameter2)#
# Foo2 implementation
}
function foo3{
Param($Parameter1,
$Parameter2)#
# Foo3 implementation
}
我想调用foo2:我该怎么做? 在这种情况下,PowerShell如何理解调用了哪个函数?
您的脚本“ stuff.ps1”:
Param($Parameter1,
$Parameter2)
function Do-Stuff
param($Parameter1,
$Parameter2)
#do stuff
}
Do-Stuff "Value1" "$Value2"
从命令行运行ps脚本:
powershell.exe -file "stuff.ps1" "ValueforParam1" "ValueForParam2"
这有效:
powershell -command "& { script1.ps; My-Func }"
例:
powershell -command "& { mypowerScript.ps; foo2 }"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.