7

I find many Chocolatey helper functions:

C:\ProgramData\chocolatey\helpers\functions

and extension functions

C:\ProgramData\chocolatey\extensions\chocolatey-core

are very useful when you develop even non Chocolatey packages. Is there any way to import these function to Powershell scripts and Powershell Console sessions?

Dilshad Abduwali
  • 1,388
  • 7
  • 26
  • 47
  • i would start with the call that choco puts in your profile when you install it. that leads to a set of files that seem to load the extensions & funcs as needed. – Lee_Dailey Jun 23 '19 at 23:48
  • can you please point out the location that is in the user profile? I cannot find it. Thanks – Dilshad Abduwali Jun 24 '19 at 00:16
  • the powershell profiles are located here >>> `$profile | Select-Object -Property *` <<< the chocolatey stuff is located here >>> `Get-ChildItem -Path env:\choc*` <<< the choco PSM1 file that seems to start the process is here >>> `C:\ProgramData\chocolatey\lib\chocolatey\tools\chocolateyInstall\helpers\chocolateyProfile.psm1` << – Lee_Dailey Jun 24 '19 at 00:27
  • Yes, `Import-Module $ChocolateyProfile` did the trick. Can you please add this to question as an answer. So that this question can be closed and other people with same enquiry can benefit when they do their search? Thanks – Dilshad Abduwali Jun 24 '19 at 00:37
  • done! ... and you are most welcome! glad to have helped ... [*grin*] – Lee_Dailey Jun 24 '19 at 00:49

4 Answers4

9

when you install chocolatey, it puts a few lines of code in your powershell profile that load the various extensions & functions. [grin] you can find the various profiles here ...

$Profile |
    Select-Object -Property *

you can find the choco files here ...

Get-ChildItem -Path env:\choc*

for me, the loader is here ...

C:\ProgramData\chocolatey\lib\chocolatey\tools\chocolateyInstall\helpers\chocolateyProfile.psm1

the code in my profile that loads it is ...

Import-Module $ChocolateyProfile
Lee_Dailey
  • 7,292
  • 2
  • 22
  • 26
  • https://stackoverflow.com/a/62533743/497403 did it for me - importing C:\ProgramData\chocolatey\helpers\chocolateyInstaller.psm1 instead of chocolateyProfile.psm1 – David Airapetyan Mar 03 '23 at 15:38
4

There is a Chocolatey Package that seeks to help with this sort of thing as well. You can find it here:

https://chocolatey.org/packages/chocolateypowershell

Once installed, you can simply double click the icon that is placed on your desktop, and you will have a PowerShell Session that already has the Chocolatey pieces loaded into the session.

This approach can be useful if you only want those pieces loaded at certain times, and not always.

Gary Ewan Park
  • 17,610
  • 5
  • 42
  • 60
0

To gain access to the choco APIs directly from an existing PowerShell terminal session, execute this command:

C:\ProgramData\chocolatey\lib\chocolateypowershell\tools\chocolateyEnvironment.ps1

This is important for me because I debug scripts using PowerShell ISE but it would also work in the Visual Studio Code Terminal.

user8128167
  • 6,929
  • 6
  • 66
  • 79
0

in my case I have used Import-Module C:\ProgramData\chocolatey\helpers\chocolateyInstaller.psm1

msaadoun
  • 21
  • 3