Question

I wrote a powershell module in c# which allows me to call some webservices. Before I can use them, I have to specify where the service is located. For example:

Set-ServiceUrl 'http://myService.cloudapp.net/'
Create-Something ...
Get-Something ...

The test functions Create-Something and Get-Something accessing a static variable "serviceurl" which is set within the Set-ServiceUrl function.

This is similar to the Azure module where you have to call Set-AzureSubscription before you can query the services.

The diffrent between my and the Azure module is, that I have to specifiy the service url for my module for each time I start the powershell whereas I have to set the AzureSubscription only once.

Is there any mechanism in powershell to store such information "forever"? Or do I have to use a file-based / registry or environment-variable solution? What would you suggest?

Was it helpful?

Solution

PowerShell has no built-in method for persisting data across sessions; you must come up with a way to store & retrieve it yourself.

OTHER TIPS

One way would be to store it in a global variable and check it from other functions or even assign the value of the variable to the required parameter.

There's no "forever" mechanism, even the Azure team saves their information to disk.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top