Friday, December 11, 2015

Good PowerShell SCRIPT Site

Good Powershell SCRIPT Site

http://get-spscripts.com/2010/07/upload-multiple-files-into-document.html

Make timer job online in sharepoint 2010

$farm  = Get-SPFarm
$disabledTimers = $farm.TimerService.Instances | where {$_.Status -ne "Online"}
if ($disabledTimers -ne $null)
{
    foreach ($timer in $disabledTimers)
    {
        Write-Host "Timer service instance on server " $timer.Server.Name " is not Online. Current status:" $timer.Status
        Write-Host "Attempting to set the status of the service instance to online"
        $timer.Status = [Microsoft.SharePoint.Administration.SPObjectStatus]::Online
        $timer.Update()
    }
}
else
{
    Write-Host "All Timer Service Instances in the farm are online! No problems found"
}
 


Thanks to http://blogs.msdn.com/b/tehnoonr/archive/2011/09/07/sharepoint-server-2010-unable-to-provision-user-profile-synchronization-service-after-upgrade.aspx

Gridview Check box validation


    <script type="text/javascript">
        function Validate() {
            var gridView = document.getElementById("<%=GridView_SResult.ClientID %>");
            var checkBoxes = gridView.getElementsByTagName("input");
            var flag = false;
            for (var i = 0; i < checkBoxes.length; i++) {
                if (checkBoxes[i].type == "checkbox" && checkBoxes[i].checked) {
                    flag = true;
                 
                }
            }
            if (flag == true) {
                return true;
            }
            else {
                alert('Please select atleast one record.');
                return false;
            }
        }
</script>

<asp:Button ID="btn_Arch" runat="server"  OnClientClick="return Validate();"  Text="Arch" />

CAML Query in powershell

function Get-SPList($webUrl, $lstUrl)
{
    $webObj = Get-SPWeb -identity $webUrl
    $lstObj = $webObj.GetList($lstUrl);
    return $lstObj
}
$spList = Get-SPList -webUrl "http://mysitecollecton/MySite" -lstUrl "http://mysitecollecton/MySite/Lists/EmpInfo"
$spQuery = new-object Microsoft.SharePoint.SPQuery
 $camlQuery =
 "<Where>
   <Eq>
    <FieldRef Name='Department' />
      <Value Type='Text'>HR</Value>
   </Eq>
 </Where>"
$spQuery.Query = $camlQuery
$spQuery.RowLimit = 100
 $spListItemCollection = $spList.GetItems($spQuery)
  $spListItemCollection | ForEach-Object {
 $_["Description"] = "Hi there..."
 $_.Update()
 }


=============================================================================================

function Get-SPList($webUrl, $lstUrl)
{
    $webObj = Get-SPWeb -identity $webUrl
    $lstObj = $webObj.GetList($lstUrl);
    return $lstObj
}
$spList = Get-SPList -webUrl "http://mysitecollecton/MySite" -lstUrl "http://mysitecollecton/MySite/Lists/EmpInfo"
$spQuery = new-object Microsoft.SharePoint.SPQuery
 $camlQuery =
 "<Where>
   <Eq>
    <FieldRef Name='Department' />
      <Value Type='Text'>HR</Value>
   </Eq>
 </Where>"
$spQuery.Query = $camlQuery
$spQuery.RowLimit = 100
 $spListItemCollection = $spList.GetItems($spQuery)
 
  # Create batch remove CAML query
  $batchRemove = '<?xml version="1.0" encoding="UTF-8"?><Batch>';
 
  # The command is used for each list item retrieved
  $command = '<Method><SetList Scope="Request">' +
  $spList.ID +'</SetList><SetVar Name="ID">{0}</SetVar>' +
  '<SetVar Name="Cmd">Delete</SetVar></Method>';
 
  foreach ($item in $spListItemCollection)
  {
     
     $batchRemove += $command -f $item.Id;
  }
  $batchRemove += "</Batch>";
 
  # Remove the list items using the batch command
  $spList.ParentWeb.ProcessBatchData($batchRemove) | Out-Null
==========================================================================================

Thnaks to "http://adicodes.com/update-delete-copy-list-items-with-powershell-in-sharepoint-2010/"