In our daily work as administrator, we use a lot of functions and PowerShell scripts. At least friends, teammates and a lot in the community does.
Now GitHub is a place were a huge amount of code is being made available and I was wondering:
Why not have them imported on-the-fly?
Why would you import code?
Well, why not? Just kidding…
I mentioned this several times: I’m super lazy and as soon as I have repeatable tasks or procedures, I try to get things somehow automated and simplified. This was one of the main reasons, why I wrote my script for debugging calendar related issues Get-CalendarItems.ps1.
In our daily work as administrator, we often using several PowerShell modules and I’m sure a lot of admins have a collection of scripts and functions. In the last months, I tend to move forward and started customizing my PowerShell profile to have certain code available right away. One demand I had, was to import code from GitHub.
How to do it?
You can always copy code from your own or a forked repository and add it to your profile, local collection or current PowerShell.
This has some caveats:
- outdated code
- manual effort
- copy and paste….error prone
Therefore I wrote a function, which imports PowerShell code using the RAW link of the code. Scripts will be imported as functions, while functions as they are.
Here an example for each:
Import the script AnalyzeSendAsAuditData.ps1 from Tony’s repository
ImportFunction-FromGit -Url https://raw.githubusercontent.com/12Knocksinna/Office365itpros/master/AnalyzeSendAsAuditData.ps1 -Verbose
Import my helper functions. I’m using every day
ImportFunction-FromGit -Url https://raw.githubusercontent.com/IngoGege/Miscellaneous/master/ExchangePowerShell/HelperFunctions.ps1 -AlreadyFunction -Verbose
You can find the function on GitHub (of course!) here.
Conclusion
I hope this is useful for some of you. Feedback is always welcome!