Getting Document Information on a SharePoint Site

Posted November 6, 2012 By Kevin Bennett

When I started at this new position they were going through a conversion from SharePoint 2007 to 2010 on the Intranet and Extranet. Actually the day before I started they attempted to the conversion and failed, so as soon as I finished my “in processing” I was pulled out of classes and put to work.

One of the first major projects (after getting the sites back up and running) was to perform a document clean up. As many company’s without a web governance standard knows after several years of uploading documents they didn’t have a handle on what was actually on the site. In order to actually see what was on the site I found/modified the following script (if I got it from you please comment if you find this so I can give credit where it is due).


function Get-DocInventory() {
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
foreach ($spService in $farm.Services) {
if (!($spService -is [Microsoft.SharePoint.Administration.SPWebService])) {
continue;
}
foreach ($webApp in $spService.WebApplications) {
if ($webApp -is [Microsoft.SharePoint.Administration.SPAdministrationWebApplication]) { continue }

foreach ($site in $webApp.Sites) {
foreach ($web in $site.AllWebs) {
foreach ($list in $web.Lists) {
if ($list.BaseType -ne "DocumentLibrary") {
continue
}
foreach ($item in $list.Items) {
$data = @{
"Web Application" = $webApp.ToString()
"Site" = $site.Url
"Web" = $web.Url
"list" = $list.Title
"Item ID" = $item.ID
"Item URL" = $item.Url
"Item Title" = $item.Title
"Item Created" = $item["Created"]
"Item Modified" = $item["Modified"]
"File Size" = $item.File.Length/1KB
}
New-Object PSObject -Property $data
}
}
$web.Dispose();
}
$site.Dispose()
}
}
}
}
Get-DocInventory | Export-Csv -NoTypeInformation -Path d:\temp\inventory.csv

The script will query the sites on the current farm (I would run this from the WFE Server) and return all the Documents. Note this also returned default.aspx and master pages but I would just filter those out of the spreadsheet.

Using one of my past writeups I would have another PowerShell Script upload to a List on our cleanup site and graph out the information so it looked good using Fusion Charts.

Conclusion of the Project BTW was 289k documents trimmed down to roughly 150k… at least it’s a start!!

Be the first to comment
    

This site I am working is seems to hate me (as the last few posts can contest). We ran into another problem last night when the Publisher tried to create a new Banner on the Rotating Banner. When they entered the title that included an apostrophe none of the text after the apostrophe showed up. Being a sys admin my answer was just don’t use apostrophes, but they are all communications majors so to them there is a big difference between “Childrens” and “Children’s”.
From my understanding it is because the JSON is using the Single Quote for escape characters hence the apostrophe appears to be the end of the text.

The work around for this was to use the ASCII code for apostrophe so publishers have to enter the text with the code instead of an apostrophe. The Client would then convert the code into an ‘.

Be the first to comment
    

jQuery Rotating Banner Errors – IE vs Chrome

Posted October 18, 2012 By Kevin Bennett

So we created a Rotating Banner that pulls from the Blog Posts in the Sharepoint Blog but were having an issue with it showing in IE and Firefox but not in chrome. The actual solution I will post later but wanted to capture the fix incase it comes up someplace else.

In the jQuery SPServices Operation of GetListItems we needed to change:

jQuery(xData.responseXML).find("z\\:row").each(function(i)
to
jQuery(xData.responseXML).find("z\\:row, row").each(function(i)

I think it actually will do 2 searches of the List Items but since there are so few (max 4 or 5) I don’t think it matters much.

Be the first to comment
    

I know even as I was doing it that I was just being lazy. The issue was that each day I run a bitlocker script to update a chart of bitlockered machines on our intranet. The hard part (..right) was that I needed to manually create an Item in a Summary Graph so the numbers look pretty for my manager. In this list I had title, date, Bitlocker Yes, Bitlocker No. So basically I just needed to enter 4 things each morning. Being that I am a sys admin with the motto of work smarter and not harder 4 items to enter was WAY too much for me to bother with. So of course I set date to default to Today but needed a way to set the title to “MM-DD Report” (don’t judge me on originality, my manager liked it).

Simply added to the Title Column Default Setting Calculated with

=TEXT([TODAY],"MM-DD") & " Report"

So now I only have to enter 2 columns.
Now to figure out How to auto populate those other 2 fields and I might be able to sleep in an extra 5 minutes.

Be the first to comment
    

Update a SharePoint List from a CSV File

Posted September 15, 2012 By Kevin Bennett

So in the last post over on http://SysAdminNightmare.com I created a CSV file for all the domain computers that had a Bitlocker key assigned to it.

Going with the work smarter not harder mantra this post will take that CSV file and update a list on our sharepoint site so I can create a graph.

Note that this must be run from a location where the Sharepoint Snap in is installed, this is usually where Sharepoint is installed so I would save this to a common drive and run from my app server.

UpdateList.ps1

[code]

# Check if the Sharepoint Snapin is loaded already, and load if not
if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
Add-PSSnapin Microsoft.SharePoint.PowerShell
}

#Setting our variables, Site name, List name, file to import and Caml
$spWeb = Get-SPWeb -Identity “https:///Departments/IT/”
$list = $spWeb.Lists[“Bitlocker”]
$csv = Import-Csv Q:\BitLockerComputerReport.csv
$caml=””

#sets up to remove current items from list
$query=new-object Microsoft.SharePoint.SPQuery
$query.ViewAttributes = “Scope=’Recursive'”
$query.Query=$caml
$items=$list.GetItems($query)

#removes current items from list
$items | % { $list.GetItemById($_.Id).Delete() }

#adds Report to SharePoint List
foreach ($row in $csv)
{
$item = $list.Items.Add();
$item[“Name”] = $row.Name;
$item[“OS”] = $row.OperatingSystem;
$item[“Location”] = $row.Location;
$item[“Bitlocker”] = $row.HasBitlockerRecoveryKey;
$item[“Virtual”] = $row.adminDescription;
$item.Update();
}

#Dispose of SPWeb, to keep things clean and no memory leaks
$spweb.Dispose()

[/code]

Again, you need to change your site name, list name and make sure your list has the correct columns. I would task this to run after the script that creates the CSV file.

Next I have one more post in this series where I take the raw csv file and upload to a sharepoint library incase the bosses want to play around with the numbers (as they always do).

Be the first to comment
    
%d bloggers like this: