But the answers that are given does somehow not working for me
I have tried to run this let say in ISE:
I run the whole script which says it need to be an admin which I think is fine, and I thought the script is loaded
then i run this:
$adtSession = Open-ADTSession -SessionState $ExecutionContext.SessionState -PassThru
it says again I need to be an admin, ok I re-open it as admin:
$adtSession = Open-ADTSession -SessionState $ExecutionContext.SessionState -PassThru
Open-ADTSession : The term 'Open-ADTSession' is not recognized as the name of a cmdlet, function, script file,
or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:15
+ $adtSession = Open-ADTSession -SessionState $ExecutionContext.Session ...
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Open-ADTSession:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : CommandNotFoundException
PSADT v4’s front script (Invoke-AppDeployToolkit.ps1) does not run linear like PSADT v3.
It’s chopped up into functions and then calls those functions near the end of the script.
In your case, you tried to use Open-ADTSession before the PSADT module was imported.
So PowerShell doesn’t know what Open-ADTSession is and gave you that error.
To see what’s in $adtSession you will need to do that AFTER the session is open.
In the Install-ADTDeployment Function, you can add $adtSession on a blank line and it will show what’s inside $adtSession in the PowerShell console.
Thank you for your reply and explanations!
When i run that lines, I see the variables are not populated still.
So, what is going wrong here, why I still cannot access variables and test the function? I appreciate your response!
DirFiles/DirSupportFiles will only be populated from the command line if you open a session from a directory that contains those folders. Right now in your current context, there probably is no such folders, therefore the values are null.
Also, no need for Export-ADTEnvironmentTableToSessionState -SessionState $ExecutionContext.SessionState after opening a new DeploymentSession. Open-ADTSession will handle this for you.