![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Help looping a script I've got a script that lists all the Owners of a SharePoint site. I need to loop it so that it gathers this information for all the sites in an array. This is what I have so far: $mysites = Import-CliXml sites.xml $sitepath="https://mysharepointsite.com" [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") $site=new-object Microsoft.SharePoint.SPSite($sitepath) $web=$site.Rootweb $web.site.url $groups = $web.groups | ? {$_.Name -match "^.*Owners" } foreach($group in $groups) { Write-Output "+ $($group.Name)" foreach($user in $group.users){Write-Output " - $user"} } the "$mysites = import-CliXml sites.xml" contains all the sites that I need to run the remainder of the script against, formatted as so: - <Props> <S N="Url">https://mysharepointsite1.com</S> <S N="Owner">Domain\UserID</S> <S N="ContentDatabase">ContentDBName</S> <S N="StorageUsedMB">1.9</S> <S N="StorageWarningMB">1843</S> <S N="StorageMaxMB">2048</S> </Props> </Obj> - <Obj RefId="RefId-0"> <TNRef RefId="RefId-0" /> The Url has for each site has to excerpted in $sitepath and the remainder of the script run against it, and then looped and run against the next Url in the xml file. Any suggestions would be greatly appreciated. Roland |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Help looping a script On Feb 20, 4:54*pm, "Roland Serman" <roland.ser...@xxxxxx> wrote: Quote: > I've got a script that lists all the Owners of a SharePoint site. *I need to > loop it so that it gathers this information for all the sites in an array. > > This is what I have so far: > > $mysites = Import-CliXml sites.xml > > $sitepath="https://mysharepointsite.com" > [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $site=new-object Microsoft.SharePoint.SPSite($sitepath) > $web=$site.Rootweb > $web.site.url > $groups = $web.groups | ? {$_.Name -match "^.*Owners" } > foreach($group in $groups) > { > * *Write-Output "+ $($group.Name)" > * *foreach($user in $group.users){Write-Output " * - $user"} > > } > > the "$mysites = import-CliXml sites.xml" contains all the sites that I need > to run the remainder of the script against, formatted as so: > > - <Props> > * <S N="Url">https://mysharepointsite1.com</S> > * <S N="Owner">Domain\UserID</S> > * <S N="ContentDatabase">ContentDBName</S> > * <S N="StorageUsedMB">1.9</S> > * <S N="StorageWarningMB">1843</S> > * <S N="StorageMaxMB">2048</S> > * </Props> > * </Obj> > - <Obj RefId="RefId-0"> > * <TNRef RefId="RefId-0" /> > > The Url has for each site has to excerpted in $sitepath and the remainder of > the script run against it, and then looped and run against the next Url in > the xml file. > > Any suggestions would be greatly appreciated. > > Roland You'd be better off using STSADM in conjunction with PowerShell - this is quite easy since STSADM returns XML strings for a lot of its operations: PS> $xml = [xml](stsadm -o enumsites -url http://localhost) PS> $xml.sites.site | select Url, Owner | ft -auto Url Owner --- ----- http://localhost Domain\user1 http://localhost/MySite NT AUTHORITY\network service etc.. etc.. You can redirect this to a file by doing: PS> $xml.sites.site | select Url, Owner | out-file owners.txt Hope this helps, - Oisin |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Help looping a script The problem is I don't need the Site Collection Owners. I'm trying to get the users listed in the "<Site Name> Owners" group, which as far as I can tell is unattainable via stsadm, which is why I've gone the long route and come up with what I have so far. Ultimately what I need to do, is generate a list of all users listed as Site Owners (not site collection owners) for all Site Collections, across multiple Web Applications, and have it output into an xml file. So far from what I can tell there is no method of pulling all of this data via stsadm. I can pull all site collections from a specific Web App via stsadm, which is how I generate the sites.xml so for now I have to manually update the script every time I add a new Web Application, I haven't found a way to generate a list of all Web Apps and their Site Collections. Roland "Oisin (x0n) Grehan [MVP]" <oising@xxxxxx> wrote in message news:b8dc5b45-b719-4ed9-a36c-27a018cc883d@xxxxxx Quote: > On Feb 20, 4:54 pm, "Roland Serman" <roland.ser...@xxxxxx> > wrote: Quote: >> I've got a script that lists all the Owners of a SharePoint site. I need >> to >> loop it so that it gathers this information for all the sites in an >> array. >> >> This is what I have so far: >> >> $mysites = Import-CliXml sites.xml >> >> $sitepath="https://mysharepointsite.com" >> [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") >> $site=new-object Microsoft.SharePoint.SPSite($sitepath) >> $web=$site.Rootweb >> $web.site.url >> $groups = $web.groups | ? {$_.Name -match "^.*Owners" } >> foreach($group in $groups) >> { >> Write-Output "+ $($group.Name)" >> foreach($user in $group.users){Write-Output " - $user"} >> >> } >> >> the "$mysites = import-CliXml sites.xml" contains all the sites that I >> need >> to run the remainder of the script against, formatted as so: >> >> - <Props> >> <S N="Url">https://mysharepointsite1.com</S> >> <S N="Owner">Domain\UserID</S> >> <S N="ContentDatabase">ContentDBName</S> >> <S N="StorageUsedMB">1.9</S> >> <S N="StorageWarningMB">1843</S> >> <S N="StorageMaxMB">2048</S> >> </Props> >> </Obj> >> - <Obj RefId="RefId-0"> >> <TNRef RefId="RefId-0" /> >> >> The Url has for each site has to excerpted in $sitepath and the remainder >> of >> the script run against it, and then looped and run against the next Url >> in >> the xml file. >> >> Any suggestions would be greatly appreciated. >> >> Roland > Hi Roland, > > You'd be better off using STSADM in conjunction with PowerShell - this > is quite easy since STSADM returns XML strings for a lot of its > operations: > > PS> $xml = [xml](stsadm -o enumsites -url http://localhost) > PS> $xml.sites.site | select Url, Owner | ft -auto > > Url Owner > --- ----- > http://localhost Domain\user1 > http://localhost/MySite NT AUTHORITY\network service > > etc.. etc.. > > You can redirect this to a file by doing: > > PS> $xml.sites.site | select Url, Owner | out-file owners.txt > > Hope this helps, > > - Oisin |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Help looping a script On Feb 21, 10:08*am, "Roland Serman" <roland.ser...@xxxxxx> wrote: Quote: > The problem is I don't need the Site Collection Owners. *I'm trying to get > the users listed in the "<Site Name> Owners" group, which as far as I can > tell is unattainable via stsadm, which is why I've gone the long route and > come up with what I have so far. > > Ultimately what I need to do, is generate a list of all users listed as Site > Owners (not site collection owners) for all Site Collections, across > multiple Web Applications, and have it output into an xml file. *So far from > what I can tell there is no method of pulling all of this data via stsadm. > I can pull all site collections from a specific Web App via stsadm, which is > how I generate the sites.xml so for now I have to manually update the script > every time I add a new Web Application, I haven't found a way to generate a > list of all Web Apps and their Site Collections. > > Roland > > "Oisin (x0n) Grehan [MVP]" <ois...@xxxxxx> wrote in messagenews:b8dc5b45-b719-4ed9-a36c-27a018cc883d@xxxxxx > > > Quote: > > On Feb 20, 4:54 pm, "Roland Serman" <roland.ser...@xxxxxx> > > wrote: Quote: > >> I've got a script that lists all the Owners of a SharePoint site. I need > >> to > >> loop it so that it gathers this information for all the sites in an > >> array. Quote: Quote: > >> This is what I have so far: Quote: Quote: > >> $mysites = Import-CliXml sites.xml Quote: Quote: > >> $sitepath="https://mysharepointsite.com" > >> [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > >> $site=new-object Microsoft.SharePoint.SPSite($sitepath) > >> $web=$site.Rootweb > >> $web.site.url > >> $groups = $web.groups | ? {$_.Name -match "^.*Owners" } > >> foreach($group in $groups) > >> { > >> Write-Output "+ $($group.Name)" > >> foreach($user in $group.users){Write-Output " - $user"} Quote: Quote: > >> } Quote: Quote: > >> the "$mysites = import-CliXml sites.xml" contains all the sites that I > >> need > >> to run the remainder of the script against, formatted as so: Quote: Quote: > >> - <Props> > >> <S N="Url">https://mysharepointsite1.com</S> > >> <S N="Owner">Domain\UserID</S> > >> <S N="ContentDatabase">ContentDBName</S> > >> <S N="StorageUsedMB">1.9</S> > >> <S N="StorageWarningMB">1843</S> > >> <S N="StorageMaxMB">2048</S> > >> </Props> > >> </Obj> > >> - <Obj RefId="RefId-0"> > >> <TNRef RefId="RefId-0" /> Quote: Quote: > >> The Url has for each site has to excerpted in $sitepath and the remainder > >> of > >> the script run against it, and then looped and run against the next Url > >> in > >> the xml file. Quote: Quote: > >> Any suggestions would be greatly appreciated. Quote: Quote: > >> Roland Quote: > > Hi Roland, Quote: > > You'd be better off using STSADM in conjunction with PowerShell - this > > is quite easy since STSADM returns XML strings for a lot of its > > operations: Quote: > > PS> $xml = [xml](stsadm -o enumsites -urlhttp://localhost) > > PS> $xml.sites.site | select Url, Owner | ft -auto Quote: > > Url * * * * * * * * * * * * * * * * * * * Owner > > --- * * * * * * * * * * * * * * * * * * * ----- > >http://localhost* * * * * * * * * * Domain\user1 > >http://localhost/MySite* * * * * * * * *NT AUTHORITY\network service Quote: > > etc.. etc.. Quote: > > You can redirect this to a file by doing: Quote: > > PS> $xml.sites.site | select Url, Owner | out-file owners.txt Quote: > > Hope this helps, [reflection.assembly]::loadwithpartialname("microsoft.sharepoint") [reflection.assembly]::loadwithpartialname("microsoft.sharepoint.portal") [Microsoft.SharePoint.Administration.SPFarm]::local.services | ` % { $_.WebApplications } | % { $_.Sites } | % { $_.RootWeb } | % { $_.Groups } | ? { $_.Name -like "*Owners" } | select @{Name="Owners";Expression={$_.Users}}, ` @{Name="Url";Expression={$_.ParentWeb.Url}} Hopefully the above script doesn't get too mangled with word wrapping. - Oisin |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Help looping a script Not bad at all. The only problem is that it lists "{user1, user2, user3...}" it also lists them as lastname, firstname, lastname, firstname. Other than that the script you've provided works beuatifully and does exactly what I'm looking for. Just need to get to display all users the users in the group, not just the first 3 or 4, and I need it to list thier actual User ID's not thier display names. Unfortunatly I'm quite new to PowerShell, and scripting in general, any idea on how to modify what you've provided to display the AD user account as apposed to thier display names? Any thoughts? Thanks, Roland "Oisin (x0n) Grehan [MVP]" wrote: Quote: > On Feb 21, 10:08 am, "Roland Serman" <roland.ser...@xxxxxx> > wrote: Quote: > > The problem is I don't need the Site Collection Owners. I'm trying to get > > the users listed in the "<Site Name> Owners" group, which as far as I can > > tell is unattainable via stsadm, which is why I've gone the long route and > > come up with what I have so far. > > > > Ultimately what I need to do, is generate a list of all users listed as Site > > Owners (not site collection owners) for all Site Collections, across > > multiple Web Applications, and have it output into an xml file. So far from > > what I can tell there is no method of pulling all of this data via stsadm. > > I can pull all site collections from a specific Web App via stsadm, which is > > how I generate the sites.xml so for now I have to manually update the script > > every time I add a new Web Application, I haven't found a way to generate a > > list of all Web Apps and their Site Collections. > > > > Roland > > > > "Oisin (x0n) Grehan [MVP]" <ois...@xxxxxx> wrote in messagenews:b8dc5b45-b719-4ed9-a36c-27a018cc883d@xxxxxx > > > > > > Quote: > > > On Feb 20, 4:54 pm, "Roland Serman" <roland.ser...@xxxxxx> > > > wrote: > > >> I've got a script that lists all the Owners of a SharePoint site. I need > > >> to > > >> loop it so that it gathers this information for all the sites in an > > >> array. Quote: > > >> This is what I have so far: Quote: > > >> $mysites = Import-CliXml sites.xml Quote: > > >> $sitepath="https://mysharepointsite.com" > > >> [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > > >> $site=new-object Microsoft.SharePoint.SPSite($sitepath) > > >> $web=$site.Rootweb > > >> $web.site.url > > >> $groups = $web.groups | ? {$_.Name -match "^.*Owners" } > > >> foreach($group in $groups) > > >> { > > >> Write-Output "+ $($group.Name)" > > >> foreach($user in $group.users){Write-Output " - $user"} Quote: > > >> } Quote: > > >> the "$mysites = import-CliXml sites.xml" contains all the sites that I > > >> need > > >> to run the remainder of the script against, formatted as so: Quote: > > >> - <Props> > > >> <S N="Url">https://mysharepointsite1.com</S> > > >> <S N="Owner">Domain\UserID</S> > > >> <S N="ContentDatabase">ContentDBName</S> > > >> <S N="StorageUsedMB">1.9</S> > > >> <S N="StorageWarningMB">1843</S> > > >> <S N="StorageMaxMB">2048</S> > > >> </Props> > > >> </Obj> > > >> - <Obj RefId="RefId-0"> > > >> <TNRef RefId="RefId-0" /> Quote: > > >> The Url has for each site has to excerpted in $sitepath and the remainder > > >> of > > >> the script run against it, and then looped and run against the next Url > > >> in > > >> the xml file. Quote: > > >> Any suggestions would be greatly appreciated. Quote: > > >> Roland Quote: > > > Hi Roland, Quote: > > > You'd be better off using STSADM in conjunction with PowerShell - this > > > is quite easy since STSADM returns XML strings for a lot of its > > > operations: Quote: > > > PS> $xml = [xml](stsadm -o enumsites -urlhttp://localhost) > > > PS> $xml.sites.site | select Url, Owner | ft -auto Quote: > > > Url Owner > > > --- ----- > > >http://localhost Domain\user1 > > >http://localhost/MySite NT AUTHORITY\network service Quote: > > > etc.. etc.. Quote: > > > You can redirect this to a file by doing: Quote: > > > PS> $xml.sites.site | select Url, Owner | out-file owners.txt Quote: > > > Hope this helps, > Ah, I see. How about: > > [reflection.assembly]::loadwithpartialname("microsoft.sharepoint") > [reflection.assembly]::loadwithpartialname("microsoft.sharepoint.portal") > > [Microsoft.SharePoint.Administration.SPFarm]::local.services | ` > % { $_.WebApplications } | % { $_.Sites } | > % { $_.RootWeb } | % { $_.Groups } | > ? { $_.Name -like "*Owners" } | > select @{Name="Owners";Expression={$_.Users}}, ` > @{Name="Url";Expression={$_.ParentWeb.Url}} > > Hopefully the above script doesn't get too mangled with word wrapping. > > - Oisin > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| VB script just keeps looping and does not excute the code | VB Script | |||
| Looping through directory | VB Script | |||
| Looping and If Structures | Vista General | |||
| AD Changes and Looping | PowerShell | |||
| Looping at start | Vista installation & setup | |||