Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Scope of objects in scripts

Reply
 
Old 02-18-2008   #1 (permalink)
Alastair French


 
 

Scope of objects in scripts

I am trying to modify a script
(http://www.terminal23.net/2007/04/po...rmissions.html) to
create an array of custom objects prior to the function call so that I can
store all the results an post process them.

I can successfully create the array and the collection of objects within the
function but the collection does not persist.

Can anyone explain what I am doing wrong? I have tried it with a normal
associative array and this persists OK. My code is below

$co = @()

function GetExplicits ($folders)
{
foreach ($i in $folders)
{
# get the access list for each folder
$acllist = get-acl $i.fullname
foreach ($x in $acllist.Access)
{
# check to see if inherited flag is set
If ($x.IsInherited -eq $false)
{
# output the data
$spacing = $true

# create new object
$ScriptermsObj = New-Object system.object

$permsObj | add-member -membertype noteproperty -name Identity -value
$($x.IdentityReference.Value)
$permsObj | add-member -membertype noteproperty -name Path -value
$($i.fullname)

$co += $permsObj
}
}

}
}


$folderslist = Get-Item -path $strpath
GetExplicits $folderslist

# get details for the child items - if they are containers
$folderslist = Get-ChildItem -path $strpath -recurse | where
{$_.psIscontainer -eq $true}
GetExplicits $folderslist




My System SpecsSystem Spec
Old 02-18-2008   #2 (permalink)
Marco Shaw [MVP]


 
 

Re: Scope of objects in scripts

> I can successfully create the array and the collection of objects within the
Quote:

> function but the collection does not persist.
>
> Can anyone explain what I am doing wrong? I have tried it with a normal
> associative array and this persists OK. My code is below
>
> $co = @()...

I've never thought of how the scope might come into play when dealing
with new-object... I have to think about that one...

As for fixing this, you don't need to create an array. So try this instead:

####Start####

$strpath="c:\demo"

#$co = @()

function GetExplicits ($folders)
{
foreach ($i in $folders)
{
# get the access list for each folder
$acllist = get-acl $i.fullname
foreach ($x in $acllist.Access)
{
# check to see if inherited flag is set
If ($x.IsInherited -eq $false)
{
# output the data
$spacing = $true #<--Not sure what
you're trying to do here

# create new object
$permsObj = New-Object system.object

$permsObj | `
add-member -membertype noteproperty -name Identity -value
$($x.IdentityReference.Value)
$permsObj | `
add-member -membertype noteproperty -name Path -value $($i.fullname)

#$co += $permsObj
}
}

}
}


$folderslist = Get-Item -path $strpath
GetExplicits $folderslist

# get details for the child items - if they are containers
$folderslist = Get-ChildItem -path $strpath -recurse | where
{$_.psIscontainer -eq $true}
GetExplicits $folderslist

$permsobj

####End####

My System SpecsSystem Spec
Old 02-18-2008   #3 (permalink)
Shay Levi


 
 

Re: Scope of objects in scripts


It doesn't work, on my box, when the "if" stament is enabled. Here's a modified
version


function GetExplicits ($folders){

foreach ($i in $folders){

$acllist = get-acl $i.fullname

foreach ($x in $acllist.Access){
#If (!$x.IsInherited){
$permsObj = New-Object system.object
$permsObj | add-member -membertype noteproperty Identity $x.IdentityReference.Value
$permsObj | add-member -membertype noteproperty Path $i.fullname
$permsObj
#}
}
}
}

$folderslist = Get-childItem c:\test1 -Recurse | where {$_.psiscontainer} |
$co = GetExplicits $folderslist
$co


## sample output:


Identity Path
-------- ----
BUILTIN\Administrators C:\test1\Copy of New Folder
NT AUTHORITY\SYSTEM C:\test1\Copy of New Folder
DOMAIN\ShayL C:\test1\Copy of New Folder
CREATOR OWNER C:\test1\Copy of New Folder
BUILTIN\Users C:\test1\Copy of New Folder
BUILTIN\Users C:\test1\Copy of New Folder
BUILTIN\Users C:\test1\Copy of New Folder
BUILTIN\Administrators C:\test1\New Folder
NT AUTHORITY\SYSTEM C:\test1\New Folder
DOMAIN\ShayL C:\test1\New Folder
CREATOR OWNER C:\test1\New Folder
BUILTIN\Users C:\test1\New Folder
BUILTIN\Users C:\test1\New Folder
BUILTIN\Users C:\test1\New Folder


P.S, Type 'help about_scope' to learn more on PowerShell's scoping rules.




-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> I am trying to modify a script
> (http://www.terminal23.net/2007/04/po...ermissions.htm
> l) to create an array of custom objects prior to the function call so
> that I can store all the results an post process them.
>
> I can successfully create the array and the collection of objects
> within the function but the collection does not persist.
>
> Can anyone explain what I am doing wrong? I have tried it with a
> normal associative array and this persists OK. My code is below
>
> $co = @()
>
> function GetExplicits ($folders)
> {
> foreach ($i in $folders)
> {
> # get the access list for each folder
> $acllist = get-acl $i.fullname
> foreach ($x in $acllist.Access)
> {
> # check to see if inherited flag is set
> If ($x.IsInherited -eq $false)
> {
> # output the data
> $spacing = $true
> # create new object
> $ScriptermsObj = New-Object system.object
> $permsObj | add-member -membertype noteproperty -name Identity
> -value
> $($x.IdentityReference.Value)
> $permsObj | add-member -membertype noteproperty -name Path -value
> $($i.fullname)
> $co += $permsObj
> }
> }
> }
> }
> $folderslist = Get-Item -path $strpath
> GetExplicits $folderslist
> # get details for the child items - if they are containers
> $folderslist = Get-ChildItem -path $strpath -recurse | where
> {$_.psIscontainer -eq $true}
> GetExplicits $folderslist

My System SpecsSystem Spec
Old 02-18-2008   #4 (permalink)
Shay Levi


 
 

Re: Scope of objects in scripts

When I say doesn't work , I mean that the "If" condition doesn't fire so
no objects are generated.

-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> It doesn't work, on my box, when the "if" stament is enabled. Here's a
> modified version
>
> function GetExplicits ($folders){
>
> foreach ($i in $folders){
>
> $acllist = get-acl $i.fullname
>
> foreach ($x in $acllist.Access){
> #If (!$x.IsInherited){
> $permsObj = New-Object system.object
> $permsObj | add-member -membertype noteproperty Identity
> $x.IdentityReference.Value
> $permsObj | add-member -membertype noteproperty Path $i.fullname
> $permsObj
> #}
> }
> }
> }
> $folderslist = Get-childItem c:\test1 -Recurse | where
> {$_.psiscontainer} |
> $co = GetExplicits $folderslist
> $co
> ## sample output:
>
> Identity Path
> -------- ----
> BUILTIN\Administrators C:\test1\Copy of New Folder
> NT AUTHORITY\SYSTEM C:\test1\Copy of New Folder
> DOMAIN\ShayL C:\test1\Copy of New Folder
> CREATOR OWNER C:\test1\Copy of New Folder
> BUILTIN\Users C:\test1\Copy of New Folder
> BUILTIN\Users C:\test1\Copy of New Folder
> BUILTIN\Users C:\test1\Copy of New Folder
> BUILTIN\Administrators C:\test1\New Folder
> NT AUTHORITY\SYSTEM C:\test1\New Folder
> DOMAIN\ShayL C:\test1\New Folder
> CREATOR OWNER C:\test1\New Folder
> BUILTIN\Users C:\test1\New Folder
> BUILTIN\Users C:\test1\New Folder
> BUILTIN\Users C:\test1\New Folder
>
> P.S, Type 'help about_scope' to learn more on PowerShell's scoping
> rules.
>
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
Quote:

>> I am trying to modify a script
>> (http://www.terminal23.net/2007/04/po...permissions.ht
>> m l) to create an array of custom objects prior to the function call
>> so that I can store all the results an post process them.
>>
>> I can successfully create the array and the collection of objects
>> within the function but the collection does not persist.
>>
>> Can anyone explain what I am doing wrong? I have tried it with a
>> normal associative array and this persists OK. My code is below
>>
>> $co = @()
>>
>> function GetExplicits ($folders)
>> {
>> foreach ($i in $folders)
>> {
>> # get the access list for each folder
>> $acllist = get-acl $i.fullname
>> foreach ($x in $acllist.Access)
>> {
>> # check to see if inherited flag is set
>> If ($x.IsInherited -eq $false)
>> {
>> # output the data
>> $spacing = $true
>> # create new object
>> $ScriptermsObj = New-Object system.object
>> $permsObj | add-member -membertype noteproperty -name Identity
>> -value
>> $($x.IdentityReference.Value)
>> $permsObj | add-member -membertype noteproperty -name Path -value
>> $($i.fullname)
>> $co += $permsObj
>> }
>> }
>> }
>> }
>> $folderslist = Get-Item -path $strpath
>> GetExplicits $folderslist
>> # get details for the child items - if they are containers
>> $folderslist = Get-ChildItem -path $strpath -recurse | where
>> {$_.psIscontainer -eq $true}
>> GetExplicits $folderslist

My System SpecsSystem Spec
Old 02-19-2008   #5 (permalink)
Alastair French


 
 

Re: Scope of objects in scripts

Marco

I tried that but had a few issues, it would not work with the backticks in
place before add-member. Taking those out caused the function to only store
the latest item processed it creates a new instance of the object each time.
Am I missing the point here somewhere? In addition the $permsObj is empty
outside of the function.

The code I posted would store all the permissions for each call of the
function but it would be empty on exit. The function is called twice to
handle the parent path and it's children. If I dumped the object output at
the end of the function I got what I wanted but in two sections. Does this
make sense. I can add examples if required.

Thanks

My System SpecsSystem Spec
Old 02-19-2008   #6 (permalink)
Alastair French


 
 

Re: Scope of objects in scripts

Shay

The reason for the 'if' is to remove any permissions that are inherited.
It's possible that your test folder inherited all the permissions of the
parent and hence no output.

Your modified example produces the output I need for the children (in an
object outside of the function) but I also need to include the parent path.
This is where the issue lies. How do I combine the output of the two calls to
the function

$folderslist = Get-Item -path $strpath
$co = GetExplicits $folderslist

$folderslist = Get-childItem -path $strpath -Recurse | where
{$_.psiscontainer}
$co = GetExplicits $folderslist
$co

using a += on the second call results in an error as there is no add
function on the object.

Thanks

Alastair

"Shay Levi" wrote:
Quote:

> When I say doesn't work , I mean that the "If" condition doesn't fire so
> no objects are generated.
>
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>
Quote:

> > It doesn't work, on my box, when the "if" stament is enabled. Here's a
> > modified version
> >
> > function GetExplicits ($folders){
> >
> > foreach ($i in $folders){
> >
> > $acllist = get-acl $i.fullname
> >
> > foreach ($x in $acllist.Access){
> > #If (!$x.IsInherited){
> > $permsObj = New-Object system.object
> > $permsObj | add-member -membertype noteproperty Identity
> > $x.IdentityReference.Value
> > $permsObj | add-member -membertype noteproperty Path $i.fullname
> > $permsObj
> > #}
> > }
> > }
> > }
> > $folderslist = Get-childItem c:\test1 -Recurse | where
> > {$_.psiscontainer} |
> > $co = GetExplicits $folderslist
> > $co
> > ## sample output:
> >
> > Identity Path
> > -------- ----
> > BUILTIN\Administrators C:\test1\Copy of New Folder
> > NT AUTHORITY\SYSTEM C:\test1\Copy of New Folder
> > DOMAIN\ShayL C:\test1\Copy of New Folder
> > CREATOR OWNER C:\test1\Copy of New Folder
> > BUILTIN\Users C:\test1\Copy of New Folder
> > BUILTIN\Users C:\test1\Copy of New Folder
> > BUILTIN\Users C:\test1\Copy of New Folder
> > BUILTIN\Administrators C:\test1\New Folder
> > NT AUTHORITY\SYSTEM C:\test1\New Folder
> > DOMAIN\ShayL C:\test1\New Folder
> > CREATOR OWNER C:\test1\New Folder
> > BUILTIN\Users C:\test1\New Folder
> > BUILTIN\Users C:\test1\New Folder
> > BUILTIN\Users C:\test1\New Folder
> >
> > P.S, Type 'help about_scope' to learn more on PowerShell's scoping
> > rules.
> >
> > -----
> > Shay Levi
> > $cript Fanatic
> > http://scriptolog.blogspot.com
Quote:

> >> I am trying to modify a script
> >> (http://www.terminal23.net/2007/04/po...permissions.ht
> >> m l) to create an array of custom objects prior to the function call
> >> so that I can store all the results an post process them.
> >>
> >> I can successfully create the array and the collection of objects
> >> within the function but the collection does not persist.
> >>
> >> Can anyone explain what I am doing wrong? I have tried it with a
> >> normal associative array and this persists OK. My code is below
> >>
> >> $co = @()
> >>
> >> function GetExplicits ($folders)
> >> {
> >> foreach ($i in $folders)
> >> {
> >> # get the access list for each folder
> >> $acllist = get-acl $i.fullname
> >> foreach ($x in $acllist.Access)
> >> {
> >> # check to see if inherited flag is set
> >> If ($x.IsInherited -eq $false)
> >> {
> >> # output the data
> >> $spacing = $true
> >> # create new object
> >> $ScriptermsObj = New-Object system.object
> >> $permsObj | add-member -membertype noteproperty -name Identity
> >> -value
> >> $($x.IdentityReference.Value)
> >> $permsObj | add-member -membertype noteproperty -name Path -value
> >> $($i.fullname)
> >> $co += $permsObj
> >> }
> >> }
> >> }
> >> }
> >> $folderslist = Get-Item -path $strpath
> >> GetExplicits $folderslist
> >> # get details for the child items - if they are containers
> >> $folderslist = Get-ChildItem -path $strpath -recurse | where
> >> {$_.psIscontainer -eq $true}
> >> GetExplicits $folderslist
>
>
>
My System SpecsSystem Spec
Old 02-19-2008   #7 (permalink)
Shay Levi


 
 

Re: Scope of objects in scripts

Try:

$folderslist = Get-Item -path $strpath
$co1 = GetExplicits $folderslist

$folderslist = Get-childItem -path $strpath -Recurse | where {$_.psiscontainer}

$co2 = GetExplicits $folderslist

$co = $co1+$co2
$co



-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> Shay
>
> The reason for the 'if' is to remove any permissions that are
> inherited. It's possible that your test folder inherited all the
> permissions of the parent and hence no output.
>
> Your modified example produces the output I need for the children (in
> an object outside of the function) but I also need to include the
> parent path. This is where the issue lies. How do I combine the output
> of the two calls to the function
>
> $folderslist = Get-Item -path $strpath $co = GetExplicits $folderslist
>
> $folderslist = Get-childItem -path $strpath -Recurse | where
> {$_.psiscontainer}
> $co = GetExplicits $folderslist
> $co
> using a += on the second call results in an error as there is no add
> function on the object.
>
> Thanks
>
> Alastair
>
> "Shay Levi" wrote:
>
Quote:

>> When I say doesn't work , I mean that the "If" condition doesn't fire
>> so no objects are generated.
>>
>> -----
>> Shay Levi
>> $cript Fanatic
>> http://scriptolog.blogspot.com
Quote:

>>> It doesn't work, on my box, when the "if" stament is enabled. Here's
>>> a modified version
>>>
>>> function GetExplicits ($folders){
>>>
>>> foreach ($i in $folders){
>>>
>>> $acllist = get-acl $i.fullname
>>>
>>> foreach ($x in $acllist.Access){
>>> #If (!$x.IsInherited){
>>> $permsObj = New-Object system.object
>>> $permsObj | add-member -membertype noteproperty Identity
>>> $x.IdentityReference.Value
>>> $permsObj | add-member -membertype noteproperty Path $i.fullname
>>> $permsObj
>>> #}
>>> }
>>> }
>>> }
>>> $folderslist = Get-childItem c:\test1 -Recurse | where
>>> {$_.psiscontainer} |
>>> $co = GetExplicits $folderslist
>>> $co
>>> ## sample output:
>>> Identity Path
>>> -------- ----
>>> BUILTIN\Administrators C:\test1\Copy of New Folder
>>> NT AUTHORITY\SYSTEM C:\test1\Copy of New Folder
>>> DOMAIN\ShayL C:\test1\Copy of New Folder
>>> CREATOR OWNER C:\test1\Copy of New Folder
>>> BUILTIN\Users C:\test1\Copy of New Folder
>>> BUILTIN\Users C:\test1\Copy of New Folder
>>> BUILTIN\Users C:\test1\Copy of New Folder
>>> BUILTIN\Administrators C:\test1\New Folder
>>> NT AUTHORITY\SYSTEM C:\test1\New Folder
>>> DOMAIN\ShayL C:\test1\New Folder
>>> CREATOR OWNER C:\test1\New Folder
>>> BUILTIN\Users C:\test1\New Folder
>>> BUILTIN\Users C:\test1\New Folder
>>> BUILTIN\Users C:\test1\New Folder
>>> P.S, Type 'help about_scope' to learn more on PowerShell's scoping
>>> rules.
>>>
>>> -----
>>> Shay Levi
>>> $cript Fanatic
>>> http://scriptolog.blogspot.com
>>>> I am trying to modify a script
>>>> (http://www.terminal23.net/2007/04/po...ng_permissions.
>>>> ht m l) to create an array of custom objects prior to the function
>>>> call so that I can store all the results an post process them.
>>>>
>>>> I can successfully create the array and the collection of objects
>>>> within the function but the collection does not persist.
>>>>
>>>> Can anyone explain what I am doing wrong? I have tried it with a
>>>> normal associative array and this persists OK. My code is below
>>>>
>>>> $co = @()
>>>>
>>>> function GetExplicits ($folders)
>>>> {
>>>> foreach ($i in $folders)
>>>> {
>>>> # get the access list for each folder
>>>> $acllist = get-acl $i.fullname
>>>> foreach ($x in $acllist.Access)
>>>> {
>>>> # check to see if inherited flag is set
>>>> If ($x.IsInherited -eq $false)
>>>> {
>>>> # output the data
>>>> $spacing = $true
>>>> # create new object
>>>> $ScriptermsObj = New-Object system.object
>>>> $permsObj | add-member -membertype noteproperty -name Identity
>>>> -value
>>>> $($x.IdentityReference.Value)
>>>> $permsObj | add-member -membertype noteproperty -name Path -value
>>>> $($i.fullname)
>>>> $co += $permsObj
>>>> }
>>>> }
>>>> }
>>>> }
>>>> $folderslist = Get-Item -path $strpath
>>>> GetExplicits $folderslist
>>>> # get details for the child items - if they are containers
>>>> $folderslist = Get-ChildItem -path $strpath -recurse | where
>>>> {$_.psIscontainer -eq $true}
>>>> GetExplicits $folderslist

My System SpecsSystem Spec
Old 02-19-2008   #8 (permalink)
Shay Levi


 
 

Re: Scope of objects in scripts

Also, take a look at this example. It updates $co with all *.ps1 and *.txt
files.

$co=@()

function updateScriptScopeObject($path,$ext){
dir $path $ext | foreach {
$permsObj = New-Object system.object
$permsObj | add-member -membertype noteproperty Name $_.name
$permsObj | add-member -membertype noteproperty Path $_.fullname
$script:co+=$permsObj
}
}



updateScriptScopeObject c:\scripts *.ps1
updateScriptScopeObject c:\scripts *.txt

$co





-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> Try:
>
> $folderslist = Get-Item -path $strpath $co1 = GetExplicits
> $folderslist
>
> $folderslist = Get-childItem -path $strpath -Recurse | where
> {$_.psiscontainer}
>
> $co2 = GetExplicits $folderslist
>
> $co = $co1+$co2
> $co
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
Quote:

>> Shay
>>
>> The reason for the 'if' is to remove any permissions that are
>> inherited. It's possible that your test folder inherited all the
>> permissions of the parent and hence no output.
>>
>> Your modified example produces the output I need for the children (in
>> an object outside of the function) but I also need to include the
>> parent path. This is where the issue lies. How do I combine the
>> output of the two calls to the function
>>
>> $folderslist = Get-Item -path $strpath $co = GetExplicits
>> $folderslist
>>
>> $folderslist = Get-childItem -path $strpath -Recurse | where
>> {$_.psiscontainer}
>> $co = GetExplicits $folderslist
>> $co
>> using a += on the second call results in an error as there is no add
>> function on the object.
>> Thanks
>>
>> Alastair
>>
>> "Shay Levi" wrote:
>>
Quote:

>>> When I say doesn't work , I mean that the "If" condition doesn't
>>> fire so no objects are generated.
>>>
>>> -----
>>> Shay Levi
>>> $cript Fanatic
>>> http://scriptolog.blogspot.com
>>>> It doesn't work, on my box, when the "if" stament is enabled.
>>>> Here's a modified version
>>>>
>>>> function GetExplicits ($folders){
>>>>
>>>> foreach ($i in $folders){
>>>>
>>>> $acllist = get-acl $i.fullname
>>>>
>>>> foreach ($x in $acllist.Access){
>>>> #If (!$x.IsInherited){
>>>> $permsObj = New-Object system.object
>>>> $permsObj | add-member -membertype noteproperty Identity
>>>> $x.IdentityReference.Value
>>>> $permsObj | add-member -membertype noteproperty Path $i.fullname
>>>> $permsObj
>>>> #}
>>>> }
>>>> }
>>>> }
>>>> $folderslist = Get-childItem c:\test1 -Recurse | where
>>>> {$_.psiscontainer} |
>>>> $co = GetExplicits $folderslist
>>>> $co
>>>> ## sample output:
>>>> Identity Path
>>>> -------- ----
>>>> BUILTIN\Administrators C:\test1\Copy of New Folder
>>>> NT AUTHORITY\SYSTEM C:\test1\Copy of New Folder
>>>> DOMAIN\ShayL C:\test1\Copy of New Folder
>>>> CREATOR OWNER C:\test1\Copy of New Folder
>>>> BUILTIN\Users C:\test1\Copy of New Folder
>>>> BUILTIN\Users C:\test1\Copy of New Folder
>>>> BUILTIN\Users C:\test1\Copy of New Folder
>>>> BUILTIN\Administrators C:\test1\New Folder
>>>> NT AUTHORITY\SYSTEM C:\test1\New Folder
>>>> DOMAIN\ShayL C:\test1\New Folder
>>>> CREATOR OWNER C:\test1\New Folder
>>>> BUILTIN\Users C:\test1\New Folder
>>>> BUILTIN\Users C:\test1\New Folder
>>>> BUILTIN\Users C:\test1\New Folder
>>>> P.S, Type 'help about_scope' to learn more on PowerShell's scoping
>>>> rules.
>>>> -----
>>>> Shay Levi
>>>> $cript Fanatic
>>>> http://scriptolog.blogspot.com
>>>>> I am trying to modify a script
>>>>> (http://www.terminal23.net/2007/04/po...ng_permissions
>>>>> . ht m l) to create an array of custom objects prior to the
>>>>> function call so that I can store all the results an post process
>>>>> them.
>>>>>
>>>>> I can successfully create the array and the collection of objects
>>>>> within the function but the collection does not persist.
>>>>>
>>>>> Can anyone explain what I am doing wrong? I have tried it with a
>>>>> normal associative array and this persists OK. My code is below
>>>>>
>>>>> $co = @()
>>>>>
>>>>> function GetExplicits ($folders)
>>>>> {
>>>>> foreach ($i in $folders)
>>>>> {
>>>>> # get the access list for each folder
>>>>> $acllist = get-acl $i.fullname
>>>>> foreach ($x in $acllist.Access)
>>>>> {
>>>>> # check to see if inherited flag is set
>>>>> If ($x.IsInherited -eq $false)
>>>>> {
>>>>> # output the data
>>>>> $spacing = $true
>>>>> # create new object
>>>>> $ScriptermsObj = New-Object system.object
>>>>> $permsObj | add-member -membertype noteproperty -name Identity
>>>>> -value
>>>>> $($x.IdentityReference.Value)
>>>>> $permsObj | add-member -membertype noteproperty -name Path -value
>>>>> $($i.fullname)
>>>>> $co += $permsObj
>>>>> }
>>>>> }
>>>>> }
>>>>> }
>>>>> $folderslist = Get-Item -path $strpath
>>>>> GetExplicits $folderslist
>>>>> # get details for the child items - if they are containers
>>>>> $folderslist = Get-ChildItem -path $strpath -recurse | where
>>>>> {$_.psIscontainer -eq $true}
>>>>> GetExplicits $folderslist

My System SpecsSystem Spec
Old 02-26-2008   #9 (permalink)
Alastair French


 
 

Re: Scope of objects in scripts



"Shay Levi" wrote:
Quote:

> Also, take a look at this example. It updates $co with all *.ps1 and *.txt
> files.
>
> $co=@()
>
> function updateScriptScopeObject($path,$ext){
> dir $path $ext | foreach {
> $permsObj = New-Object system.object
> $permsObj | add-member -membertype noteproperty Name $_.name
> $permsObj | add-member -membertype noteproperty Path $_.fullname
> $script:co+=$permsObj
> }
> }
>
>
>
> updateScriptScopeObject c:\scripts *.ps1
> updateScriptScopeObject c:\scripts *.txt
>
> $co
>
>
>
>
Thanks, that sorted me. It was the Script: scope modifier - I tried most
other combinations just not that one.

Thanks again

Alastair French
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
run .cmd scripts on remote machine (automating the MOSS install via scripts) PowerShell
Is this a bug in the scope? PowerShell
Variable scope PowerShell
Execute scripts in current scope? PowerShell
Using a function to setup objects properties with scope of script PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

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