Use a variable from within a variable after Compare-Object to use in Foreach-object loop


hi,

i have powershell script need compare 2 folders of siteusers , profiles use compare-object determine folders in siteusers , not profiles only. need use folder name data variable array use icacls script. ideas or please?

$siteusers = @(get-childitem "c:\siteusers\test\" | where{$_.psiscontainer})
$profiles = @(get-childitem "c:\siteusers\profiles\" | where{$_.psiscontainer})
$missingprofiles = compare-object -referenceobject $siteusers -differenceobject $profiles -property name | where{$_.sideindicator -eq "<="} | format-list name

foreach-object
#to work out how use $_.name variable $missingprofiles variable , input text below icacls commands

{
c:
cd \
md \siteusers\profiles\$2
icacls \siteusers\profiles\$2 /inheritance`:r
icacls \siteusers\profiles\$2 /grant 'system:(oi)(ci)(f)'
icacls \siteusers\profiles\$2 /grant 'domain\network admins:(oi)(ci)(f)'
icacls \siteusers\profiles\$2 /grant domain\$2`:`(oi`)`(ci`)`(f`)
icacls \siteusers\profiles\$2 /setowner domain\$2
md \siteusers\profiles\$2\profile
icacls \siteusers\profiles\$2\profile /setowner domain\$2
md \siteusers\profiles\$2\tsprofile
icacls \siteusers\profiles\$2\tsprofile /setowner domain\$2
}

the problem format-list name @ end.  try this:

$siteusers = get-childitem "c:\siteusers\test" | where{$_.psiscontainer} $profiles = get-childitem "c:\siteusers\profile" | where{$_.psiscontainer} $missingprofiles = compare-object -referenceobject $siteusers -differenceobject $profiles -property name | where{$_.sideindicator -eq "<="} $missingprofiles|foreach {   write-host $_.name   md "c:\siteusers\profiles\$($_.name)" }
small note: don't need @() tell it array/list.  get-childitem returns list , filters list.


write-host ((0..56)|%{if (($_+1)%3 -eq 0){[char][int]("116111101110117102102064103109097105108046099111109"[($_-2)..$_] -join "")}}) -separator ""


Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

some help on Event 540

WMI Repository 4GB limit - Win 2003 Ent Question

Event ID 1302 (error 1307) DFS replication service encountered an error while writing to the debug log file