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

Wednesday, April 16, 2014

Edit library in SharePoint site list with PowerShell


I like simple scripts I don't really like functions and all that when I need is to run a quick update.
Here a really nice one I've modified from some smart guys
I needed to remove the property "Force Check Out" from all libraries on my site collection.
 

$sites = Get-SPWeb {Site URL}
foreach ($site in $sites.webs)
{
$web = Get-SPWeb $site.URL
$library = $web.Lists[{Library Name}]
$library.ForceCheckOut = $false
$library.Update()
$web.Update()
$web.Dispose()
}
 
Additional options here

$library.EnableVersioning = $true
$library.EnableMinorVersions = $true
$library.MajorVersionLimit = $majorVersionLimit
$library.MajorWithMinorVersionsLimit = $minorVersionLimit
$library.ForceCheckOut = $requireCheckOut

I hope it helps

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)