How do you load the toolkit so it autocomplete in Visual Code?

I use mostly visual code for creating the install script but how do i load so the function in the toolkit so it autocomplete in the editor…

thanks

I wasn’t a big fan of Visual Code when I tried it out, but I do recall you need to load a Powershell extension in order to get it to autocomplete and do the color-coding. (File > Preferences > Extensions)

Instead of Visual Code, I’m using the Windows Powershell ISE with an addon called ISESteroids. You may want to give it a look. It’s pretty awesome.

ISESteroids is cool but it not free and…like vscode because there is a dark theme for it and alot of extensions.

got it to work by following these steps:

Configuring PSAppDeployToolkit for Intellisense in Visual Studio Code

  1. Install the PowerShell Extension for VS Code
  2. PowerShell - Visual Studio Marketplace
  3. Set the default language to PowerShell (optional)
  4. Under Settings (Ctrl+,) find Files: Default Language
  5. Set this to powershell
  6. Close Settings
  7. Download PSAppDeployToolkit
  8. Releases · PSAppDeployToolkit/PSAppDeployToolkit · GitHub
  9. Extract the contents to a folder
  10. Copy the Toolkit folder to a path of your choosing (such as these options)
  11. $Home\Documents\WindowsPowerShell\Modules
    1. $Env:ProgramFiles\WindowsPowerShell\Modules
  12. Mine is copied to: C:\Users\user\Documents\WindowsPowerShell\Modules\AppDeployToolkit
  13. Convert the script to a module
  14. In ISE: Open \Documents\WindowsPowerShell\Modules\AppDeployToolkit_AppDeployToolkitMain.ps1_
  15. File > Save As
    1. Change type to PowerShell Script Module
    2. Change name to: AppDeployToolkit.psm1
  16. Delete AppDeployToolkitMain.ps1, it is no longer needed
  17. Update the PSADT XML
  18. Edit AppDeployToolkitConfig.xml
  19. Edit Toolkit_RequireAdmin (line 17) from True to False
  20. Create a VS Code profile
  21. Launch VS Code and select the PowerShell Integrated Console terminal then type in notepad $profile
    1. If no profile exists, Notepad will ask to create the file, select Yes
  22. Add a line to import the module:
    1. Import-Module $Home\Documents\WindowsPowerShell\Modules\AppDeployToolkit
  23. I also add a line to clear the host, as I don’t want to see the import each time.
    1. Clear-Host
  24. Save Microsoft.VSCode_profile.ps1 and close Notepad
  25. Relaunch VS Code
  26. It will switch to the PowerShell extension, perform the import from the profile, then clear the host.
  27. You can confirm by running: get-help copy-file

Credit to Christian Nyhuus for documenting the steps for ISE

https://www.nyhu.us/powershell/psadt/intellisense-psadt-powershell-ise/ Reddit - Dive into anything

2 Likes

I prefer ISE as I have to move from computer to computer so no need to be install. Also, PSADTK is running with no need to special configuration as shown below.

Thanks for this detailed information, @long!

Based on your post, i edited my $profile-file with this:

$PSADTPath = "H:\Pack\Scripts\GDrive\CMDs\CodeSnippets\Silvermonkey Templates Test\Release\AppDeployToolkit"

If ( Test-Path -Path $PSADTPath ) {
  Copy-Item -Path $PSADTPath -Destination "$env:Temp" -Force -Recurse

  Push-Location "$env:Temp\$(Split-Path -Path $PSADTPath -Leaf)"
  $ToolKit = [XML](Get-Content .\AppDeployToolkitConfig.xml)
  $ToolKit.AppDeployToolkit_Config.Toolkit_Options.Toolkit_RequireAdmin = "False"
  $ToolKit.Save("$pwd\AppDeployToolkitConfig.xml")

  If ( Test-Path -Path .\AppDeployToolkitMain.ps1 ) {
    Move-Item -Path .\AppDeployToolkitMain.ps1 -Destination .\AppDeployToolkitMain.psm1 -Force
  }

  Import-Module .\AppDeployToolkitMain.psm1

  Pop-Location
} 

so it’ll load a fresh copy everytime, i start my favorite editor, or if using vscode: reload the window.

Thank you so much for guiding me in the right direction!

kind regards
BaBa

2 Likes

I have been trying to follow these steps to import into VisualStudio Code. I have the powershell extension installed but it is 7.0.3 Core.

I converted all the Get-WmiObject commands to Get-CimInstance but I still get an error when trying to import the module.

Line10708
Add-Type -Path $appDeployCustomTypesSourceCode -ReferencedAssembl …

C:\$Location\PowerShell\Modules\AppDeployToolkit\Toolkit\AppDeployToolkit\AppDeployToolkitMain.cs(9,23): error CS0234: The type or namespace name 'Principal' does not exist in the namespace 'System.Security' (are you missing an assembly reference?) using System.Security.Principal;      


Any ideas on how to fix this?

The toolkit isn’t compatible with PowerShellCore yet. Use PowerShell 5.1

Since PowerShell 5.1 is no longer actively supported, when will the toolkit be upgraded to support PowerShellCore?