好的.我正在尝试完成一项学校作业,而且不能为我的生活弄清楚这一点.我正在尝试使用powershell将值从一个函数传递到另一个函数,从而形成一个"模块化"类型的脚本.我似乎无法弄清楚如何在不使用$ script:xxxxx的情况下将值移出函数范围.是否有另一种方法可以将powershell中的值作为常规参数参数传递?
这就是我所拥有的:
function main
{
inputGrams($carbGrams, $fatGrams)
$carbGrams
$carbGrams
calcGrams
displayInfo
}
function inputGrams([ref]$carbGrams, [ref]$fatGrams)
{
$carbGrams = read-host "Enter the grams of carbs per day"
$fatGrams = read-host "Enter the grams of fat per day"
}
function calcGrams
{
$carbCal = $carbGrams * 4
$fatCal = $fatGrams * 9
}
function displayInfo
{
write-host "The total amount of carb calories is $carbCal"
write-host "The total amount of fat calories is $fatCal"
}
main
Run Code Online (Sandbox Code Playgroud)
inputGrams函数之后的两个值应该在每次运行脚本时更改,但由于范围问题和传递值而不会更改.任何人都知道如何正确地将这些值传递回主函数?
有没有办法读取msi文件中的属性?
例如,给定一个msi文件名Testpackage.msi
我需要找到
productName
PackageCode
version
Run Code Online (Sandbox Code Playgroud)
我将使用它与WMI卸载
string objPath = string.Format("Win32_Product.IdentifyingNumber='{0}',Name='{1}',Version='{2}'", "{AC9C1263-2BA8-4863-BE18-01232375CE42}", "testproduct", "10.0.0.0");
Run Code Online (Sandbox Code Playgroud)
更新:使用Orca是一个很好的选择,如果这可以以编程方式实现,那么我可以使用它来生成自动发行说明.并且在卸载程序中也是如此.