Tuesday 29 July 2014

SharePoint Farm BackUp


Config DB backup can be accomplish by two ways through PS as below:

 - Full Config Back up of DB:
    Backup-SPConfigurationDatabase -Directory -DatabaseServer  -DatabaseName -Verbose
 - Configuration details alone
    Backup-SPFarm -Directory \\file_server\share\Backup -BackupMethod full -ConfigurationOnly

Full Farm Backup


    Backup-SPFarm – Directory “\\server_name\Full_Farm_Backup” –backupmethod Full

Wednesday 16 July 2014

How to take screenshot using VBScript

Dim dt
dt=now
set WshShell = CreateObject("WScript.Shell")
WshShell.Run "taskmgr.exe"
WScript.Sleep 2000
WshShell.SendKeys "% x"
Set oWordBasic = CreateObject("Word.Basic")
oWordBasic.SendKeys "{prtsc}"
oWordBasic.AppClose "Microsoft Word"
WScript.Sleep 2000
WshShell.SendKeys "% n"
WshShell.Run("C:\\ScreenShots\\ScreenShots.docx")
WScript.Sleep 1000
WshShell.SendKeys "% x"
WScript.Sleep 1000
WshShell.SendKeys dt
WshShell.SendKeys "^v"
WScript.Sleep 500
WshShell.SendKeys "^s"
WScript.Sleep 500
WshShell.SendKeys "{ENTER}"
WScript.Sleep 5000
WshShell.Run "taskkill /im winword.exe", , True
WScript.Sleep 500
WshShell.SendKeys "{ENTER}"
Set WshShell=Nothing
WScript.Quit

Monday 14 July 2014

Set Index column in list in SharePoint 2013 using PowerShell


Following is the code
********************************************************
Start-SPAssignment
$subsite = Get-SPWeb http://perimeter.portal.qc.atc.local/apps/mngr

Function removeIndex ()
{
Param ($list,$InternalFldName)

    try
        {
        Write-Output "The searching  field $InternalFldName";

        $fldToIndex =$list.Fields.GetFieldByInternalName($InternalFldName);                                                

        Write-Output "The field $fldToIndex has been found";

            try
            {
               $index= $list.FieldIndexes.Item($fldToIndex.Id)
               $fldToIndex.Indexed = $true;  
               $list.FieldIndexes.Delete($fldToIndex.Id);
               Write-Output ("The indexed {0} has been removed" -f $fldToIndex.Title) ;
             
            }
            catch
            {
               Write-Output "The field $fldToIndex is already non-indexed"
            }

        }
    catch
        {
         $error[0]
        }

}


Function AddIndex ()
{
Param ($list,$InternalFldName)

    try
        {
        Write-Output "The searching  field $InternalFldName";

        $fldToIndex =$list.Fields.GetFieldByInternalName($InternalFldName);                                                

        Write-Output "The field $fldToIndex has been found";

            try
            {
               $index= $list.FieldIndexes.Item($fldToIndex.Id)
               Write-Output "The field $fldToIndex is already indexed"
            }
            catch
            {
                $fldToIndex.Indexed = $true;  
                $list.FieldIndexes.Add($fldToIndex);
                Write-Output ("The field {0} has been indexed" -f  $fldToIndex.Title);
            }

        }
    catch
        {
         $error[0]
        }

}

$listsToIndex = @{
"apps/mngr/lists/IMDocument"="Mngr_Id";
}

foreach ($lstToIndex in $listsToIndex.GetEnumerator())
{

Write-Output ( "Index  {0} for list {1} ..." -f $lstToIndex.Value,  $lstToIndex.Key );


$lst = $subsite.GetList($lstToIndex.Key)
$InternalFldName=$lstToIndex.Value

if (($lst -ne $null) -and ($InternalFldName -ne $null))
{
    #removeIndex  $lst $InternalFldName
    addIndex $lst $InternalFldName
    write-Output "~~~~~~~~~~~~~~~~~~~~"
 }
else
{
    Write-Output "The predefined list has error for $lst"
}

}