What you will find here

If you are one of those multi hat kind of person you might want to take a look here.
Some of the sections here will cover: SharePoint, SQL, Server, VB Script, Batch files, PCI Compliance

Icon

Icon

Friday, March 28, 2014

Add library to SharePoint sites using power shell


Will work on your sites three, run from your top site.

$sites = Get-SPWeb <site url>
foreach ($site in $sites.webs)
{
 $listTemplate = $Site.ListTemplates["Document Library"];
 $Site.Lists.Add(<Library name>,<Library Name>,$listTemplate);
 $list = $Site.Lists[<Library Name>];
 $list.Title = <Library Title>;
 $List.DefaultItemOpen = "PreferClient";
 $list.EnableVersioning = $true;               
 $list.EnableMinorVersions = $false;
 $list.MajorVersionLimit = 0;        
 $list.ForceCheckout = $true;
 $List.OnQuickLaunch = $true;
 $List.ContentTypesEnabled = $true
 $list.Update()
 $ctToRemove = $list.ContentTypes[<Main Content Type>]
 $list.ContentTypes.Delete($ctToRemove.Id)
 $list.Update()
 $SPWeb1 = Get-SPWeb -Identity <Main Site where content type is>
 $ctToAdd = $SPWeb1.ContentTypes[<Content Type Name>];
 $ct = $List.ContentTypes.Add($ctToAdd);
 $list.Update()
 $Site.Dispose() 
 $SPWeb1.Dispose()
}

Get table size T SQL

Simple and effective your admin will love this


SELECT   DB_NAME() AS DatabaseName
   , object_name(i.object_id) AS TableName
   , ISNULL(i.name, 'HEAP') AS IndexName
   , i.index_id AS IndexID
   , i.type_desc AS IndexType
   , p.partition_number AS PartitionNo
   , p.[rows] AS NumRows
   , au.type_desc AS InType
   , au.total_pages AS NumPages
   , au.total_pages * 8 AS TotKBs
   , au.used_pages * 8 AS UsedKBs
   , au.data_pages * 8 AS DataKBs
FROM sys.indexes i INNER JOIN sys.partitions p
ON i.object_id = p.object_id AND i.index_id = p.index_id
INNER JOIN sys.allocation_units au ON
CASE
WHEN au.[type] in (1,3) THEN p.hobt_id
WHEN au.type = 2 THEN p.partition_id
end = au.container_id
INNER JOIN sys.objects o ON i.object_id = o.object_id
WHERE o.is_ms_shipped <> 1
ORDER BY TableName, i.index_id

Database in lock state?

With this script you will get your panic attack under control

Use <Database>

sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Agent XPs', 1;
GO
RECONFIGURE

Easy way to Shrink databases Log


Easy to set up as an scheduled task

USE DatabaseName
GO
DBCC SHRINKFILE(<TransactionLogName>, 1)
BACKUP LOG <DatabaseName> WITH TRUNCATE_ONLY
DBCC SHRINKFILE(<TransactionLogName>, 1)
GO

Same apply to the database file

USE [RC_BI_DW]  DBCC SHRINKFILE (N<Database file name> , 0, TRUNCATEONLY)

SharePoint Add Gropup to Site using Power Shell


Simple Script to add an existing group to a site or sites.

$sites = Get-SPWeb "Site url"
foreach ($site in $sites.webs)
{
$site.AssociatedGroups.Add($site.SiteGroups["Group Name"]);
$GroupAccount = $site.SiteGroups["Group Name"]
$timeoffassignment = New-Object Microsoft.SharePoint.SPRoleAssignment($GroupAccount)
$timeoffrole = $site.RoleDefinitions["Read"]
$timeoffassignment.RoleDefinitionBindings.Add($timeoffrole)
$site.RoleAssignments.Add($timeoffassignment)
$site.Update()
$site.Dispose()
}

So you wear multiple hats?


If you are one of those multi hat kind of person you might want to take a look here.
I hope I can help with some tricks or tips that will make your life a little easier.

Some of the sections here will cover:
·         SharePoint
·         SQL Server
·         VB Script
·         Batch files
·         PCI Compliance