0
我已經注意到,模塊函數內的變量在執行返回到腳本後不會保留在範圍內。我遇到了Export-ModuleMember
,但這似乎沒有幫助,也許我用錯了。如何將變量從模塊傳遞迴腳本?
FunctionLibrary.psm1
Function AuthorizeAPI
{
# does a bunch of things to find $access_token
$access_token = "aerh137heuar7fhes732"
}
Write-Host $access_token
aerh137heuar7fhes732
Export-ModuleMember -Variable access_token -Function AuthorizeAPI
主要腳本
Import-Module FunctionLibrary
AuthorizeAPI # call to module function to get access_token
Write-Host $access_token
# nothing returns
我知道作爲一種替代我可以只點源分開腳本,這將讓我拿到的access_token,但我喜歡這個主意使用模塊並具有我所有的功能。這是可行的嗎?謝謝!
'$ =的access_token' - >'$腳本:ACCESS_TOKEN =' – PetSerAl
嗯,沒有工作。當執行返回到主腳本時,變量仍然爲空 – Quanda
變量爲空還是不存在? – PetSerAl