<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>PowerShell on Ash Tewari</title><link>https://www.tewari.info/tag/powershell/</link><description>Recent content in PowerShell on Ash Tewari</description><generator>Hugo -- gohugo.io</generator><language>en-US</language><lastBuildDate>Sun, 25 Apr 2021 19:40:55 +0000</lastBuildDate><atom:link href="https://www.tewari.info/tag/powershell/feed.xml" rel="self" type="application/rss+xml"/><item><title>Kusto Queries on AKS Clusters</title><link>https://www.tewari.info/2021/04/25/kusto-queries-on-aks-clusters/</link><pubDate>Sun, 25 Apr 2021 19:40:55 +0000</pubDate><guid>https://www.tewari.info/2021/04/25/kusto-queries-on-aks-clusters/</guid><description>&lt;p&gt;&lt;a class="link" href="https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/" target="_blank" rel="noopener"&#10; &gt;Kusto&lt;/a&gt; query language can be used to get &lt;a class="link" href="https://docs.microsoft.com/en-us/azure/azure-monitor/containers/container-insights-log-search" target="_blank" rel="noopener"&#10; &gt;insights&lt;/a&gt; into Azure Kubernetes Service (&lt;a class="link" href="https://azure.microsoft.com/en-us/services/kubernetes-service/" target="_blank" rel="noopener"&#10; &gt;AKS&lt;/a&gt;) clusters. &lt;a class="link" href="https://docs.microsoft.com/en-us/azure/azure-monitor/containers/container-insights-overview" target="_blank" rel="noopener"&#10; &gt;Container insights&lt;/a&gt; collects data from AKS clusters and forwards it to &lt;a class="link" href="https://docs.microsoft.com/en-us/azure/azure-monitor/logs/log-analytics-tutorial" target="_blank" rel="noopener"&#10; &gt;Log Analytics&lt;/a&gt; workspace, if enabled for a cluster. This data is available for querying in the &lt;a class="link" href="https://docs.microsoft.com/en-us/azure/azure-monitor/logs/data-platform-logs" target="_blank" rel="noopener"&#10; &gt;Azure Monitor&lt;/a&gt;. Here is an example of how you can query the pods not in running state in specific namespaces.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;KubePodInventory&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;| where Namespace in (&amp;#34;dv&amp;#34;,&amp;#34;test&amp;#34;,&amp;#34;prod&amp;#34;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;| where ContainerStatus != &amp;#34;Running&amp;#34;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;| where ContainerStatusReason !in (&amp;#34;&amp;#34;, &amp;#34;Completed&amp;#34;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;| distinct Namespace, Name&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-7.png"&#10;&#9;&#9;&#9;alt="Log Analytics query results listing pods not in running state by namespace"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;p&gt;The following query includes the name of the AKS cluster and renders the output as a stacked bar chart.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;KubePodInventory&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;| where Namespace in (&amp;#34;dv&amp;#34;,&amp;#34;test&amp;#34;,&amp;#34;prod&amp;#34;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;| where ContainerStatus != &amp;#34;Running&amp;#34;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;| where ContainerStatusReason !in (&amp;#34;&amp;#34;, &amp;#34;Completed&amp;#34;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;| distinct ClusterName, Namespace, Name&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;| summarize dcount(Name) by ClusterName, Namespace&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;| render columnchart kind=stacked100&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-8-1024x582.png"&#10;&#9;&#9;&#9;alt="Stacked column chart of non-running pods by AKS cluster and namespace"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;p&gt;You can include multiple AKS clusters in the scope in which this query is executed by clicking on [Select scope] hyperlink.&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-12.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-15.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;p&gt;Create an Azure Dashboard panel with this output by clicking on [Pin to dashboard] button.&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-13.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-11-1024x676.png"&#10;&#9;&#9;&#9;alt="Azure dashboard showing the pinned AKS pod status chart"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;p&gt;You can also execute this Kusto query directly using powershell.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$workspaceName = &amp;#34;DefaultWorkspace-6637b095-xxxx-xxxx-xxxx-xxxxxxxxxxx-EUS&amp;#34;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$workspaceRG = &amp;#34;defaultresourcegroup-eus&amp;#34;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$WorkspaceID = (Get-AzOperationalInsightsWorkspace -Name $workspaceName -ResourceGroupName $workspaceRG).CustomerID&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$query = &amp;#39;KubePodInventory | where Namespace in (&amp;#34;dv&amp;#34;,&amp;#34;test&amp;#34;,&amp;#34;prod&amp;#34;) | where ContainerStatus != &amp;#34;Running&amp;#34; | where ContainerStatusReason !in (&amp;#34;&amp;#34;, &amp;#34;Completed&amp;#34;) | distinct ClusterName, Namespace, Name | summarize dcount(Name) by ClusterName, Namespace&amp;#39;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$result = Invoke-AzOperationalInsightsQuery -WorkspaceId $WorkspaceID -Query $query -Timespan (New-TimeSpan -days 1)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$result.results&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This allows you to include the results of your custom Kusto queries in any reports you might run using Azure Automation Runbooks.&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-14-1024x392.png"&#10;&#9;&#9;&#9;alt="PowerShell session running the Kusto query with Invoke-AzOperationalInsightsQuery"&gt;&#10;&lt;/figure&gt;&#10;&#10;</description></item><item><title>AKS Supported Kubernetes Versions</title><link>https://www.tewari.info/2020/11/08/aks-supported-kubernetes-versions/</link><pubDate>Mon, 09 Nov 2020 03:08:17 +0000</pubDate><guid>https://www.tewari.info/2020/11/08/aks-supported-kubernetes-versions/</guid><description>&lt;p&gt;&lt;a class="link" href="https://docs.microsoft.com/en-us/azure/aks/" target="_blank" rel="noopener"&#10; &gt;Azure Kubernetes Service&lt;/a&gt; (AKS) &lt;a class="link" href="https://docs.microsoft.com/en-us/azure/aks/supported-kubernetes-versions" target="_blank" rel="noopener"&#10; &gt;supports specific versions&lt;/a&gt; of &lt;a class="link" href="https://kubernetes.io/" target="_blank" rel="noopener"&#10; &gt;Kubernetes&lt;/a&gt;.&lt;br&gt;&#10;It is necessary to regularly monitor the release of new versions and upgrade your AKS clusters to supported versions in order to remain in compliance with &lt;a class="link" href="https://docs.microsoft.com/en-us/azure/aks/supported-kubernetes-versions#kubernetes-version-support-policy" target="_blank" rel="noopener"&#10; &gt;AKS Kubernetes Version Support Policy&lt;/a&gt;.&lt;/p&gt;&#10;&lt;p&gt;&lt;a class="link" href="https://docs.microsoft.com/en-us/azure/aks/supported-kubernetes-versions#release-and-deprecation-process" target="_blank" rel="noopener"&#10; &gt;AKS announces&lt;/a&gt; the planned date of a new minor version release and corresponding old version deprecation via AKS &lt;a class="link" href="https://github.com/Azure/AKS/releases" target="_blank" rel="noopener"&#10; &gt;Release notes&lt;/a&gt; at least 30 days prior to removal. An email notification is sent to the subscription administrators with the planned version removal dates. You get 30 days from version removal to upgrade to a supported minor version release. Patch versions can be released anytime and you get 30 days from the removal date to upgrade to a supported patch version.&lt;/p&gt;&#10;&lt;p&gt;You should test new target Kubernetes versions and upgrade your AKS clusters in a timely manner. For that, it is necessary to proactively monitor the AKS release notes. This can easily become a chore in a large Enterprise environment. Here is a Powershell script to make it easier to stay on top of Kubernetes version releases in AKS and publish/share it with others: &lt;a class="link" href="https://gist.github.com/ashtewari/31ce67d89b1878db52ca7558dbb3e194" target="_blank" rel="noopener"&#10; &gt;Get-AksSupportedVersions&lt;/a&gt;.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$aksVersionsJson = az aks get-versions --location eastus&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$aksVersions = $aksVersionsJson | ConvertFrom-Json&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$aksVersions.orchestrators.upgrades.orchestratorVersion&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$data = $aksVersions.orchestrators | Select-Object `&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -Property @{Name=&amp;#34;Version&amp;#34;;Expression={$_.orchestratorVersion}} `&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; , @{Name=&amp;#34;Default&amp;#34;;Expression={$_.default}} `&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; , @{Name=&amp;#34;Preview&amp;#34;;Expression={$_.isPreview}} `&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; , @{Name=&amp;#34;Upgrades&amp;#34;;Expression={$_.upgrades.orchestratorVersion -join &amp;#34;, &amp;#34;}}&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$versionTable = $data | ConvertTo-Html -Fragment&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$versionTableString = $versionTable | Out-String&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$html = New-Object -ComObject &amp;#34;HTMLFile&amp;#34;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$html.IHTMLDocument2_write($versionTableString)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$tables = $html.body.getElementsByTagName(&amp;#34;table&amp;#34;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$rptString = &amp;#34;&amp;#34;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ForEach($table in $tables){&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ForEach($row in $table.rows){&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; $cellCount = 0&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ForEach($cell in $row.cells){&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; $cellCount++&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; if(($cellCount -eq 2) -and ($cell.innertext -eq &amp;#39;True&amp;#39;))&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; {&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; $row.className = &amp;#34;OkStatus&amp;#34;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; if(($cellCount -eq 3) -and ($cell.innertext -eq &amp;#39;True&amp;#39;))&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; {&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; $row.className = &amp;#34;WarningStatus&amp;#34;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; $rptString += $table.outerHTML&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$reportDate = $(get-date -DisplayHint DateTime) | Out-String&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$fileTS = $(get-date -Format &amp;#34;yyyyMMdd&amp;#34;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$fileName = &amp;#34;aks-versions-$fileTS.html&amp;#34;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$rptTitle = &amp;#34;&amp;lt;h1&amp;gt;AKS Kubernetes Versions&amp;lt;/h1&amp;gt;&amp;lt;p&amp;gt;$reportDate&amp;lt;/p&amp;gt;&amp;#34;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$report = ConvertTo-Html -Title &amp;#34;AKS Versions&amp;#34; -Body &amp;#34;$rptTitle $rptString&amp;#34; -Head $header&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$report | Out-File &amp;#34;$fileName&amp;#34;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;It creates an HTML report of currently supported Kubernetes versions in AKS along with their respective upgrade paths. Here is an example of the report generated by the script referenced above :&lt;/p&gt;&#10;&lt;h1 id="aks-kubernetes-versions"&gt;AKS Kubernetes Versions&#10;&lt;/h1&gt;&lt;p&gt;Sunday, November 8, 2020 8:47:42 PM&lt;/p&gt;&#10;&lt;table&gt;&#10;&#9;&lt;thead&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;th&gt;Version&lt;/th&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;th&gt;Default&lt;/th&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;th&gt;Preview&lt;/th&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;th&gt;Upgrades&lt;/th&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&lt;/thead&gt;&#10;&#9;&lt;tbody&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;1.16.13&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;1.16.15, 1.17.9, 1.17.11&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;1.16.15&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;1.17.9, 1.17.11&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;1.17.9&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;1.17.11, 1.18.6, 1.18.8&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;1.17.11&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;True&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;1.18.6, 1.18.8&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;1.18.6&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;1.18.8, 1.19.0&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;1.18.8&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;1.19.0&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;1.19.0&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;True&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&lt;/tbody&gt;&#10;&lt;/table&gt;&#10;&lt;p&gt;Reference: &lt;a class="link" href="https://adamtheautomator.com/powershell-convertto-html/" target="_blank" rel="noopener"&#10; &gt;How To Create An HTML Report With PowerShell&lt;/a&gt;&lt;/p&gt;&#10;</description></item><item><title>Using Powershell with Splunk</title><link>https://www.tewari.info/2016/02/22/using-powershell-with-splunk/</link><pubDate>Tue, 23 Feb 2016 03:20:14 +0000</pubDate><guid>https://www.tewari.info/2016/02/22/using-powershell-with-splunk/</guid><description>&lt;p&gt;&lt;a class="link" href="http://dev.splunk.com/view/splunk-powershell-resource-kit/SP-CAAADRU" title="Splunk Powershell Resource Kit"&#10; target="_blank" rel="noopener"&#10; &gt;Splunk Powershell Resource Kit&lt;/a&gt; is a convenient and very capable wrapper over &lt;a class="link" href="http://www.splunk.com/" target="_blank" rel="noopener"&#10; &gt;Splunk&lt;/a&gt; &lt;a class="link" href="http://dev.splunk.com/restapi" target="_blank" rel="noopener"&#10; &gt;REST API&lt;/a&gt;. You can use the &lt;a class="link" href="https://msdn.microsoft.com/en-us/powershell" target="_blank" rel="noopener"&#10; &gt;Powershell&lt;/a&gt; commandlets exposed by this resource kit to deploy, check and manage splunk services as well as execute splunk searches. In this post, you will be introduced to the Splunk Powershell Resource Kit, you will learn how to use powershell commandlets to connect to a splunk instance and execute searches.&lt;/p&gt;&#10;&lt;p&gt;1. First, you will need to download the resource kit from &lt;a class="link" href="https://github.com/splunk/splunk-reskit-powershell" target="_blank" rel="noopener"&#10; &gt;github&lt;/a&gt;.&#10;2. Installation is very simple. All you have to do is download and extract the files from the zip archive and double click on install.bat to install the splunk powershell module.&#10;3. Open Windows Powershell console from Windows Start menu.&#10;4. Verify that the Splunk module is installed by executing Get-Module commandlet.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Get-Module SplunkSearch&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;5. Import splunk resource kit commandlets using Import-Module command.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Import-Module -Name Splunk&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;6. Next, you need to use Get-Credentials and then Connect-Splunk commandlets to connect to splunk. You need to do this once per session or if you need to switch to a different splunk instance.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$credential = Get-Credential&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Connect-Splunk -Credential $credential -ComputerName localhost&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I have a local Splunk Enterprise instance running on my machine, so I am using localhost as the ComputerName to connect to it. If you have a SplunkCloud subscription you can use YourSubscriptionId.splunkcloud.com as the ComputerName to connect to your subscription. Like so -&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Connect-Splunk -Credential $credential -ComputerName MySubscription.splunkcloud.com&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;7. Next, use Search-Splunk commandlet to execute searches -&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Search-Splunk -Search &amp;#34;Error&amp;#34;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here is a sample script:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$lastDay = ( get-date ).addDays( -1 ).toString( ‘s’ )&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$searches = @(&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &amp;#34;ERROR&amp;#34;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; , &amp;#34;source=&amp;#34;&amp;#34;tutorialdata.zip:*&amp;#34;&amp;#34; ERROR&amp;#34;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; , &amp;#34;CreditDoesNotMatch&amp;#34;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ,&amp;#34;source=&amp;#34;&amp;#34;tutorialdata.zip:.\\www3/access.log&amp;#34;&amp;#34; productId=WC-SH-G04&amp;#34;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Write-Output $lastDay&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;foreach($search in $searches)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;{&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; $qry = $search + &amp;#34; | stats count&amp;#34;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Write-Output $qry&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Search-Splunk -Search $qry -StartTime $lastDay | Select-Object -ExpandProperty Count&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The sample script executes multiple Splunk searches and outputs the count of results matching these search queries. Note that I am &amp;ldquo;-StartTime&amp;rdquo; parameter to scope the search to a narrower time window and &amp;ldquo;stats count&amp;rdquo; command to get the count of results. You can get this sample script as a &lt;a class="link" href="https://gist.github.com/ashtewari/c29a8ac98587d42c91bd" target="_blank" rel="noopener"&#10; &gt;github gist&lt;/a&gt;.&lt;/p&gt;&#10;&lt;p&gt;You can also use -EndTime and –MaxReturnCount to further constrain the query results and Format-List, Format-Table, Format-Wide commands to format the results. You can learn more about other Search parameters as well as other capabilities exposed in the resource kit &lt;a class="link" href="https://github.com/splunk/splunk-reskit-powershell/raw/master/Docs/Splunk%20PowerShell%20Resource%20Kit.docx" target="_blank" rel="noopener"&#10; &gt;documentation&lt;/a&gt;.&lt;/p&gt;&#10;&lt;p&gt;Resources :&lt;/p&gt;&#10;&lt;ol&gt;&#10;&lt;li&gt;&lt;a class="link" href="http://dev.splunk.com/view/splunk-powershell-resource-kit/SP-CAAADRU" target="_blank" rel="noopener"&#10; &gt;Splunk Powershell ResourceKit&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a class="link" href="https://github.com/splunk/splunk-reskit-powershell" target="_blank" rel="noopener"&#10; &gt;Splunk Powershell ResourceKit on github&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a class="link" href="https://github.com/splunk/splunk-reskit-powershell/raw/master/Docs/Splunk%20PowerShell%20Resource%20Kit.docx" target="_blank" rel="noopener"&#10; &gt;Splunk Powershell ResourceKit Documentation&lt;/a&gt;&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;p&gt;Image credit : &lt;a class="link" href="https://thenounproject.com/search/?q=shell&amp;amp;i=209178" target="_blank" rel="noopener"&#10; &gt;terminal by Andrea Mazzini&lt;/a&gt; from the Noun Project&lt;/p&gt;&#10;</description></item><item><title>Code Validation in TortoiseSVN pre_commit_hook</title><link>https://www.tewari.info/2010/03/31/code-validation-in-tortoisesvn-pre_commit_hook/</link><pubDate>Thu, 01 Apr 2010 04:32:10 +0000</pubDate><guid>https://www.tewari.info/2010/03/31/code-validation-in-tortoisesvn-pre_commit_hook/</guid><description>&lt;p&gt;If you want to abort a commit if your code fails certain rule and you don&amp;rsquo;t have access to the &lt;a class="link" href="http://subversion.tigris.org/" title="svn"&#10; target="_blank" rel="noopener"&#10; &gt;SVN&lt;/a&gt; Server to configure a hook. What do you do ?&lt;/p&gt;&#10;&lt;p&gt;Assuming you are using &lt;a class="link" href="http://tortoisesvn.tigris.org/" title="tortoisesvn"&#10; target="_blank" rel="noopener"&#10; &gt;TortoiseSVN&lt;/a&gt;, you can configure a &lt;a class="link" href="http://tortoisesvn.tigris.org/tsvn_1.5_releasenotes.html#client-side-hooks" title="tortoisesvn-client-side-hook"&#10; target="_blank" rel="noopener"&#10; &gt;Client-Side hook&lt;/a&gt;.&lt;/p&gt;&#10;&lt;p&gt;Here is an example - Say you want to abort commit if you have a comment in your code that starts with &lt;strong&gt;//Do Not Commit&lt;/strong&gt;. You can create a &lt;a class="link" href="http://en.wikipedia.org/wiki/Windows_PowerShell" title="wikipedia-powershell"&#10; target="_blank" rel="noopener"&#10; &gt;PowerShell&lt;/a&gt; script that validates all the files in your changeset and use this script as a Client-Side pre_commit_hook in TortoiseSVN.&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/TortoiseSVN-Settings-HookScripts.png"&#10;&#9;&#9;&#9;alt="TortoiseSVN-Settings-HookScripts"&gt;&lt;figcaption&gt;&#10;&#9;&#9;&#9;&lt;p&gt;TortoiseSVN-Settings-HookScripts&lt;/p&gt;&#10;&#9;&#9;&lt;/figcaption&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;p&gt;The pre_commit_hook configuration :&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/Configure-Hook-Scripts.png"&#10;&#9;&#9;&#9;alt="Configure-Hook-Scripts"&gt;&lt;figcaption&gt;&#10;&#9;&#9;&#9;&lt;p&gt;Configure-Hook-Scripts&lt;/p&gt;&#10;&#9;&#9;&lt;/figcaption&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;p&gt;//Powershell script : pre_commit.ps1&lt;/p&gt;&#10;&lt;p&gt;$donotcommit = &amp;ldquo;//Do Not Commit&amp;rdquo;;&lt;/p&gt;&#10;&lt;p&gt;$changeset = Get-Content$args[0];&lt;/p&gt;&#10;&lt;p&gt;foreach($file in $changeset)&#10;{&#10;if( Get-Content$file | Select-String$donotcommit-quiet )&#10;{&#10;Write-Error &amp;ldquo;$file contains code that you are not supposed to commit. [$donotcommit]&amp;rdquo;;&#10;exit9;&#10;}&#10;}&lt;/p&gt;&#10;&lt;p&gt;Now, if your changeset has a file with a comment starting with &lt;strong&gt;//Do Not Commit&lt;/strong&gt; and you click on OK to commit this change, the commit will be aborted with this error message -&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/pre_commit_hook-validation1.png"&#10;&#9;&#9;&#9;alt="pre_commit_hook-validation"&gt;&lt;figcaption&gt;&#10;&#9;&#9;&#9;&lt;p&gt;pre_commit_hook-validation&lt;/p&gt;&#10;&#9;&#9;&lt;/figcaption&gt;&#10;&lt;/figure&gt;&#10;&#10;</description></item></channel></rss>