Persistent Module Data

We’ve got some 200+ servers and climbing, all of which I’ve set up a few little scripts and tidbits in the profile for easy use but it’s now past the point it should all be in a module.

Part of the module is a variable that holds a path to a particular file. It could be in one of several locations and rarely may need to be set manually, so I need to store this path somewhere.

Problem is I can’t work out how to package this data with the module. I could save it in a data file in the module directory but as far as I’ve found I have to point to the full path to find it - meaning it would be useless if moved to another user account name.

EDIT I should note this is all on PowerShell v4

Save it in the Registry. Make a new structure for your “app module” under HKLM:\Software and use that to store your global settings.

Registry works for sure. If you want something portable, and accessible from a variety of locations, you might want a file (or database!).

Here’s a quick bit on some common data formats you could use - all depends on what you need out of it, .txt might be more than enough!

A common practice is to store this in some deterministic path under $ENV:APPDATA. Alternatively, you might have a configuration file that points to this file (this would allow you to specify another location, perhaps on a network share that multiple folks can access?)

Not sure if he posts on here, but Joel Bennett has done a bit of work with this.

Good luck!.