1/29/2015

PowerShell Sorting Tip for Enumerations

 

Do you ever have a PowerShell script that just won't sort right?

The problem? PowerShell makes assumptions, and not always the ones you would make. For example let's get a list of SharePoint lists and sort them by their BaseTemplate property:

    $mtg = Get-SPWeb http://maxsp2013wfe/sites/Meetings
    $mtg.Lists | Sort BaseTemplate | Select BaseTemplate, Title

Is the result you would expect?

image

Not what I first expected… but there's a hint hiding there though… Why is the BaseTemplate column right aligned as if was numeric?

If we take the above script and pipe it to Get-Member we find that BaseTemplate is not a string! It's an object of some kind. It's an SPListTemplateType object!

image

So let's see what that is… Doing a Bing on Microsoft.SharePoint.SPListTemplateType reveals that it is an enumeration, which internally is a number. If you look at the list in the MSDN article you will see both the text and numeric values of the base types.

image

What we need is the display text for the enumeration, and we can get that by using the ToString() method. As that would then be an expression, we need to add the annoying curly brackets and the $_. notation.

    $mtg.Lists | Sort { $_.BaseTemplate.ToString() } | Select BaseTemplate, Title

And now we get:

image

And that's more like it! (except for the right align stuff that going on)

Convert the column in the Select to a string and all's well!

    $mtg.Lists | Sort {$_.BaseTemplate.ToString()} | Select {$_.BaseTemplate.ToString()}, Title

image

 

So what were the PowerShell assumptions?

  1. To display the text value of the enumeration, and align it as a number.
  2. To sort on the numeric value of the enumeration.

(And you know what "assume" does, right?)  Smile

 

.

1/26/2015

SharePoint Auditing and Site Content Administration using PowerShell

 

If you have attended one of my SharePoint Saturday PowerShell presentations or read my PowerShell series at SharePoint Pro magazine, then you know a bit about what's possible with PowerShell. This Friday. January, 30th, I will be delivering one of the more fun classes I do: "SharePoint 2010 and 2013 Auditing and Site Content Administration using PowerShell". If you are a SharePoint administrator and need to "find and inventory stuff" in SharePoint then you need this class! Whatever is hiding in SharePoint is visible to the PowerShell user, if you know where to look.

Class details are here: http://www.maxtrain.com/Classes/ClassInfo.aspx?Id=119394
You can join us at MAX Technical Training in Cincinnati or attend remotely from your office or home.

This class is available world wide though Microsoft training partners
and the Microsoft Courseware library. Just ask for course 55095.

 

MS-55095 SharePoint 2010 and 2013 Auditing and Site Content Administration using PowerShell

This one day instructor-led class is designed for SharePoint 2010 and 2013 server administrators and auditors who need to query just about anything in SharePoint. The class handout is effectively a take home cheat sheet with over 175 PowerShell scripts plus the general patterns to create your own scripts. These scripts cover:

  • getting lists / inventories of servers, services web applications, sites, webs, lists, libraries, items, fields, content types, users and much more
  • finding lists by template type, content type and types of content
  • finding files by user, content type, file extension, checked out status, size and age
  • finding inactive sites
  • finding and changing SharePoint Designer settings and finding and resetting customized pages
  • inventorying and managing features
  • deleting and recycling files and list items
  • inventorying users and user permissions and finding out “who can access what”
  • creating sites, lists and libraries
  • uploading and downloading files
  • general tips for counting, reformatting and exporting results;
  • drilling up and down the SharePoint object model
  • and much more…

 

Prerequisites: You should have good SharePoint skills as and end user and administrator along with some practical experience with PowerShell.

 

.

1/22/2015

Cincinnati SharePoint User Group Remote Access Tonight

 

Go here after 4:00 PM EST for login instructions: www.CincinnatiSPUG.org

Meeting will start at 6:00 for food, social and networking. Presentation will start at 6:30 PM EST.

Attending physically or remotely? Register here and let us know! http://www.meetup.com/TechLife-Cincinnati/events/219938769/

Support your local user group!

(yah, a movie title rip off…)

Your local IT user groups… one of the few really useful free things in life. Attend, network, learn and share!

For a list of Cincinnati area user groups see here:
http://www.maxtrain.com/UserGroups.aspx

For a list of upcoming user group events see here:
http://www.meetup.com/TechLife-Cincinnati/

And don't forget tonight's Cincinnati SharePoint user group meeting!
http://www.meetup.com/TechLife-Cincinnati/events/219938769/

A list of SharePoint User Groups:
http://www.sharepointfest.com/portal/index.php/2012-04-13-17-00-56/sharepoint-user-groups/north-america/united-states

A list of .Net User Groups:
http://blogs.msdn.com/b/dotnet/p/dotnetusergroups.aspx

A large list of user groups / communities:
https://www.technicalcommunity.com/CommunityDirectory.aspx

Benefits of user groups:

  • Networking! Bring your business cards, questions and ideas to the meeting!
  • Networking!  Looking for a job? Looking for an new employee?
  • Free consulting! Really! Many of the user group attendees work for consulting firms. Ask away!
  • Free food! Most user groups supply pizza or sandwiches at the meeting.
  • Discounts! User groups have access to book, training and other discounts. If you don't see them listed on the user group's web sites, then ask.
  • Learn! Every session will present something new. New products, new ideas, new twists on old ideas or just a new way to think about or use the technology.
  • Stay up to date… about bugs, fixes, tricks, events, and stuff you would have never even thought about.
  • Get a raise! (Maybe… just present the next great idea at work that your stole from the user group meeting.)
  • Free stuff! Most user groups get lots of books, gadgets and toys from the sponsors that they pass out at the meetings.

 

Reasons not to attend:

  • There's something better on TV tonight, I don't have a DVR, and it will really improve my life!
  • Don't like the topics. Well… recommend some new topics. We will find the speakers! (Or volunteer to speak!)
  • Don't like free food, books, toys and other goodies
  • Don't need to network! I already know everything and could not be any better at my job! (Well then you should come to the meetings and share!)
  • Boss won't let me go.  Get a better boss! (Unless we are speaking about your better half…) Or just tell your boss that they usually charge $500 for this kind of event, but you know someone and can get the training, network and consulting for free.

 

What you can do…

  • Attend and share! I guarantee that you know something about the technology that no one else at the meeting does.
  • Volunteer. There's always something that needs to be done.
  • Get your company to sponsor a meeting! It will be some of the least expensive promotion they do all year.
  • Speak! We always need speakers. Not comfortable speaking? Ask about 5-15 minute lightning rounds. Little or no prep needed. Just share something cool that you have done, or something interesting you have just figured out. (Adding "speaker" to your resume is pretty cool too!)
  • Promote the meetings! Coworkers, Twitter, Blogs, students… get the word out!
  • Thank the sponsors!  (and consider buying their products)
  • Thank the volunteers!  (and consider buying them a cold beverage!)
  • Thank the speakers!  (and consider buying their services, their books… or a cold beverage!)

 

.

Note to spammers!

Spammers, don't waste your time... all posts are moderated. If your comment includes unrelated links, is advertising, or just pure spam, it will never be seen.