New-Variable question

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.

Did you mean SCSM or SCCM?

If you’re wanting to store a variable that can be represented as a string, then you could use an environment variable, which you could read later

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 representation of your object(s).

Sorry, SCCM.

I want to pull the information towards the end of the odd build.

The variable is set in provisoning by powershell.

Are you by any chance using a task sequence? If so, then you can directly set and use task sequence variables. You can use the com object to read and write the task sequence variables.

You’ve not said yet though whether it’s the properties of an object that you want to store, or an individual string/number?

Hi Tim,

Yes am SCCM task sequence. It’s the object im after.