New-Variable question

This topic contains 5 replies, has 3 voices, and was last updated by  Graham Beer 3 years, 3 months ago.

  • Author
  • #24240

    Graham Beer

    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.

  • #24241

    Dave Wyatt

    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.

  • #24256

    Tim Pringle

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

  • #24262

    Graham Beer

    Sorry, SCCM.

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

    The variable is set in provisoning by powershell.

  • #24269

    Tim Pringle

    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?

  • #24270

    Graham Beer

    Hi Tim,

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

You must be logged in to reply to this topic.