<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sitecore Xperiences &#187; Powershell</title>
	<atom:link href="http://blog.peplau.com.br/category/powershell/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.peplau.com.br</link>
	<description>The things I&#039;ve seen as a Sitecore Professional</description>
	<lastBuildDate>Sun, 13 Feb 2022 16:58:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.35</generator>
	<item>
		<title>Automatic Sitecore NuGet upgrades with Powershell</title>
		<link>http://blog.peplau.com.br/automatic-sitecore-nuget-upgrades-with-powershell/</link>
		<comments>http://blog.peplau.com.br/automatic-sitecore-nuget-upgrades-with-powershell/#comments</comments>
		<pubDate>Tue, 02 Nov 2021 02:05:18 +0000</pubDate>
		<dc:creator><![CDATA[Rodrigo Peplau]]></dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Upgrades]]></category>

		<guid isPermaLink="false">http://blog.peplau.com.br/?p=894</guid>
		<description><![CDATA[<div class="lr_horizontal_share" data-share-url="http://blog.peplau.com.br/automatic-sitecore-nuget-upgrades-with-powershell/"></div>One of the most tedious tasks in any Sitecore upgrade is to update your NuGet references. If your projects have so many NuGet references on packages.config, and in special with Helix solutions, updating everything manually can take you several hours. To the rescue, I&#8217;ve created this Powershell Script, which you can use to save your precious time. What [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>One of the most tedious tasks in any Sitecore upgrade is to update your NuGet references. If your projects have so many NuGet references on <em>packages.config</em>, and in special with Helix solutions, updating everything manually can take you several hours.</p>
<p>To the rescue, I&#8217;ve created this <a href="https://gist.github.com/peplau/450a72767b8a15a61db552560bc8bf9f" target="_blank">Powershell Script</a>, which you can use to save your precious time.</p>
<p>What you need to download:</p>
<ul>
<li>The <a href="https://gist.github.com/peplau/450a72767b8a15a61db552560bc8bf9f" target="_blank">Powershell Script</a> itself</li>
<li>The CSV file with all Sitecore references from <a href="http://www.stockpick.nl/english/sitecore-nuget-dependencies-in-sitecore-101/" target="_blank">this article</a> &#8211; Direct link to the <a href="http://www.stockpick.nl/1/NuGet%20Sitecore.Platform.Assemblies%2010.1.0%20rev.%20005207.csv" target="_blank">CSV file itself is here</a>.<br />
This file is valid for Sitecore 10.1 &#8211; if you need a different version, you will have to prepare and use a different CSV file (Read the article to learn more)</li>
</ul>
<p>Steps to update each project in your solution:</p>
<ul>
<li><strong>Step 1</strong> &#8211; If your upgrade requires, update your Project to the target .NET Framework</li>
<li><strong>Step 2</strong> &#8211; Get the NuGet commands to update your project.</li>
<li><strong>Step 3</strong> &#8211; Run the NuGet commands at the Package Manager Console of Visual Studio</li>
</ul>
<p>It is recommended to update the references gradually, so you can detect and fix any issue as you continue.</p>
<p>In my experience, the following sequence produced good results:</p>
<ol>
<li>If your .NET Framework has changed due to the upgrade, re-install all references not used by Sitecore by running the following command:<br />
<blockquote><p>.\Update-PackagesFile.ps1 -Csv &#8220;C:\temp\NuGet Sitecore.Platform.Assemblies 10.1.0 rev. 005207.csv&#8221; -Packages &#8220;D:\Git\myproject\packages.config&#8221; -ProjectName &#8220;MyProject&#8221; -DumpUnknownReinstall $true</p></blockquote>
</li>
<li>Update the 3rd party references to the target versions, and using this command:<br />
<blockquote><p>.\Update-PackagesFile.ps1 -Csv &#8220;C:\temp\NuGet Sitecore.Platform.Assemblies 10.1.0 rev. 005207.csv&#8221; -Packages &#8220;D:\Git\myproject\packages.config&#8221; -ProjectName &#8220;MyProject&#8221; -DumpKnownReinstall $true</p></blockquote>
</li>
<li>Sometimes 3rd party reference versions didn&#8217;t change, but you still want to force them to reinstall.  If that&#8217;s your case, use the command:<br />
<blockquote><p>.\Update-PackagesFile.ps1 -Csv &#8220;C:\temp\NuGet Sitecore.Platform.Assemblies 10.1.0 rev. 005207.csv&#8221; -Packages &#8220;D:\Git\myproject\packages.config&#8221; -ProjectName &#8220;MyProject&#8221; -DumpKnownReinstall $true</p></blockquote>
</li>
<li>Finally, uninstall and re-install your Sitecore references (useful when migrating from earlier versions into SC10):<br />
<blockquote><p>.\Update-PackagesFile.ps1 -Csv &#8220;C:\temp\NuGet Sitecore.Platform.Assemblies 10.1.0 rev. 005207.csv&#8221; -Packages &#8220;D:\Git\myproject\packages.config&#8221; -ProjectName &#8220;MyProject&#8221; -TargetSitecore &#8220;10.1&#8221; -DumpSitecoreUpdates $true</p></blockquote>
<p>or simply update them with this command:</p>
<blockquote><p>.\Update-PackagesFile.ps1 -Csv &#8220;C:\temp\NuGet Sitecore.Platform.Assemblies 10.1.0 rev. 005207.csv&#8221; -Packages &#8220;D:\Git\myproject\packages.config&#8221; -ProjectName &#8220;MyProject&#8221; -TargetSitecore &#8220;10.1&#8221; -DumpSitecoreUpdates $true -KeepSitecoreLibs $true</p></blockquote>
</li>
</ol>
<p>&nbsp;</p>
<h3>Full description of parameters:</h3>
<ul>
<li><strong>Csv</strong> (mandatory) &#8211; Path to the CSV file</li>
<li><strong>Packages</strong> (mandatory) &#8211; Path to the packages.config file</li>
<li><strong>ProjectName</strong> (mandatory) &#8211; Project Name</li>
<li><strong>TargetSitecore</strong> &#8211; Target Sitecore version</li>
<li><strong>DumpUnknownReinstall</strong> &#8211; If $true =&gt; Will dump the Update-Package with -reinstall commands for libraries not used by Sitecore</li>
<li><strong>DumpKnownUpdates</strong> &#8211; If $true =&gt; Will dump the Update-Package commands for known libraries when versions doesn&#8217;t match</li>
<li><strong>DumpKnownReinstall</strong> &#8211; If $true =&gt; Will dump the Update-Package with -reinstall when versions are the same</li>
<li><strong>DumpSitecoreUpdates</strong> &#8211; If $true =&gt; Will dump the Update-Package for Sitecore.* libraries</li>
<li><strong>KeepSitecoreLibs</strong>
<ul>
<li>If $true  =&gt; then the Sitecore entries will NOT be uninstalled (Update)</li>
<li>If $false =&gt; then the Sitecore entries will be uninstalled and re-installed (useful when migrating from earlier versions into SC10)</li>
</ul>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.peplau.com.br/automatic-sitecore-nuget-upgrades-with-powershell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Index Searching - Find-Item using custom fields with Sitecore Powershell</title>
		<link>http://blog.peplau.com.br/index-searching-find-item-using-custom-fields-with-sitecore-powershell/</link>
		<comments>http://blog.peplau.com.br/index-searching-find-item-using-custom-fields-with-sitecore-powershell/#comments</comments>
		<pubDate>Fri, 05 Jul 2019 17:21:50 +0000</pubDate>
		<dc:creator><![CDATA[Rodrigo Peplau]]></dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[SPE]]></category>

		<guid isPermaLink="false">http://blog.peplau.com.br/?p=768</guid>
		<description><![CDATA[<div class="lr_horizontal_share" data-share-url="http://blog.peplau.com.br/index-searching-find-item-using-custom-fields-with-sitecore-powershell/"></div>UPDATE: Michael West likes this solution and confirmed that it will be part of the next release of SPE (6.0), becoming my first contribution to SPE! Here is the ticket where this implementation is being tracked. If you are a big fan of Sitecore Powershell Extensions like me, you probably know the Find-Item command, which allows searching your search [&#8230;]]]></description>
				<content:encoded><![CDATA[<hr />
<p><em><strong>UPDATE:</strong> <a href="https://github.com/michaellwest" target="_blank">Michael West</a> likes this solution and confirmed that it will be part of the next release of SPE (6.0), becoming my first contribution to SPE! </em><em><a href="https://github.com/SitecorePowerShell/Console/issues/1120" target="_blank">Here is the ticket</a> where this implementation is being tracked.</em></p>
<hr />
<p>If you are a big fan of <a href="https://marketplace.sitecore.net/Modules/Sitecore_PowerShell_console.aspx" target="_blank">Sitecore Powershell Extensions</a> like me, you probably know the <a href="https://doc.sitecorepowershell.com/appendix/indexing/find-item" target="_blank">Find-Item</a> command, which allows searching your search index in Powershell scripts. This command, however, has an important limitation: you cannot use custom fields to filter and sort from the index. Due to this limitation, extended usage of <em>Find-Item</em> with custom code is usually not possible.</p>
<p>Internally <em>Find-Item</em> uses the base class &#8220;<em>Sitecore.ContentSearch.SearchTypes.SearchResultItem</em>&#8220;, which does not include any custom fields. What we usually do with C# is to create a class that inherits from &#8220;<em>SearchResultItem</em>&#8220;, adding our custom fields, such as below:</p>
<pre>public class CustomSearchResultItem : SearchResultItem
{
   [IndexField("_templates")]
   [DataMember]
   public virtual List&lt;ID&gt; TemplateIds { get; set; }
}</pre>
<p>The <em>Find-Item</em> command, however, does not allow using this field. For instance, the following script:</p>
<pre>$props = @{
 Index = "sitecore_master_index"
 Where = "Paths.Contains(@0) And TemplateIds.Contains(@1)"
 WhereValues = [ID]::Parse("{D5B8857B-DE30-4616-84F5-812A7129ACD5}"), [ID]::Parse("{50FFE147-4F48-428B-A417-4D96DD2048FF}")
}
Find-Item @props</pre>
<p>Will give the following error:</p>
<pre>Find-Item : No property or field 'TemplateIds' exists in type 'SearchResultItem'</pre>
<p>Because, yeah&#8230; that property is only defined at our custom class, not at <em>SearchResultItem</em>. To circumvent this limitation I built this special command.</p>
<h2>Find-CustomItem</h2>
<p>This command extends the original <em>Find-Item</em>, allowing you to pass a type that will be used instead of the base <em>SearchResultItem</em> class:</p>
<pre>$props = @{
 Index = "sitecore_master_index"
<strong> Type = [PSWebsite.Foundation.Indexing.SearchTypes.BaseSearchResultItem]</strong>
 Where = "Paths.Contains(@0) And TemplateIds.Contains(@1)"
 WhereValues = [ID]::Parse("{D5B8857B-DE30-4616-84F5-812A7129ACD5}"), [ID]::Parse("{50FFE147-4F48-428B-A417-4D96DD2048FF}")
}
Find-CustomItem @props</pre>
<h2>Create the custom command</h2>
<p>In order to use <em>Find-CustomItem</em> in your project, you should:</p>
<ol>
<li>Add NuGet references to <em>Sitecore.ContextSearch</em> and <em>Sitecore.ContextSearch.Linq</em>;</li>
<li>Add a reference to <em>Cognifide.Powershell.dll</em>;</li>
<li>Create a custom <em>FindItemCommand</em> class extending <em>Cognifide.PowerShell.Commandlets.Data.Search.FindItemCommand</em>;<br />
You can <a href="https://github.com/peplau/PSWebsite/blob/master/src/Foundation/Indexing/code/Powershell/Commandlets/FindItemCommand.cs" target="_blank">download the whole class here</a></li>
<li>Register your new command with an include patch &#8211; make sure the content is according to the following</li>
</ol>
<pre>&lt;?xml version="1.0"?&gt;
&lt;configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"&gt;
   &lt;sitecore&gt;
      &lt;powershell&gt;
         &lt;commandlets&gt;
            &lt;add Name="Find Item" type="PSWebsite.Foundation.Indexing.Powershell.Commandlets.FindItemCommand, PSWebsite.Foundation.Indexing" /&gt;
         &lt;/commandlets&gt;
      &lt;/powershell&gt;
   &lt;/sitecore&gt;
&lt;/configuration&gt;</pre>
<h2>Limitations</h2>
<p>Not all parameters from <em>Find-Item</em> are supported by <em>Find-CustomItem</em>. If you use any of the unsupported parameters along with any custom properties, it will cast the query to the base <em>SearchResultItem</em>, and give the same error as the original <em>Find-Item</em> command.</p>
<p><strong>Supported parameters:</strong></p>
<ul>
<li>Index</li>
<li>Where</li>
<li>WhereValues</li>
<li>OrderBy</li>
<li>First</li>
<li>Last</li>
<li>Skip</li>
</ul>
<p><strong>Unsupported parameters:</strong></p>
<ul>
<li>Criteria</li>
<li>Predicate</li>
<li>ScopeQuery</li>
</ul>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.peplau.com.br/index-searching-find-item-using-custom-fields-with-sitecore-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Powershell script to find TDS files with length error</title>
		<link>http://blog.peplau.com.br/powershell-script-to-find-tds-files-with-length-error/</link>
		<comments>http://blog.peplau.com.br/powershell-script-to-find-tds-files-with-length-error/#comments</comments>
		<pubDate>Mon, 17 Dec 2018 12:49:00 +0000</pubDate>
		<dc:creator><![CDATA[Rodrigo Peplau]]></dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[TDS]]></category>

		<guid isPermaLink="false">http://blog.peplau.com.br/?p=739</guid>
		<description><![CDATA[<div class="lr_horizontal_share" data-share-url="http://blog.peplau.com.br/powershell-script-to-find-tds-files-with-length-error/"></div>A very well described problem with TDS is the File Name length error. This article from Hedgehog brings everything you need to know about the issue itself, and how to work it out. The solution is to use the &#8220;Alias&#8221; TDS feature to cut down the file path length. For instance, if you have an item with a very long [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>A very well described problem with TDS is the File Name length error. <a href="https://www.teamdevelopmentforsitecore.com/Blog/file-length-error-tds" target="_blank">This article</a> from Hedgehog brings everything you need to know about the issue itself, and how to work it out. The solution is to use the &#8220;Alias&#8221; TDS feature to cut down the file path length.</p>
<p>For instance, if you have an item with a very long name such as &#8220;Subpage with Left Rail Without Footer&#8221;, you could choose an Alias as &#8220;sub3&#8243; and save 33 characters. Of course, your original item name is preserved, as this only applies to the file system.</p>
<p>In short:</p>
<ul>
<li>File path should not exceed 260 chars</li>
<li>Folder path should not exceed 248 chars</li>
</ul>
<h2 id="TDSpathlengthissuesolving-Whatcausesandwhattodoabout">What causes and what to do about</h2>
<ol>
<li>You have cloned the repository into a folder with a too large name<br />
<strong>What to do about: </strong></p>
<ol>
<li>Make sure you have something short like:<br />
C:\src\ABC<br />
instead of<br />
C:\Source Control\My Client Name Is Long\My Long Project Name</li>
</ol>
</li>
<li>TDS project name is too wide &#8211; due to the Helix standard TDS projects can have longer names (Eg: <em>MyProject.Foundation.DependencyInjection.Master</em>)<br />
<strong>What to do about:</strong></p>
<ol>
<li>New projects: avoid long names (Eg: DI instead of DependencyInjection)</li>
<li>Existent projects:
<ol>
<li>Use the Powershell script to find long paths and apply Aliases</li>
<li>Be proactive to apply Aliases to TDS long names</li>
</ol>
</li>
</ol>
</li>
<li>The Sitecore Item Path added to TDS (including the item itself) is too long<br />
<strong>What to do about:</strong></p>
<ol>
<li>Use the Powershell script to identify long paths, then apply a TDS Alias to each item that makes it longer</li>
<li>EG: this path<br />
/sitecore/content/mywebsite/This page has a big name/But this page also has a big name/NotToBlame<br />
has 2 problematic items:</p>
<ol>
<li>&#8220;This page has a big name&#8221;</li>
<li>&#8220;But this page also has a big name&#8221;</li>
</ol>
</li>
<li>Those 2 items must be added to TDS and have their &#8220;File System Alias&#8221; setup to something smaller</li>
</ol>
</li>
</ol>
<h2 id="TDSpathlengthissuesolving-Powershellscript">Powershell script</h2>
<p>When a certain environment has this issue, make sure to follow the steps described earlier. However, to execute Step 3 you should first discover what items are problematic.</p>
<p>To quickly obtain such a list, use the following Powershell script:</p>
<blockquote><p># Script Setup<br />
$pathToScan = &#8220;D:\src\ABC&#8221;;<br />
$outputToCsv = $false;<br />
$outputToPrompt = $true;<br />
$maxLength = 225;<br />
#########</p>
<p>cls;</p>
<p>if ($pathToScan.IndexOf(&#8220;\src&#8221;) -eq -1){<br />
$pathToScan = &#8220;$pathToScan\src&#8221;;<br />
}</p>
<p># Get all TDS folders<br />
$tdsFolders = Get-ChildItem -Path $pathToScan -File -Recurse | Where-Object {($_.FullName -like &#8216;*.Master*&#8217;) -or ($_.FullName -like &#8216;*.Core*&#8217;)} | Where-Object {($_.FullName -notlike &#8216;*\bin\*&#8217;)};<br />
#$tdsFolders = Get-ChildItem -Path $pathToScan -Directory -Recurse;</p>
<p># Add properties<br />
foreach ($folder in $tdsFolders){<br />
$folder | Add-Member PathLength $folder.FullName.Length;<br />
}</p>
<p># Sort<br />
$tdsFoldersSorted = $tdsFolders | sort FullName | sort PathLength -Descending;</p>
<p># Get Max Length to filter those that will not match<br />
#$maxLength = Read-Host -Prompt &#8216;Max Length allowed';<br />
$tdsFoldersToShow = $tdsFoldersSorted | Where-Object {$_.PathLength -gt $maxLength};</p>
<p># Output Loop<br />
$fileName = &#8220;$PSScriptRoot\beyond $maxLength.csv&#8221;;<br />
$csvText = &#8220;&#8221;;<br />
if ($outputToCsv){<br />
$csvText = &#8220;$($csvText)Length,FullName`n&#8221;;<br />
#Add-Content -Path $fileName -Value &#8220;Length,FullName&#8221;;<br />
}<br />
if ($outputToPrompt){<br />
Write-Output(&#8220;Length,FullName&#8221;);<br />
}</p>
<p>foreach ($folder in $tdsFoldersToShow){<br />
if ($outputToCsv){<br />
$csvText = &#8220;$($csvText)$($folder.PathLength),$($folder.FullName)`n&#8221;;<br />
#Add-Content -Path $fileName -Value &#8220;$($folder.PathLength),$($folder.FullName)&#8221;;<br />
}<br />
if ($outputToPrompt){<br />
Write-Output(&#8220;$($folder.PathLength),$($folder.FullName)&#8221;);<br />
}<br />
}</p>
<p>if ($outputToCsv){<br />
Add-Content -Path $fileName -Value $csvText;<br />
Write-Output(&#8220;File $fileName saved&#8221;);<br />
}</p></blockquote>
<h3 id="TDSpathlengthissuesolving-Instructions">Instructions</h3>
<ol>
<li>Open the script in Powershell ISE as Administrator</li>
<li>Setup script changing variables at the top:
<ol>
<li><strong>$pathToScan</strong> &#8211; should point to your git folder</li>
<li><strong>$outputToCsv</strong> &#8211; Set as $true if you want the script to create a CSV file with results, $false otherwise</li>
<li><strong>$outputToPrompt</strong> &#8211; Set as $true if you want the script to display results at prompt, $false otherwise</li>
<li><strong>$maxLength</strong> &#8211; Max length tolerated to a TDS item path &#8211; the script will list everything that goes beyond this vale</li>
</ol>
</li>
<li>Run the script</li>
<li>Use the list obtained to apply instructions Aliases, making paths shorter</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://blog.peplau.com.br/powershell-script-to-find-tds-files-with-length-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
