Wednesday, April 25, 2018

How to use CAML Query in PowerShell to excute any operation

If you want to delete (or any operation) multiple Items from a list based on certain condition then you can refer below PowerShell command where we can use CAML query to get exact items which we need to delete. Most of the time I found that the developers write PowerShell command which get all the items then Check the condition and delete the items. If you have large number items in list then it will get much time to execute.

Add-PSSnapin Microsoft.SharePoint.Powershell -ea SilentlyContinue
$web = get-spweb "[Site URL]"
$list = $web.lists["List Name"]
$ValueToCompare = "[Value To Compare]"
$FieldToCompare = "[Field Name To Compare]"
$query = New-Object Microsoft.SharePoint.SPQuery
$query.ViewAttributes = "Scope='Recursive'"
$query.RowLimit = 1000
$caml='<Where> <Eq> <FieldRef Name="'+$FieldToCompare+'" /><Value Type="Text">'+$ValueToCompare+'</Value> </Eq> </Where>'
Write-Host $caml
$query.Query = $caml
$query.ViewFields = "<FieldRef Name='ID'/>"
$query.ViewFieldsOnly = $true
do
{
  $listItems = $list.GetItems($query)
  $query.ListItemCollectionPosition = $listItems.ListItemCollectionPosition
  foreach($item in $listItems)
  {
    Write-Host "Deleting Item - $($item.Id)"
    $list.GetItemById($item.Id).delete()
  }
}
while ($query.ListItemCollectionPosition -ne $null)  


Sunday, April 15, 2018

How to copy text from image - The One Note Way

In my opinion One Note is one of the Powerful tool comes in Office package but we rarely use those features. Here is one example of that.

In my last project I was working on an auditing software where client asks us to refer another Android app which was in Dutch language. There were many text so I was feeling pretty lazy to type all the text and implement it in our new app. To overcome this problem, I had taken the following steps:


  1. Take a screenshot of the old app from your mobile.
  2. Copy the screenshot in the desktop.
  3. Open the Microsoft One Note.
  4. Click on Insert from top menu. Then click on picture.  
  1. Then right click on the picture and select “Copy text from Picture”
  1. Then right click on a blank area and paste it.
  1. Finally, you will get only text from it. Rarely I found any error in this process.