The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Alexandre (2) [Avatar] Offline
#1
Hello,
how to make a deepcopy for one variable ?

This code does not copy the fields Options and Attributes :
copy-item variable:Test Variable:Test2

Thanks.
soostibi (11) [Avatar] Offline
#2
Re: Variable.Attributes and deepCopy
Good point!
Even $test2 = $test does not work. Only the value is copied.

Anyway, what is Attributes, how can it be set?

The syntax of New-Variable:
New-Variable [-name] <string> [[-value] <Object>] [-scope <string>] [-descr
iption <string>] [-option {<None> | <ReadOnly> | <Constant> | <Private> | <
AllScope>}] [-force] [-passThru] [-whatIf] [-confirm] [<CommonParameters>]

And after creating a variable I get:
[58] PS C:>Get-Variable x| fl *


Name : x
Description : My variable
Value : 1
Options : Constant
Attributes : {}

There is no Set method for Attributes.
Alexandre (2) [Avatar] Offline
#3
Re: Variable.Attributes and deepCopy
For Attribute (US) :
http://www.manning.com/payette/wpia_errata.pdf

For Attribute (French)
ftp://ftp-developpez.com/laurent-dardenne/articles/Windows/PowerShell/VariablesContraintes/fichiers/Les-variables-contraintes-sous-PowerShell.pdf

"Deepcopy" :

gv V|Export-Clixml Variable-V.xml
$V2=Import-Clixml Variable-V.xml
$V2.name= "V2"
$v|gm
$V2|gm

Attention :
The type of V2 is PsVaraible and the type of V is Int32.