Did you ever erased a function from a file, but actually didnt mean to delete it. You still got you powershell prompt open ? No worries, your code is still there, and you wont need to rewrite it if you follow these few but very simple steps 😉

In my case, my function was called : “Get-SCCMFolder”

Since we are several persons working on the same module, something happens, and my function disapeared from the module.

But i could still use it in my PowerShell console.

Get-FunctionBack_02

Even if this function is quite small, rewriting it would have been doing twice the same job, and that is never really super funny (Especially for people who specialized in automation right ? ;))

So dont panic, and be sure NOT to close you powerShell console.

So i rembered that powerhsell had providers and especially that it had one called “functions”.

Get-FunctionBack_03

Looking into the ps provider, I see a possible solution, and hope invades my boday again.

Get-FunctionBack_04

Especially when i read this line 😉

Get-FunctionBack_05

Using DIR (alias for Get-ChildItem) allows use to walk through the psprovider, and get the information of our specefic function.

Get-FunctionBack_06

That “definition” property must contain some crusty information..

Get-FunctionBack_07

And it Does ! Now we only need to pipe this information to a new text file and we are able to get it back.

Get-FunctionBack_08

Et voila !! 🙂

We can simply copy and paste it back into our module (script) again 😀 (Do not forget to add the the Keyword “function” with the function name).

#Greetings from Switzerland 😀

#Stéphane