This guide is to create a PowerShell profile on your dev workstation in order to always import PSADT v4 module for IntelliSense and variable tab completion. This is not necessary to deploy applications with a complete PSADT template.
Locate your PowerShell profile directory (typically C:\Users\user\Documents\WindowsPowerShell). You can check this with the $profile variable in a PowerShell environment.
From PSAppDeployToolkit_Template_v4.zip, copy (and optionally modify) the non-signed Assets, Config, and Strings folders to WindowsPowerShell. At minimum, RequireAdmin must be set to $false in config.psd1.
Create folder Modules in WindowsPowerShell and copy the signed PSAppDeployToolkit module (PSAppDeployToolkit.zip).
Optionally, copy PSAppDeployToolkit.Extensions and any other custom extension folder(s) to WindowsPowerShell\Modules.
Create any of the following files in WindowsPowerShell for your applicable environment(s) if they do not exist:
The point of creating the profile like this was to also expose the ADTSession object for tab complete, while not requiring run as admin which is more secure. You have to have the config file to disable require admin to run Open-ADTSession non-elevated and also have the params mocked up to feed in like the template has. I also wanted my custom functions exposed for IntelliSense.
I think for most people, just having the module imported and the environment variables exported into their session state is enough. If there’s a dummy session present, PSAppDeployToolkit isn’t going to necessarily overwrite it when a new Open-ADTSession call is made as multiple active sessions are supported. The only time PSAppDeployToolkit will blow away an active session while calling Open-ADTSession is from the commmand line and not from a script.
Open session is to return all the object properties to the adtSession variable for tab completion. It’s not about having a dummy session available. I was looking to have a full environment available when scripting to avoid typos and having to constantly look up property names.
How about a function to return a dummy ADTSession object just for the purposes of tab completion instead of having to open a dummy session to build it, and doesn’t trip require admin?
Just do [PSADT.Module.DeploymentSession]::new() if you want a dummy session that bypasses the module’s controls and internal database.
Please note that because it’s not within the internal database, functions that require a session won’t work, and others may ask more questions. For instance, the dialog functions in the absence of a session will ask you for a Title and Subtitle whereas they usually do not.
Its a hashtable, your documentation calls it an object, doesn’t remove the fact that I am trying to instantiate one from the toolkit for tab complete use within an editor.
May want to check on that bit about bypassing controls.
$adtSession = [PSADT.Module.DeploymentSession]::new()
[2025-02-21 12:42:11.266] [Initialization] [<ScriptBlock>] [Error] :: Failure occurred while instantiating new deployment session: "[PSAppDeployToolkit] has a toolkit config option [RequireAdmin] set to [True] and the current user is not an Administrator, or PowerShell is not elevated. Please re-run the deployment script as an Administrator or change the option in the config file to not require Administrator rights.".
[2025-02-21 12:42:11.266] [Initialization] [<ScriptBlock>] [Error] :: [PSAppDeployToolkit_4.0.5_EN_01] install completed with exit code [60008].
[2025-02-21 12:42:11.315] [Initialization] [<ScriptBlock>] [Info] :: *******************************************************************************
Exception calling ".ctor" with "0" argument(s): "[PSAppDeployToolkit] has a toolkit config option [RequireAdmin] set
to [True] and the current user is not an Administrator, or PowerShell is not elevated. Please re-run the deployment
script as an Administrator or change the option in the config file to not require Administrator rights."
At line:1 char:1
+ $adtSession = [PSADT.Module.DeploymentSession]::new()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : UnauthorizedAccessException
…Because it’s an object? The hashtable is just to splat arguments onto Open-ADTSession. Why do you think the line to Open-ADTSession stores the PassThru output into $adtSession again?
Call Initialize-ADTModule -ScriptDirectory <scriptdir> first so your config that disables the admin requirement is loaded prior.
I’m confused by both sides… I don’t do any of this, but Intellisense works for me in VSCode?
Unless I’m missing something, all you need to do is import the PSAppDeployToolkit module?
Why would you try/catch everything, only to have an empty catch block. Assuming the first try block fails, the 2nd and 3rd ones won’t work properly.
Regarding the RequireAdmin stuff, you can just do (Get-ADTConfig).Toolkit.RequireAdmin = $false after running Import-Module.
Also, rather than calling Clear-Host, you could just add 6>&1 after the constructor call, that’ll cause no output to appear, or you could disable it via the config also. You should also consider whether logging should be enabled at all.
Thanks for the help, but would you happen to know how i can get this working for VS Code.. I followed all your steps and it working fine and populating everything for ISE but not working for VS Code.. When i try it i keep getting The Specific Module ‘PSAppDeployToolKit’ was not loaded because no valid module file was found in any module directory.