Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import Chocolatey function, core and extension to PowerShell sessions?

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?

like image 862
Dilshad Abduwali Avatar asked Jun 23 '19 23:06

Dilshad Abduwali


2 Answers

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
like image 137
Lee_Dailey Avatar answered Nov 15 '22 05:11

Lee_Dailey


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.

like image 22
Gary Ewan Park Avatar answered Nov 15 '22 06:11

Gary Ewan Park