-PipelineVariable isnt working correctly

Pipeline variable keeps the reference, The newly added member is also present in the pipeline variable which is represented in New column

[PSCustomObject]@{Column1=1;Column2=2} | Select-Object -Property * -PipelineVariable rr | Foreach-Object -Process {$_.Column1=5;$_|Add-Member -MemberType NoteProperty -Name Column3 -Value 6;$_} | Select-Object -Property *,@{E={$rr};L='New'}

Column1 Column2 Column3 New
------- ------- ------- ---
      5       2       6 @{Column1=5; Column2=2; Column3=6}

[quote quote=121542]Pipeline variable keeps the reference, The newly added member is present in the pipeline variable which is represented in New column

<textarea class="ace_text-input" style="opacity: 0; height: 18px; width: 7.20125px; left: 45px; top: 0px;" spellcheck="false" wrap="off"></textarea>
1
2
[PSCustomObject]@{Column1=1;Column2=2} | Select-Object -Property * -PipelineVariable rr | Foreach-Object -Process {$_.Column1=5;$_|Add-Member -MemberType NoteProperty -Name Column3 -Value 6;$_} | Select-Object -Property *,@{E={$rr};L='New'}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[/quote] So in other words, its useless for my use case

Hmm, I guess that’s true of all properties.

$a = [pscustomobject]@{message='hi'}
$b = $a
$a.message = 'there'
$b.message

there

Update from my last post back using your approach a bit differently. “correction pasted the wrong one”

$SSAS_services = @"
Server,Service,Startup Type,Task
$env:COMPUTERNAME,AxInstSV,Manual,stopped
"@  > 'D:\scripts\SSAS_services1.csv'

Import-CSV 'D:\Scripts\SSAS_services1.csv' |
ForEach-Object{
    $svc = Get-Service $_.Service -ComputerName $_.Server | Select MachineName, Name, StartType, Status
    Set-Service -ComputerName $_.Server -Service $_.Service -Status $_.Task -StartupType $_.'Startup Type' -PassThru | 
    Select MachineName, Name, StartType, Status,@{n='OldStartUp';e={$svc.StartType}},@{n='OldStatus';e={$svc.Status}}
} 



MachineName : LC01
Name        : AxInstSV
StartType   : Manual
Status      : Stopped
OldStartUp  : Manual
OldStatus   : Stopped




$SSAS_services = @"
Server,Service,Startup Type,Task
$env:COMPUTERNAME,AxInstSV,Disabled,stopped
"@  > 'D:\scripts\SSAS_services1.csv'

Import-CSV 'D:\Scripts\SSAS_services1.csv' |
ForEach-Object{
    $svc = Get-Service $_.Service -ComputerName $_.Server | Select MachineName, Name, StartType, Status
    Set-Service -ComputerName $_.Server -Service $_.Service -Status $_.Task -StartupType $_.'Startup Type' -PassThru | 
    Select MachineName, Name, StartType, Status,@{n='OldStartUp';e={$svc.StartType}},@{n='OldStatus';e={$svc.Status}}
} 




MachineName : LC01
Name        : AxInstSV
StartType   : Disabled
Status      : Stopped
OldStartUp  : Manual
OldStatus   : Stopped




$SSAS_services = @"
Server,Service,Startup Type,Task
$env:COMPUTERNAME,AxInstSV,Manual,stopped
"@  > 'D:\scripts\SSAS_services1.csv'

Import-CSV 'D:\Scripts\SSAS_services1.csv' |
ForEach-Object{
    $svc = Get-Service $_.Service -ComputerName $_.Server | Select MachineName, Name, StartType, Status
    Set-Service -ComputerName $_.Server -Service $_.Service -Status $_.Task -StartupType $_.'Startup Type' -PassThru | 
    Select MachineName, Name, StartType, Status,@{n='OldStartUp';e={$svc.StartType}},@{n='OldStatus';e={$svc.Status}}
} 



MachineName : LC01
Name        : AxInstSV
StartType   : Manual
Status      : Stopped
OldStartUp  : Disabled
OldStatus   : Stopped

[quote quote=121719]Update from my last post back using your approach a bit differently.

PowerShell
57 lines
<textarea class="ace_text-input" style="opacity: 0; height: 18px; width: 7.20125px; left: 52px; top: 0px;" spellcheck="false" wrap="off"></textarea>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
$SSAS_services = @"
Server,Service,Startup Type,Task
$env:COMPUTERNAME,AxInstSV,Manual,stopped
"@ > 'D:\scripts\SSAS_services1.csv'
Import-CSV 'D:\Scripts\SSAS_services1.csv' |
ForEach-Object{
Get-Service $_.Service -ComputerName $_.Server -PipelineVariable svc
Set-Service -ComputerName $_.Server -Service $_.Service -Status $_.Task -StartupType $_.'Startup Type' -PassThru
} | Select-Object -Property MachineName, Name, StartType, Status,
@{n='OldStartType';e={$_.StartType}}, @{n='OldStatus';e={$_.Status}}
MachineName : LP70
Name : AxInstSV
StartType : Manual
Status : Stopped
OldStartType : Manual
OldStatus : Stopped
MachineName : LP70
Name : AxInstSV
StartType : Manual
Status : Stopped
OldStartType : Manual
OldStatus : Stopped
$SSAS_services = @"
Server,Service,Startup Type,Task
$env:COMPUTERNAME,AxInstSV,Disable,stopped
"@ > 'D:\scripts\SSAS_services1.csv'
Import-CSV 'D:\Scripts\SSAS_services1.csv' |
ForEach-Object{
Get-Service $_.Service -ComputerName $_.Server -PipelineVariable svc
Set-Service -ComputerName $_.Server -Service $_.Service -Status $_.Task -StartupType $_.'Startup Type' -PassThru
} | Select-Object -Property MachineName, Name, StartType, Status,
@{n='OldStartType';e={$_.StartType}}, @{n='OldStatus';e={$_.Status}}
MachineName : LabPC01
Name : AxInstSV
StartType : Manual
Status : Stopped
OldStartType : Manual
OldStatus : Stopped
MachineName : LabPC01
Name : AxInstSV
StartType : Disabled
Status : Stopped
OldStartType : Disabled
OldStatus : Stopped
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[/quote] Not sure if it's a response to JS, but if for me, the results are wrong here, unless the system was already the same states as in the csv file.

A way to copy the values of an object (clone) (Powershell: Everything you wanted to know about PSCustomObject). Why does psobject have to be hidden?

$a = [pscustomobject]@{message='hi'}
$a.message
hi

$b = $a.psobject.copy()
$b.message
hi

$a.message = 'there'
$a.message
there

$b.message
hi