gci -recurse | where {$_.IsReadOnly -eq $TRUE} | $_.set_IsReadOnly
($FALSE)
I want to get every file which is marked as read only and clear the
flag. The first bit works on it's own:
gci -recurse
The second bit works:
gci -recurse | where {$_.IsReadOnly -eq $TRUE}
but as soon as I try to effect a change with the third bit:
gci | where {$_.IsReadOnly -eq $TRUE} | $_.set_IsReadOnly($FALSE)
I get an error like this:
Expressions are only permitted as the first element of a pipeline.
At line:1 char:65
+ gci | where {$_.IsReadOnly -eq $TRUE} | $_.set_IsReadOnly($FALSE)
<<<<
Is it just a syntax problem or am I misunderstanding pipelines
altogether: is it not possible to change objects at the end of a
pipeline?
ssg31415926 wrote:
> I'm always struggling with pipelines - in particular to do something
> to the object(s) I've got at the end of the pipeline. This is a
> typical example:
>
> gci -recurse | where {$_.IsReadOnly -eq $TRUE} | $_.set_IsReadOnly
> ($FALSE)
>
> I want to get every file which is marked as read only and clear the
> flag. The first bit works on it's own:
>
> gci -recurse
>
> The second bit works:
>
> gci -recurse | where {$_.IsReadOnly -eq $TRUE}
>
> but as soon as I try to effect a change with the third bit:
>
> gci | where {$_.IsReadOnly -eq $TRUE} | $_.set_IsReadOnly($FALSE)
Try this, I got it running on this way ...
$ReadOnlyFiles = gci -recurse | where {$_.IsReadOnly -eq $TRUE}
foreach ($file in $ReadOnlyFiles) {$file.set_IsReadOnly($FALSE)}
>
> I get an error like this:
>
> Expressions are only permitted as the first element of a pipeline.
> At line:1 char:65
> + gci | where {$_.IsReadOnly -eq $TRUE} | $_.set_IsReadOnly($FALSE)
> <<<<
>
> Is it just a syntax problem or am I misunderstanding pipelines
> altogether: is it not possible to change objects at the end of a
> pipeline?
I think you can use "$_" only one time, otherwise you have to use variables and loops like I did it. For further information about pipes this page "http://www.microsoft.com/technet/scriptcenter/topics/winpsh/manual/pipe.mspx" is helpful.
Regards from Munich,
Uwe
ssg31415926 wrote:
> I'm always struggling with pipelines - in particular to do something
> to the object(s) I've got at the end of the pipeline. This is a
> typical example:
>
> gci -recurse | where {$_.IsReadOnly -eq $TRUE} | $_.set_IsReadOnly
> ($FALSE)
>
> I want to get every file which is marked as read only and clear the
> flag. The first bit works on it's own:
>
> gci -recurse
>
> The second bit works:
>
> gci -recurse | where {$_.IsReadOnly -eq $TRUE}
>
> but as soon as I try to effect a change with the third bit:
>
> gci | where {$_.IsReadOnly -eq $TRUE} | $_.set_IsReadOnly($FALSE)
Just try this please ...
gci -recurse | where {$_.IsReadOnly -eq $TRUE} | Foreach-Object {$_.set_IsReadOnly($FALSE)}
>
> I get an error like this:
>
> Expressions are only permitted as the first element of a pipeline.
> At line:1 char:65
> + gci | where {$_.IsReadOnly -eq $TRUE} | $_.set_IsReadOnly($FALSE)
> <<<<
>
> Is it just a syntax problem or am I misunderstanding pipelines
> altogether: is it not possible to change objects at the end of a
> pipeline?
For further information about pipes the page "http://www.microsoft.com/technet/scriptcenter/topics/winpsh/manual/pipe.mspx" is helpful.
Regards from Munich,
Uwe
I managed to get this to work:
gci -recurse -force | where { $_.IsReadOnly -eq $TRUE } | foreach
{ $_.set_IsReadOnly($FALSE) }
Cheers
> For further information about pipes the page "http://www.microsoft.com/technet/scriptcenter/topics/winpsh/manual/pi..." is helpful.
>
> Regards from Munich,
> Uwe