Wednesday, April 20, 2016

Pipeline

What is Pipeline in Sitecore?
A pipeline is a discrete set of steps, executed in order. It is an architectural design you can employ for certain cases in your applications. If we have a series of tasks which need to be performed to accomplish a task, then a pipeline may be the way to go. A pipeline will execute the steps in order, so we could use a pipeline for our ordered tasks as well as our unordered tasks (as the order doesn’t matter we don’t care that it was executed in order).
Pipelines define a sequence of processors that implement a function, such as defining the Sitecore context for an HTTP request or generating a list of messages in the Content Editor.
Whenever the HTTP request comes to server  how sitecore handles the request is depicted in the below diagram .


So in the above image we can see that every single request to sitecore it straight goes to Pipeline. Then the pipeline will determine that which are the steps need to be execute in order . Pipeline also determine whether the request is match with standard MVC route or not . If the request match with MVC route then go for MVC application else Sitecore will try to resolve particular item's layout. Lastly we can see in the image that is there any layout define for the particular item , If yes then layout will will check for MVC extension settings or not . If it match mvc extension then indeed a MVC request comes from HTTP request else it is a web form request .

What is the Purpose of Pipeline ?
From above discussion we can see the importance of pipeline in Sitecore application . In a one word I would like to say that Pipelines are used to control most of Sitecore's functionality. For e.g. processes ranging from authentication to request handling to publishing to indexing etc all are controlled through the pipeline in Sitecore.
Generally Pipelines are defined in the Web.config and in the Sitecore Patch files . Sitecore separates the pipelines in to two groups . In the web.config we can see . 
  • <pipelines> 
    
    Those defined under this tend to use system processes .

  • <processors
    In this node used to define the pipelines that operate for UI requests and can be interact with users .
Some commonly used pipelines are given below. These are unlikely you will ever call any of them directly but it is not unusual to extend these below pipelines .
Pipeline NameGenerally Defined inArgs typeSmall Description
 <initialize>
Web.configPipelineArgsWhenever the IIS application pool is started this will run . Processors handles initalization of task that need to run once
<httpRequestBegin>
Web.configHttpRequestArgsThis handles Httprequest , including task such as resolving the context item , device , presentation settings etc.
<insertRenderings>
Web.configInsertRenderingsArgs Determines the presentation components to include when rendering an item .
 
<renderField>
Web.configRenderFieldArgsRuns when the FieldRenderer is used to render a Field value .

If you are not bale to find any of the above mentioned Pipeline name in the Web.config file , then please have a look under Sitecore.config file , may be there has been defined.

How to create Own Pipeline ?
I would like to say instead of modifying any of the sitecore defined pipeline , it will be better to create a new custom pipeline for any of our business requirement . In this post I will create new pipeline for dummy purpose . I would like to create a custom button . While click on this my custom pipeline will going to define the steps to validate that the user input value from the prompt is the current year. For e.g. Current year is 2016 , so while button click one pop-up will ask the user "What is the Current year?" , If the user input value is match with current year then will say Thank You, else will show a message  with wrong value and ask to try once again.
Now I  have open the sitecore website in browser . Login the site with admin credentials . I go to desktop mode . First change my database from master to core , because it contains the definition for the Sitecore User interface. I need to create a custom button to show in sitecore ribbon .
Step 1 : In the content Editor , just go to Applications–>  Content Editor–> Ribbons–> Chunks–> Sorting–> Right click in Sorting select insert option (Insert from Template)
Choose the template System/Ribbon/Large Button , name the Item Test Button. Then hit Insert.
Step 2: Insert the following values to the fields . Header = "Test Button" , Icon ="Applications/32x32/desktop.png", Click="testbutton:click" , Tooltip ="Run a custom UI pipeline.'

Step 3: I have move the Test Button at the last child of the Sorting Item.
Step 4: Now click on save and come out from core database to master and see the button is showing in the ribbon .
Step 5: Now it is time to write down little code in Visual Studio. Lets open Visual Studio Solution , I have set up my solutions with sitecore website , so that after complete developing the custom pipeline if I publish then it should work. We shall write code for this test button , so that while click on it user can enter the value (Current Year)
I have create a Class in VS Solution in the name of TestCommand , this class will derived from Sitecore.Shell.Framework.Commands.Command .Through this class Execute method we shall start our custom pipeline.
namespace WebApplication.Custom_Command
{
    public class TestCommand : Command
    {
        public override void Execute(CommandContext context)
        {
            //
            //parameters provide a way to pass values to the pipeline
            NameValueCollection parameters = new NameValueCollection();
            parameters["year"] = DateTime.Now.Year.ToString();
 
            //custom args class provides another way to pass values to the pipeline
            TestArgs args = new TestArgs(context.Items[0], parameters);
            Sitecore.Context.ClientPage.Start("testPipeline", args);
        }
    }
}
Step 6: Now I shall create a that will handles to pass the values to pipeline processors . I have mark the class as serializable. Other than that the code allows a sitecore item to be store as a property. Below is the code .
namespace WebApplication.CustomPipeline
{
    [Serializable]
    public class TestArgs : ClientPipelineArgs
    {
        public TestArgs(Item item)
            : base()
        {
            this.m_Item = item;
        }
 
        public TestArgs(Item item, NameValueCollection parameters)
            : base(parameters)
        {
            this.m_Item = item;
        }
 
        public TestArgs(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            m_ItemId = info.GetString("itemid");
            m_DatabaseName = info.GetString("databasename");
        }
 
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("itemid", m_ItemId);
            info.AddValue("databasename", m_DatabaseName);
            base.GetObjectData(info, context);
        }
 
        private string m_ItemId = null;
        private string m_DatabaseName = null;
 
        private Item m_Item = null;
 
        public Item Item
        {
            get
            {
                if (m_Item == null)
                {
                    if (!string.IsNullOrEmpty(m_ItemId) && !string.IsNullOrEmpty(m_DatabaseName))
                    {
                        Database database = Factory.GetDatabase(m_DatabaseName);
                        if (database != null)
                        {
                            m_Item = database.GetItem(new ID(m_ItemId));
                        }
                    }
                }
                return m_Item;
            }
        }
    }
}

Step 7: Now we shall create a custom processors . I have said in the top of this post that a Pipeline is a set of processors that will run in specific order . A processor is just like a method . A processors class can have multiple methods but for simplicity I have create only one method in this class.
namespace WebApplication.CustomPipeline
{
    public class TestProcessor
    {
        public void ConfirmYear(TestArgs args)
        {
            if (args.IsPostBack)
            {
                //args.Result will be "null" if the cancel button is clicked
                if (String.IsNullOrEmpty(args.Result) || (args.Result == null) || (args.Result == "null") || args.Result == "undefined")
                {
                    args.AbortPipeline();
                    SheerResponse.ClosePopups(false);
                    return;
                }
               
                //if the user didn't enter the correct year, prompt again
                if (args.Result != args.Parameters["year"])
                {
                    SheerResponse.Input("Is the current year is '" + args.Result + "'?, please try again", args.Result);
                    args.AddMessage("Worng Year");
                    args.WaitForPostBack();
                    return;
                }
                SheerResponse.Alert("Thanks You"true);
            }
            else
            {
                //prompt the user for the year
                SheerResponse.Input("What year is it?""");
                args.WaitForPostBack();
            }
        }
    }
}
Step 8: Last step we need to define our custom pipeline in config file in sitecore website. Before that I would concise up to now what I have done . I just create a custom button in ribbon, then call the click command, this will open a pop up that allows user to enter the current year value. If the value is matched with current year will show thank you message else throw warning message to user. So , lets define our custom pipeline in the config file so that our test button functionality could be started  .
We shall create a config file under ..\App_config\Include\ folder , since the namespace I have used WebApplication , so I will create a config file in the name of WebApplication.Config. The following XML is added in this file .
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <processors>
      <testPipeline>
        <processor type="WebApplication.CustomPipeline.TestProcessor, WebApplication" method="ConfirmYear" />
      </testPipeline>
    </processors>
    <commands>
      <command name="testbutton:click" type="WebApplication.Custom_Command.TestCommand, WebApplication"/>
    </commands>
  </sitecore>
</configuration>
 
Step 9: Now  build the solution in Visual Studio and hit publish . It is the time for testing our custom pipeline processor. So I have login in our Sitecore website , go to the content editor and click in the test button . This will show a prompt like below image

Now I have enter a value for e.g. abcd , obviously the current year is not abcd, so this should throw a warning message to user and let them to try once again. below is the Image.

Now I have enter a correct current year which 2016 at this time , and see the thank you message .

So , I have create my custom pipeline that will confirm the current year value with user input value , hope this simple excersice cab able to clear the concept of sitecore pipelines basics, for more details can be found over John West blog and Sitecore documents , please comment below if anything have you seen in this post wrong or need to modify , Thanks for your time to read my post.

