If i set a new-variable how long is it current for ? So for example if i do a new-variable during provisioning (During SSCM) will i be able to call on that variable at a later stage ? Its a com object that i want the value of later but can't call run the script later as the com object will not exist later.
I could create XML file i guess.
New-Variable follows the same scoping rules as any other variable assignment. By default, it's only active for as long as your current scope is active. (Until the end of a script if the statement is in the script scope, unless the caller dot-sources the script into the global scope, etc.)
PowerShell variables are never available past the end of the current session, so if you want something that works even if you restart PowerShell, you'd need to put it into a profile script, or something along those lines.
Or are you talking about actually wanting to export the object itself? The closest you could do to this would be to use Export-CliXML, but bear in mind that this makes an XML [u]representation[/u] of your object(s).