Forum Discussion
pra4ash
Jun 03, 2020Copper Contributor
Variable not appearing in Function
Guys - newbie here, please bear with me. 1. I have a function that'll store user credential. It's in the profile file 2. profile loads, I initiate the function manually Get-MyUserCred 3. Loads suc...
Manfred101
Jun 03, 2020Iron Contributor
pra4ash This is because of Powershell scopes. You can read about scopes here: https://ss64.com/ps/syntax-scopes.html
In your case you have to use $global:Cred = Get-Credential to make the $Cred available outside your function!
Grtz, Manfred de Laat