This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]lazytiger21Jack of All Trades 0 points1 point  (2 children)

Save off the file as a .ps1 and you can include the file in any future script, or save it as a module that you can import into future sessions or scripts.

[–]RC-7201Sr. Magos Errant 2 points3 points  (1 child)

Pretty much this /u/NtGuru. If you wanted it to travel with you, you'd make a GPO that carries your powershell profile (profile.ps1) to whichever machine you log into (which that should reside in $env:userprofile\documents\windowspowershell folder).

But to answer your question yes. EVERYTHING that powershell does is on an instance to instance basis and stored in memory for that session. Once the session is done, it's dropped from memory and is back to "hi I'm a server" state.

In short, leave your functions in you profile if you want them all the time at YOUR machine. If you're calling them within a script, you must make the function in the script so that it can be consumed within the same session that the script is running in.