SharePoint listitems browser PowerShell GUI

0

PowerShell script that creates a form (application) that let you browse a specified SiteCollection down to item level.

The script gets the following information:

  • Display all WebApplications
  • Load all SiteCollections of a selected WebApplication
  • Load all (Sub)Sites of a selected SiteCollection
  • Load all Lists/Librarys of a selected Site
  • Load all ListItems of a selected List/Library
  • Displays the out-string of the ListItem object

Note: The script needs to be executed on a SharePoint Server as it uses the native SharePoint PowerShell Snap-in!

Version: The script was tested Windows Server 2012 R2 with SharePoint 2013.

<#
    .SYNOPSIS
        This script generates a GUI and let you navigate to a listitem
        Script: GUI-Analyze-ListItems
        Author: Christian Unnerstall
        Required Dependencies: Microsoft.SharePoint.PowerShell Snap-In
        Optional Dependencies: None
        Version: 0.9
            
    .DESCRIPTION
        This script generates a GUI and let you navigate to a listitem. Currently, the script gets the following information:
        - Display all WebApplications
        - Load all SiteCollections of a selected WebApplication
        - Load all (Sub)Sites of a selected SiteCollection
        - Load all Lists/Librarys of a selected Site
        - Load all ListItems of a selected List/Library
        - Displays the out-string of the ListItem object
        
    .NOTES
        This script is an intuitiv way to narrow down to a Microsoft SharePoint ListItem via GUI.
        Script was tested on a Microsoft SharePoint 2013 Application Server using Farm Admin account!
#>

# Add SharePoint PowerShell Snapin which adds SharePoint specific cmdlets
$ver = $host | select version
if ($ver.Version.Major -gt 1) {$host.Runspace.ThreadOptions = "ReuseThread"} 
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) 
{
    Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}

# Build form (GUI)
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")

$form_Main = New-Object System.Windows.Forms.Form
$form_Main.Text = "ListItem Tool (Read-only) by Christian Unnerstall - v1.1"
$form_Main.Size = New-Object System.Drawing.Size(1200,600)
$form_Main.StartPosition = "CenterScreen"
$form_Main.FormBorderStyle = "FixedDialog"
$form_Main.MaximizeBox = $false

# WebApplication
$form_lst_WebApplication = New-Object System.Windows.Forms.ListBox
$form_lst_WebApplication.Location = New-Object System.Drawing.Size(10,10)
$form_lst_WebApplication.Size = New-Object System.Drawing.Size(600,100)
$form_Main.Controls.Add($form_lst_WebApplication)

# SiteCollection
$form_lst_SiteCollection = New-Object System.Windows.Forms.ListBox
$form_lst_SiteCollection.Location = New-Object System.Drawing.Size(10,110)
$form_lst_SiteCollection.Size = New-Object System.Drawing.Size(600,100)
$form_Main.Controls.Add($form_lst_SiteCollection)

# Sites
$form_lst_Sites = New-Object System.Windows.Forms.ListBox
$form_lst_Sites.Location = New-Object System.Drawing.Size(10,210)
$form_lst_Sites.Size = New-Object System.Drawing.Size(600,100)
$form_Main.Controls.Add($form_lst_Sites)

# Lists
$form_lst_Lists = New-Object System.Windows.Forms.ListBox
$form_lst_Lists.Location = New-Object System.Drawing.Size(10,310)
$form_lst_Lists.Size = New-Object System.Drawing.Size(600,100)
$form_Main.Controls.Add($form_lst_Lists)

# ListItems
$form_lst_ListItems = New-Object System.Windows.Forms.ListView
$form_lst_ListItems.View = [System.Windows.Forms.View]::Details
$form_lst_ListItems.Location = New-Object System.Drawing.Size(10,410)
$form_lst_ListItems.Size = New-Object System.Drawing.Size(600,155)
$form_lst_ListItems.MultiSelect = $false
$form_lst_ListItems.FullRowSelect = $true
$cHeader1 =  New-Object System.Windows.Forms.ColumnHeader
$cHeader1.Text = "Name"
$cHeader1.Width = 350
$cHeader2 =  New-Object System.Windows.Forms.ColumnHeader
$cHeader2.Text = "UniqueId"
$cHeader2.Width = 220

