{"id":30,"date":"2013-01-20T23:08:47","date_gmt":"2013-01-20T23:08:47","guid":{"rendered":"http:\/\/www.johntimney.com\/?p=30"},"modified":"2013-03-22T23:09:27","modified_gmt":"2013-03-22T23:09:27","slug":"powershell-its-everywhere","status":"publish","type":"post","link":"https:\/\/www.johntimney.com\/?p=30","title":{"rendered":"PowerShell, It&#8217;s everywhere"},"content":{"rendered":"<p>Love it or hate it, you cannot avoid it.\u00a0 if you are expecting to do any work in SharePoint 2013 then you simply need to have skills in Powershell, or at least a working knowledge of its capabilities.<\/p>\n<p>Let&#8217;s assume you need to get out some stats because your manager is knocking on your door asking for Usage Reports.\u00a0 These can be found under Site Settings -&gt; Site Administration -&gt;Popularity Trends -&gt; View Usage Reports.<\/p>\n<p>They are though a little constrained but you can get deep and dirty with powershell.\u00a0 The web contains many a fine example of how to get more granular\u00a0 (Example below is taken from the Technet forums so credit to R Tut)<\/p>\n<p>Get the Usage Reports for a site collection in PoweShell<\/p>\n<p>$searchApp = Get-SPEnterpriseSearchServiceApplication<\/p>\n<p>$site = Get-SPSite &#8220;{SiteUrl}&#8221;<\/p>\n<p>$result = $searchApp.GetRollupAnalyticsItemData(1,[System.Guid]::Empty,$site.ID,[System.Guid]::Empty)<br \/>\n$result<\/p>\n<p>#for a specific date or for a specific month<\/p>\n<p>$date = Get-Date &#8220;2013-01-18&#8221;<br \/>\n$result.GetHitCountForDay($date)<br \/>\n$result.GetHitCountForMonth($date)<\/p>\n<p>Or using object model<\/p>\n<p>SPSecurity.RunWithElevatedPrivileges(delegate<br \/>\n{<\/p>\n<p>\/\/ You can use SPContext.Current.Site.ID if you have HttpContext<\/p>\n<p>using (var site = new SPSite(siteId))<br \/>\n{<br \/>\nvar context = SPServiceContext.GetContext(site);<br \/>\nvar searchProxy = context.GetDefaultProxy(typeof(SearchServiceApplicationProxy)) as SearchServiceApplicationProxy;<br \/>\nvar usageData= searchProxy.GetRollupAnalyticsItemData(1,Guid.Empty,site.ID,Guid.Empty);<br \/>\n\/\/ process it<br \/>\n}<br \/>\n});<\/p>\n<p>&#8230;.and in fact to enable us to schedule and script the output should we chose to do that, but we could also add code to upload this to a specific document library using powersehll for a fully automated solution for granular reporting.<\/p>\n<p>You will find some impressiv examples in technet to help you manage 2013 with powershell here:<\/p>\n<p>http:\/\/technet.microsoft.com\/en-us\/library\/ee890108.aspx<\/p>\n<p>You can even manage SQL server via powershell now and a whole raft of start examples abound here:<\/p>\n<p>http:\/\/technet.microsoft.com\/en-us\/library\/cc281954.aspx<\/p>\n<p>So, no excuses.\u00a0 Learn powershell.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Love it or hate it, you cannot avoid it.\u00a0 if you are expecting to do any work in SharePoint 2013 then you simply need to have skills in Powershell, or at least a working knowledge of its capabilities. Let&#8217;s assume you need to get out some stats because your manager is knocking on your door [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.johntimney.com\/index.php?rest_route=\/wp\/v2\/posts\/30"}],"collection":[{"href":"https:\/\/www.johntimney.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johntimney.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johntimney.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johntimney.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=30"}],"version-history":[{"count":2,"href":"https:\/\/www.johntimney.com\/index.php?rest_route=\/wp\/v2\/posts\/30\/revisions"}],"predecessor-version":[{"id":32,"href":"https:\/\/www.johntimney.com\/index.php?rest_route=\/wp\/v2\/posts\/30\/revisions\/32"}],"wp:attachment":[{"href":"https:\/\/www.johntimney.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=30"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johntimney.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=30"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johntimney.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=30"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}