This topic contains 5 replies, has 3 voices, and was last updated by
April 14, 2015 at 4:02 am #24240
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.
April 14, 2015 at 4:06 am #24241MemberPoints: 0Rank: Member
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.
April 14, 2015 at 6:20 am #24256ParticipantPoints: 0Rank: Member
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).
April 14, 2015 at 6:54 am #24262
I want to pull the information towards the end of the odd build.
The variable is set in provisoning by powershell.
April 14, 2015 at 9:12 am #24269ParticipantPoints: 0Rank: Member
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?
April 14, 2015 at 9:49 am #24270
Yes am SCCM task sequence. It's the object im after.
The topic ‘New-Variable question’ is closed to new replies.