Tagged: powershell Toggle Comment Threads | Keyboard Shortcuts

  • akhileshgandhi 12:26 am on July 9, 2013 Permalink | Reply
    Tags: large list, powershell,   

    PowerShell script to delete sharepoint large list in batch job 

    write-host

    1. Enter your configuration here

    $siteUrl = “http://abc/SiteDirectory/test/”
    $listName = “ErrorWarning”
    $batchSize = 100

    write-host “Opening web at $siteUrl…”

    $site = new-object Microsoft.SharePoint.SPSite($siteUrl)
    $web = $site.OpenWeb()
    write-host “Web is: $($web.Title)”
    $q = New-Object Microsoft.SharePoint.SPQuery ;
    $q.RowLimit = 100;

    $list = $web.Lists[$listName];
    write-host “List is: $($list.Title)”
    $command = [string]::Format(“<Method><SetList Scope=`”Request`”>{0}</SetList><SetVar Name=`”ID`”>{{0}}</SetVar><SetVar Name=`”Cmd`”>Delete</SetVar><SetVar Name=`”owsfileref`”>{{1}}</SetVar></Method>”, $list.ID);

    while ($list.ItemCount -gt 0)
    {
    write-host “Item count: $($list.ItemCount)”
    $coll = $list.GetItems($q);

    $sbDelete = New-Object -TypeName “System.Text.StringBuilder”;
    [void]$sbDelete.Append(“<?xml version=`”1.0`” encoding=`”UTF-8`”?><Batch>”)

    $ids = @()
    for ($i=0;$i -le $coll.Count;$i++)
    {
    $item = $coll[$i];
    [void]$sbDelete.Append([string]::Format($command, $item.ID.ToString(), $item.File.ServerRelativeUrl));
    $ids = $ids + $item.UniqueId;
    }
    $sbDelete.Append(“</Batch>”);

    write-host

    write-host “Sending batch…”

    1. We execute it

    $result = $web.ProcessBatchData($sbDelete)

    write-host “Emptying Recycle Bin…”

    1. We remove items from recyclebin

    $web.RecycleBin.DeleteAll()

    write-host

    $list.Update()
    }

    write-host “Done.”

     
  • akhileshgandhi 8:01 pm on July 2, 2013 Permalink | Reply
    Tags: Active Directory, powershell   

    Powershell sctript to get all Active Users and there Important Properties 

    Powershell sctript to get all Active Users and there Important Properties

    get-aduser -ldapfilter “(&(&(objectCategory=user)(userAccountControl=512)))” -Properties * |select DisplayName,UserPrincipalName,Title,SamAccountName,Manager,EmployeeNumber,EmployeeID,City,Country,Deleted,Department,Division,MobilePhone,Office,OfficePhone,Organization,POBox ,PostalCode,State,StreetAddress, EmailAddress,givenname, sn,enabled | export-csv -path c:\users.csv

     

    I will update this script to insert this data in Database 

     
  • akhileshgandhi 6:52 pm on July 2, 2013 Permalink | Reply
    Tags: , lastmodified, powershell, , , size   

    Get All SiteCollection Audit Info 

    cls
    #get-spsite -Limit All -ContentDatabase WSS_Content_ProjectServer | select url,@{label=”Size in GB”;Expression={$_.usage.storage/1024MB}} | Format-Table –AutoSize

    function ProcessSiteCollection($site)
    {

    $list = $site.url

    if ($site.Quota.Storagemaximumlevel -gt0)
    {
    [int]$MaxStorage = $site.Quota.StorageMaximumLevel /1MB
    }
    else
    { $MaxStorage = “0”
    };
    $contentDbName = get-spsite -Identity $list -Limit All | select contentdatabase
    if ($site.Usage.Storage -gt0) {[int]$StorageUsed = $site.Usage.Storage /1MB};
    if ($Storageused -gt0 -and $Maxstorage -gt0){[int]$SiteQuotaUsed = $Storageused / $Maxstorage * 100} else {$SiteQuotaUsed = “0”};
    $subsite = New-Object System.Object

    $subsite | Add-Member -MemberType NoteProperty -Name “Url” -Value $site.Url
    $subsite | Add-Member -MemberType NoteProperty -Name “Web Application” -Value $Webapp.DisplayName
    $subsite | Add-Member -MemberType NoteProperty -Name “Owner Name” -Value $site.Owner.Name
    $subsite | Add-Member -MemberType NoteProperty -Name “Owner Email” -Value $site.Owner.Email
    $subsite | Add-Member -MemberType NoteProperty -Name “Last Modified” -Value $site.LastContentModifiedDate.ToShortDateString()
    $subsite | Add-Member -MemberType NoteProperty -Name “Quota Limit (MB)” -Value $MaxStorage
    $subsite | Add-Member -MemberType NoteProperty -Name “Total Storage Used (MB)” -Value $StorageUsed
    $subsite | Add-Member -MemberType NoteProperty -Name “Site Quota Percentage Used” -Value $SiteQuotaUsed
    $subsite | Add-Member -MemberType NoteProperty -Name “Content DB” -Value $site.ContentDatabase.Name
    $global:SiteCollInfo += $subsite

    Write-Host “Title :” $site.HostName
    Write-Host “Url :” $site.Url
    Write-Host “Web Application” $Webapp.DisplayName
    Write-Host “Owner Name” $site.Owner.Name
    Write-Host “Owner Email” $site.Owner.Email
    Write-Host “Last Modified” $site.LastContentModifiedDate.ToShortDateString()
    Write-Host “Quota Limit (MB)” $MaxStorage
    Write-Host “Total Storage Used (MB)” $StorageUsed
    Write-Host “Site Quota Percentage Used” $SiteQuotaUsed
    Write-Host “Content DB” $site.ContentDatabase.Name
    Write-Host
    # $web = Get-SPWeb $site.Url
    # [long]$total = 0
    # # $total += GetWebSize -Web $web
    # $val = ProcessSubWebs -Site $web
    # $total += $total +$val ;
    # $totalInMb = ($total/1024)/1024
    # $totalInMb = “{0:N2}” -f $totalInMb
    # $totalInGb = (($total/1024)/1024)/1024
    # $totalInGb = “{0:N2}” -f $totalInGb
    # write-host “Total size of all sites below” $StartWeb “is” $total “Bytes,”
    # write-host “which is” $totalInMb “MB or” $totalInGb “GB” -foregroundcolor blue
    $web.Dispose()

    }

    function ProcesWebApplication($Webapp)
    {
    Write-Host “Web Application : ” $webApp.name
    Write-Host “Application Pool : ” $webApp.ApplicationPool.Name
    # #Get all Solution in Web Application
    # Get-SPSolution | ForEach-Object {
    # if ($_.LastOperationDetails.IndexOf($webApp.url) -gt 0)
    # {
    # Write-Host ” Solutions:”
    # Write-Host ” ” $_.DisplayName
    # }
    # }

    #Get All Site Collection in a Web Application
    foreach($site in $webApp.Sites)
    {
    ProcessSiteCollection $site ;
    $site.Dispose()
    }

    }

    $global:SiteCollInfo = @()
    #Get All Web Application
    $contentWebAppServices = (Get-SPFarm).services |? {$_.typename -eq “Microsoft SharePoint Foundation Web Application”}

     

    foreach($webApp in $contentWebAppServices.WebApplications)
    {

    ProcesWebApplication -Webapp $webApp;

    }

    $global:SiteCollInfo | Export-Csv -NoTypeInformation -Path “C:\AllSiteCollectionInfo.csv”

     
  • akhileshgandhi 8:35 pm on October 29, 2012 Permalink | Reply
    Tags: AD, manager, powershell   

    Powershell get Users Manager 

    In Below code I have filtered user by employee Id you can filter by name or SAMAccount

    $ADRoot = [ADSI]”

    $EE_NO = ‘12700’
    $ADSearch = New-Object System.DirectoryServices.DirectorySearcher($ADRoot)
    $SAMAccountName = “$Username”
    $employeeid = “$Username”

    1. $ADSearch.Filter = “(&(objectClass=user)(sAMAccountName=$SAMAccountName))”

    $ADSearch.Filter = “(&(objectClass=user)(employeeid=$EE_NO))”
    $Result = $ADSearch.FindAll()

    If($Result.Count -eq 0)
    {
    Write-Host “No such user on the Server” $Username | Out-Null

    }
    Else
    {
    foreach($user in $Result)
    {
    $val = $user.path
    $account=[ADSI]$val
    $mgr = $account.PsBase.InvokeGet(“manager”)

    1. $acc = “sdcorp\” + $SAMAccountName.Trim()

    $acc = $mgr;
    }
    }

     
c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel