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.
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”.
Looking into the ps provider, I see a possible solution, and hope invades my boday again.
Especially when i read this line 😉
Using DIR (alias for Get-ChildItem) allows use to walk through the psprovider, and get the information of our specefic function.
That “definition” property must contain some crusty information..
And it Does ! Now we only need to pipe this information to a new text file and we are able to get it back.
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
Leave A Comment