$form_lst_ListItems.Columns.AddRange([System.Windows.Forms.ColumnHeader[]](@($cHeader1, $cHeader2)))
$form_Main.Controls.Add($form_lst_ListItems)

# Output TextBox (Read-Only)
$form_txt_output = New-Object System.Windows.Forms.TextBox
$form_txt_output.Location = New-Object System.Drawing.Size(620,10)
$form_txt_output.Size = New-Object System.Drawing.Size(565,547)
$form_txt_output.Multiline = $true
$form_txt_output.Font = New-Object System.Drawing.Font("Courier New", "8")
$form_txt_output.Wordwrap = $false
$form_txt_output.ReadOnly = $True
$form_txt_output.ScrollBars = [System.Windows.Forms.ScrollBars]::Vertical, [System.Windows.Forms.ScrollBars]::Horizontal
$form_Main.Controls.Add($form_txt_output)

# Load available WebApplications
$SPWebApplications = Get-SPWebApplication | select Name
foreach ($SPWepApplication in $SPWebApplications)
{   
    [void]$form_lst_WebApplication.Items.Add($SPWepApplication.Name)
}


# (Interactive) Functions
$form_lst_WebApplication.Add_DoubleClick(
{
    $form_lst_SiteCollection.Items.Clear()
    $form_lst_Sites.Items.Clear()
    $form_lst_Lists.Items.Clear()
    $form_lst_ListItems.Items.Clear()
    $form_txt_output.Text = ""
    $SPSiteCollections = Get-SPSite -WebApplication $form_lst_WebApplication.SelectedItem -Limit All | select Url
    foreach ($SPSiteCollection in $SPSiteCollections)
    {   
        [void]$form_lst_SiteCollection.Items.Add($SPSiteCollection.Url)
    }
}
)

$form_lst_SiteCollection.Add_DoubleClick(
{
    $form_lst_Sites.Items.Clear()
    $form_lst_Lists.Items.Clear()
    $form_lst_ListItems.Items.Clear()
    $form_txt_output.Text = ""
    $SPSites = (Get-SPSite $form_lst_SiteCollection.SelectedItem).AllWebs | select Url
    foreach ($SPSite in $SPSites)
    {   
        [void]$form_lst_Sites.Items.Add($SPSite.Url)
    }
}
)

$form_lst_Sites.Add_DoubleClick(
{
    $form_lst_Lists.Items.Clear()
    $form_lst_ListItems.Items.Clear()
    $form_txt_output.Text = ""
    $SPWeb = Get-SPWeb $form_lst_Sites.SelectedItem
    $SPLists = $SPWeb.Lists
    foreach ($SPList in $SPLists)
    {   
        [void]$form_lst_Lists.Items.Add($SPList.Title)
    }
}
)

$form_lst_Lists.Add_DoubleClick(
{
    $form_lst_ListItems.Items.Clear()
    $form_txt_output.Text = ""
    $SPListItems = ((Get-SPWeb $form_lst_Sites.SelectedItem).Lists[$form_lst_Lists.SelectedItem]).Items
    foreach ($SPListItem in $SPListItems)
    {   
        $item = New-Object System.Windows.Forms.ListViewItem($SPListItem.Name)
        $item.SubItems.Add(($SPListItem.UniqueId).Guid.ToString())
        [void]$form_lst_ListItems.Items.Add($item)
    }
}
)

$form_lst_ListItems.Add_DoubleClick({
    
    $form_txt_output.Text = ""
    $SPList = (Get-SPWeb $form_lst_Sites.SelectedItem).Lists[$form_lst_Lists.SelectedItem]
    $SPListItem = $SPList.Items | ? { $_.UniqueId -eq $form_lst_ListItems.SelectedItems[0].SubItems[1].Text }
    $form_txt_output.Text = Out-String -InputObject $SPLIstItem
})

# Finally show form (GUI)
$form_Main.Add_Shown({$form_Main.Activate()})
$form_Main.ShowDialog()
Share.

About Author

Christian Unnerstall

Christian Unnerstall, founder of devshooin.com, enjoys designing and building things that look nice and work well, whether it's websites or services within the interwebs. Have questions - feel free to reach out to him. Enjoy

Leave a Reply