http://www.sitecore.net/learn/blogs/technical-blogs/morten-ljungberg-sitecore-whats-new/posts/2015/08/adding-a-custom-button-to-the-ribbon.aspx



Friday, April 15, 2016

Sitecore Rocks Query Analyzer

Hi All,
       Today we try to cover basics of Sitecore Rocks Query Analyzer. It is the top most features of Sitecore Rocks.
Query analyzer have the sheer power.
Let's start by opening the Query Analyzer.  Right click on a database, navigate under the Tools menu and select "Query Analyzer" from the menu.

If you've never worked with the Query Analyzer before, the best way to get familiar with what's available is to start with the help commands.  Simply enter "help" for the query and execute.  This will return the list of commands available at our disposal.

Sitecore Rocks

We can dive deeper in the commands help by appending a command to the help query.  For example, if you enter "help select" and execute this query you will see all the options and syntax for the select command.
Now that we have a basic idea what commands are available let's execute some queries and see the results.

Sitecore Select Query Samples:

Simple Select statement

select * from /sitecore/content/Home

Select child items

select * from /sitecore/*

Select descendents

select * from /sitecore//*

Select descendents with filter

select * from /sitecore//*[@Title = "Welcome to Sitecore"]

Select columns

select @Title, @Text from /sitecore/content/Home

Select columns with aliases

select @Title as Caption, @Text as Body from /sitecore/content/Home

Select expression

select @Title + ", " + @Text as Value from /sitecore/content/Home

Select item ID

select @@ID from /sitecore/content/Home

Select item name

select @@Name from /sitecore/content/Home

Select item path

select @@Path from /sitecore/content/Home

Select item template

select @@TemplateID, @@TemplateName, @@TemplateKey from /sitecore/content/Home

Select with space escaping

If a field contains a space, the field name can be escaped using hashes #.

select @#Body Text# from /sitecore/content/Home

Select using Distinct

select distinct @Title from /sitecore/content/*

Select using Order By

Notice that the result set is order by column names, not field names.

select @@Name as Name from /sitecore/content//* order by Name

Select using Order By descendent

Notice that the result set is order by column names, not field names.

select @@Name as Name from /sitecore/content//* order by Name desc

Select using Distinct and Order By

select distinct Name as Name from /sitecore/content//* order by Name

Sitecore Query Delete Samples

Delete an item

delete from /sitecore/content/Home

Delete children

delete from /sitecore/content/*

Delete descendents with a specific template

delete from /sitecore/content//*[@@templatename = 'News']

Delete items created by a specific user

delete from //*[@#__Created By# = 'sitecore\admin' or @#__Updated By# = 'sitecore\admin']

Delete items that were updated recently

delete from /sitecore/content//*[@__Updated > '20111231T235959']

Scary

delete from /*

Sitecore Query Update Samples

Update single field

update set @Text = "Welcome to Sitecore" from /sitecore/content/Home

Update multiple fields

update set @Title = "Sitecore", @Text = "Hello" from /sitecore/content/Home

Update multiple fields in multiple items

update set @Title = "Sitecore", @Text = "Hello" from /sitecore/content/*[@@TemplateName = "Sample Item"]

Reset Updated fields to Created fields

update set @#__Updated By# = @#__Created By#, @__Updated = @__Created, from /sitecore/content/Home

Expressions

update set @Text = "Title: " + @Title from /sitecore/content/Home

Complex Query:

update set @testdroplink ="{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}" from /sitecore/content/Home//*[@testdroplink = ""]

This query update the testdroplink field from all the descendant child's under the home node which has blank testdroplink field value.

I hope this blog help you to understand the Sitecore Rocks Query Analyzer.

Thanks
Arun Sharma

Thursday, April 14, 2016

Schedule a daily backup with SQL Server(ssms)

As you know MS SQL Server Express Edition hasn’t Agent Service, which can be used to schedule daily backups or other periodic administrative tasks. But you can use for this standard Windows Schedule tool.
SQL Server Express Edition has some limitation, but anyway it is very powerful tool for storing data. For most little or middle projects you can use it without any restrictions. But Express edition has a little problem, it hasn’t SQL Server Agent. But you can use SQLCMD command line tool and standard Scheduled Tasks for Windows instead of it. If you want to set automating administrative periodic task first of all you need to write a sql script. We want to solve problem: write a script which will do a daily backup. Of course you can use MS Management Studio for generating current script (as you know you can download Management Studio Express Edition too from Microsoft site): just click “Script Actions to…” instead of OK button at “Back Up Database” dialog box and you will get a script.
For daily backups I usually use this script:
DECLARE @pathName NVARCHAR(512) 
SET @pathName = 'E:\Backups\DatabaseBackup\Ulm\StadtUlmSitecore_Master_' + Convert(varchar(8), GETDATE(), 112) + '.bak' 
BACKUP DATABASE [StadtUlmSitecore_Master] TO  DISK = @pathName WITH NOFORMAT, NOINIT,  NAME = N'StadtUlmSitecore_Master', SKIP, NOREWIND, NOUNLOAD,  STATS = 10

This script makes a backup file with name db_backup_YYYYDDMM.bak where YYYYDDMM – it is current date. This format will give you an opportunity to have every day backup at separate files. Correct this script and try to run it, check that you will get a backup file (I set “d:\backup” folder for files, change it if you want). Next step – save this script to file schedule.sql and put it to “c:\scheduled tasks\” (you can choose any other names for script file and folders, just make sure that you will change it at all places where it will be used). At this folder create a file backup.bat with next contain:
sqlcmd -S INB032\SQLEXPRESS -U sa -P Simple@123 -i StadtUlmSitecore_MasterBackup.sql
7z a -tzip E:\Backups\DatabaseBackup\Ulm\StadtUlmSitecore_Master_%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%.zip E:\Backups\DatabaseBackup\Ulm\StadtUlmSitecore_Master_*.bak
del E:\Backups\DatabaseBackup\Ulm\StadtUlmSitecore_Master_*.bak
Where: SERVERNAME – database instance name (server name), UserName – sql user, which has a privileges for making backups, Password – password of this user, schedule.sql – name of script with we created on previous step. Second and third lines of this bat script do an archive of this backup file and then delete backup file. I use 7z (http://www.7-zip.org/) utility for this, if you want you can use any other archive tool, or maybe leave backup file unzipped (MS SQL Server 2008 and higher has an opportunity to backup database with compression, so you can just set it in sql script). If you will use 7z like me you need to set full path to 7z.exe tool or you can just copy 7z.exe and 7z.dll files from installed folder of 7z tool to folder where will be located this bat script. And make sure that if you used other folder names or file names at previous steps you will change these names at this bat script too. You can try to run this bat script and check that backup file will be created and zipped.
Last step is to create schedule task. In each Windows versions it can be different way to create this task. This is how to create schedule task for Windows XP -http://support.microsoft.com/kb/308569, this is link how to for Windows 7 -http://windows.microsoft.com/en-US/windows7/schedule-a-task. For other versions I think you can find a how-to at Windows helps or other blog posts.
When you will create this Windows task you should check that user by whom these tasks will be launched has rights to create files at folders, where script will put backups, and this user has right to execute bat file.
Like this you can run not only daily backup. You can execute some procedures, re-index tables or maybe some other administrative stuff – just place what you want at schedule.sql script.

Wednesday, April 13, 2016

Sitecore Powershell

Sitecore Poweshell is great tool for maximize the productivity of developers.The Sitecore PowerShell Extensions module (SPE) provides a robust environment for automating tasks within Sitecore.

How do I retrieve my Sitecore items the PowerShell way?

The most natural way to retrieve Sitecore items is with use of Get-Item and Get-ChildItem commandlets. That is because those 2 commandlets add a PowerShell wrapping around them that allows the functionalities that I’m going to describe in the next section of this blog after I’ll tell you all about retrieving items.

1.Getting Items based on path

Example: The following will retrieve the item based on the Sitecore path.
PS master:\> Get-Item -Path master:\content\home

Name Children Languages                Id                                     TemplateName
---- -------- ---------                --                                     ------------
Home True     {en, de-DE, es-ES, pt... {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} Sample Item
As you may have noticed, the /sitecore portion of the path is unnecessary. This is because the Sitecore item is represented by the root item of the drive master: and is therefore optional.
The above will return the latest version of the item in your current language. But what if you want the item in another language? No problem!
Example: The following will retrieve the Danish version of the Home item.
PS master:\> Get-Item -Path master:/content/home -Language da | Format-Table DisplayName, Language, Id, Version, TemplateName

DisplayName Language ID                                     Version TemplateName
----------- -------- --                                     ------- ------------
Hjem        da       {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1       Sample Item
I've formatted the output above to show you that indeed the right language was returned. 
The command supports wildcards for both -Language and -Version parameters. 
You may have also noticed that the forward and backward slashes can be used interchangeably.
 
Example: The following retrieves the latest version for all languages of an item.
PS master:\> Get-Item master:/content/home -Language * | Format-Table DisplayName, Language, Id, Version, TemplateName

DisplayName Language ID                                     Version TemplateName
----------- -------- --                                     ------- ------------
Home        en       {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1       Sample Item
Home        de-DE    {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1       Sample Item
Home        pl-PL    {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1       Sample Item
Home        en-US    {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 3       Sample Item
Home        en-GB    {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1       Sample Item
Hjem        da       {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1       Sample Item
Notice that the item with language en-US at its third version.
 
Example: The following retrieves the item in all languages and versions.
PS master:\> Get-Item master:/content/home -Language * -Version *| Format-Table DisplayName, Language, Id, Version, TemplateName

DisplayName Language ID                                     Version TemplateName
----------- -------- --                                     ------- ------------
Home        en       {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1       Sample Item
Home        de-DE    {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1       Sample Item
Home        pl-PL    {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1       Sample Item
Home        en-US    {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1       Sample Item
Home        en-US    {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 2       Sample Item
Home        en-US    {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 3       Sample Item
Home        en-GB    {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1       Sample Item
Hjem        da       {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1       Sample Item
You can see that specifying the language and version using the wildcard will retrieve all possible variants of an item. The wildcard can also include a partial match like en-*. The use of that filter would return all items in the English language, ignoring the region.
Example: The following retrieves the child items in all languages and versions.
PS master:\> Get-ChildItem master:/content -Language * -Version * | Format-Table DisplayName, Language, Id, Version, TemplateName

DisplayName         Language ID                                     Version TemplateName
-----------         -------- --                                     ------- ------------
Home                en       {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1       Sample Item
Home                de-DE    {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1       Sample Item
Home                pl-PL    {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1       Sample Item
Home                en-US    {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1       Sample Item
Home                en-US    {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 2       Sample Item
Home                en-US    {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 3       Sample Item
Home                en-GB    {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1       Sample Item
Hjem                da       {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1       Sample Item
CognifideCom        en       {6A1EC18E-AF9B-443E-84C7-5528F2363A10} 1       TenantTemplate
Demo                en       {4F02AEDF-1CC6-4B84-8B6E-F5CB465F8AD9} 1       TenantTemplate
GetEngaged          en       {68AD4037-EE50-4615-BA2E-AE11B1D3F6CC} 1       TenantTemplate
GetEngaged          de-DE    {68AD4037-EE50-4615-BA2E-AE11B1D3F6CC} 1       TenantTemplate
GetEngaged          es-ES    {68AD4037-EE50-4615-BA2E-AE11B1D3F6CC} 1       TenantTemplate
GetEngaged          pt-BR    {68AD4037-EE50-4615-BA2E-AE11B1D3F6CC} 1       TenantTemplate
GetEngaged          pl-PL    {68AD4037-EE50-4615-BA2E-AE11B1D3F6CC} 1       TenantTemplate
  

Getting items by Path with Sitecore query

t's not always most efficient to operate on items by traversing the tree using Get-ChildItem. This is especially true if you need to work on large trees but need to select only a few items (e.g. a specific template). For this we’ve introduced support for the Sitecore query within our provider. 
Example: The following retrieves all items beneath the path /sitecore/content/ with the template of Sample Item.
PS master:\> Get-Item -Path master: -Query "/sitecore/content//*[@@templatename='Sample Item']"

Name                             Children Languages                Id                                     TemplateName
----                             -------- ---------                --                                     ------------
Copy of Home                     True     {en, de-DE, es-ES, pt... {503713E5-F9EE-4847-AEAF-DD13FD853004} Sample Item
Home                             True     {en, de-DE, es-ES, pt... {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} Sample Item
Example: The following retrieves all items beneath the path /sitecore/content/ with the template of Sample Item in all versions and languages.
PS master:\> Get-Item -Path master: -Query "/sitecore/content//*[@@templatename='Sample Item']"
 -Language * -Version * | Format-Table DisplayName, Language, Id, Version, TemplateName -AutoSize

DisplayName  Language ID                                     Version TemplateName
-----------  -------- --                                     ------- ------------
Copy of Home en       {503713E5-F9EE-4847-AEAF-DD13FD853004} 1       Sample Item
Home         de-DE    {503713E5-F9EE-4847-AEAF-DD13FD853004} 1       Sample Item
Copy of Home pl-PL    {503713E5-F9EE-4847-AEAF-DD13FD853004} 1       Sample Item
Copy of Home en-US    {503713E5-F9EE-4847-AEAF-DD13FD853004} 1       Sample Item
Hjem         da       {503713E5-F9EE-4847-AEAF-DD13FD853004} 1       Sample Item
Home         en       {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1       Sample Item
Home         de-DE    {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1       Sample Item
Home         pl-PL    {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1       Sample Item
Home         en-US    {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1       Sample Item
Home         en-US    {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 2       Sample Item
Home         en-US    {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 3       Sample Item
Home         en-GB    {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1       Sample Item
Hjem         da       {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} 1       Sample Item

Get items by Id

Example: The following retrieves an item by id.
PS master:\> Get-Item -Path master: -ID "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}"

Name  Children Languages                Id                                     TemplateName
----  -------- ---------                --                                     ------------
Home  True     {en, de-DE, es-ES, pt... {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} Sample Item

Get items by Uri

The Uri encodes the language and version within the path.
Example: The following retrieves an item by uri.
PS master:\> Get-Item -Path master: -Uri "sitecore://master/{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}?lang=en&ver=1"

Name Children Languages                Id                                     TemplateName
---- -------- ---------                --                                     ------------
Home True     {en, de-DE, es-ES, pt... {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} Sample Item
In all the examples you'll notice we specified the database. Windows PowerShell needs to know which provider to execute within. This also signals to SPE to show the dynamic parameters. 
      

Changing item properties

We often see the following two ways of accessing and changing fields used in scripts. One uses Set-ItemProperty and the other is more natural to a Sitecore developer.
Example: The following sets the title property using Set-ItemProperty.
PS master:\> Set-ItemProperty -Path master:/content/home -Name "Title" -Value "New Title"
Example: The following sets the title property using .Editing.BeginEdit and .Editing.EndEdit methods.
$item = Get-Item master:/content/home
$item.Editing.BeginEdit()
$item["Title"] = "New Title"
$item.Editing.EndEdit()
Note: The above example may also be written in the ISE where no console prompt is visible.
The previous examples work but are not the most efficient ways to change item content. The items returned by the provider expose the Sitecore item fields as automated PowerShell properties.
Example: The following sets the title property using the automated PowerShell property.
$item = Get-Item master:/content/home
$item.Title = "New Title"
Example: The following sets the title property using the semi-native PowerShell property without the use of a variable.
(Get-Item master:/content/home).Title = "New Title"

Some other useful Examples that might help you to dig more into sitecore powershell:
EXAMPLE:-
$item=Get-Item -Path master: -Query "/sitecore/content/Home[@Related To Division = '']"
$item.Editing.BeginEdit()
$item["Related To Division"] ="{A43E680A-F5BD-4CC0-A4A0-AF5A53163447}"
$item.Editing.EndEdit()
Above example is useful for checking the field value for particular location. In above example we are also able to use
$item.Fieldname or $item.Title but if we have space in field then it is not work we need to use like:$item["Related To Division"]
EXAMPLE:-
$items=Get-Item -Path master: -Query "/sitecore/content//*[@Related To Division = ""]"
$items.Editing.BeginEdit()
foreach ($item in $items)
{
$item["Related To Division"] ="{A43E680A-F5BD-4CC0-A4A0-AF5A53163447}"
}
$items.Editing.EndEdit()
Above example is useful for checking the field value for all child's below the specified node.

I hope these examples help you for understanding the Sitecore PowerShell & you can dig more for enhance your knowledge but never miss to share your knowledge with us.
Other useful Links:
http://blog.najmanowicz.com/2014/10/12/working-with-sitecore-items-in-powershell-extensions/
https://sitecorepowershell.gitbooks.io/sitecore-powershell-extensions/content/item-languages.html
https://sitecorepowershell.gitbooks.io/sitecore-powershell-extensions/content/working-with-items.html
http://coreblimey.azurewebsites.net/sitecore-and-powershell-feel-like-he-man/
http://blog.najmanowicz.com/sitecore-powershell-console/
https://sitecorejunkie.com/2014/06/02/make-bulk-item-updates-using-sitecore-powershell-extensions/

Thanks
Arun Sharma