Skip to content

Commit

Permalink
lagt til 'Get-Date'
Browse files Browse the repository at this point in the history
  • Loading branch information
orjan-berg committed Mar 14, 2023
1 parent 5409a09 commit 4adc508
Show file tree
Hide file tree
Showing 11 changed files with 467 additions and 13 deletions.
2 changes: 1 addition & 1 deletion content/posts/GetDate.md
Original file line number Diff line number Diff line change
@@ -1,7 1,7 @@
---
title: "Get-Date"
date: 2023-03-14T12:05:14 01:00
draft: true
draft: false
toc: false
images:
tags:
Expand Down
15 changes: 14 additions & 1 deletion docs/index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 7,20 @@
<generator>Hugo -- gohugo.io</generator>
<language>en-us</language>
<copyright>&lt;a href=&#34;https://creativecommons.org/licenses/by-nc/4.0/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;CC BY-NC 4.0&lt;/a&gt;</copyright>
<lastBuildDate>Fri, 03 Feb 2023 15:24:39 0100</lastBuildDate><atom:link href="https://orjan-berg.github.io/index.xml" rel="self" type="application/rss xml" />
<lastBuildDate>Tue, 14 Mar 2023 12:05:14 0100</lastBuildDate><atom:link href="https://orjan-berg.github.io/index.xml" rel="self" type="application/rss xml" />
<item>
<title>Get-Date</title>
<link>https://orjan-berg.github.io/posts/getdate/</link>
<pubDate>Tue, 14 Mar 2023 12:05:14 0100</pubDate>

<guid>https://orjan-berg.github.io/posts/getdate/</guid>
<description>Ofte har man behov for å filtrere data, slik som jeg når jeg skulle finne records i en sql tabell som var endret etter en gitt dato.
Jeg liker å bruke Powershell og spesielt modulen dbatools. Dette ble derfor mine foretrukne verktøy til å løse denne oppgaven.
Har Powershell en cmdlet for å arbeide med datoer?
For å finne ut av dette benyttet jeg Get-Command -CommandType -Name *date*
Powershell kom med en rekke forslag,</description>
</item>

<item>
<title>Kryptert passord</title>
<link>https://orjan-berg.github.io/posts/encryptedcredentials/</link>
Expand Down
7 changes: 7 additions & 0 deletions docs/posts/encryptedcredentials/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 335,13 @@ <h3 id="lage-et-kryptert-passord">Lage et kryptert passord</h3>

<div class="pagination__buttons">

<span class="button previous">
<a href="https://orjan-berg.github.io/posts/getdate/">
<span class="button__icon"></span>
<span class="button__text">Get-Date</span>
</a>
</span>



<span class="button next">
Expand Down
367 changes: 367 additions & 0 deletions docs/posts/getdate/index.html

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions docs/posts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 126,17 @@ <h1>Posts</h1>

<ul class="posts-list">

<li class="post-item">
<a href="https://orjan-berg.github.io/posts/getdate/">
<span class="post-title">Get-Date</span>
<span class="post-day">

Mar 14

</span>
</a>
</li>

<li class="post-item">
<a href="https://orjan-berg.github.io/posts/encryptedcredentials/">
<span class="post-title">Kryptert passord</span>
Expand Down
31 changes: 30 additions & 1 deletion docs/posts/index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 6,38 @@
<generator>Hugo -- gohugo.io</generator>
<language>en-us</language>
<copyright>&lt;a href=&#34;https://creativecommons.org/licenses/by-nc/4.0/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;CC BY-NC 4.0&lt;/a&gt;</copyright>
<lastBuildDate>Fri, 03 Feb 2023 15:24:39 0100</lastBuildDate>
<lastBuildDate>Tue, 14 Mar 2023 12:05:14 0100</lastBuildDate>
<atom:link href="https://orjan-berg.github.io/posts/index.xml" rel="self" type="application/rss xml" />

<item>
<title>Get-Date</title>
<link>https://orjan-berg.github.io/posts/getdate/</link>
<pubDate>Tue, 14 Mar 2023 12:05:14 0100</pubDate>

<guid>https://orjan-berg.github.io/posts/getdate/</guid>
<description>Ofte har man behov for å filtrere data, slik som jeg når jeg skulle finne records i en sql tabell som var endret etter en gitt dato.
Jeg liker å bruke Powershell og spesielt modulen dbatools. Dette ble derfor mine foretrukne verktøy til å løse denne oppgaven.
Har Powershell en cmdlet for å arbeide med datoer?
For å finne ut av dette benyttet jeg Get-Command -CommandType -Name *date*
Powershell kom med en rekke forslag,</description>
<content type="html"><![CDATA[<p>Ofte har man behov for å filtrere data, slik som jeg når jeg skulle finne records i en sql tabell som var endret etter en gitt dato.</p>
<p>Jeg liker å bruke Powershell og spesielt modulen dbatools. Dette ble derfor mine foretrukne verktøy til å løse denne oppgaven.</p>
<p>Har Powershell en cmdlet for å arbeide med datoer?</p>
<p>For å finne ut av dette benyttet jeg <code>Get-Command -CommandType -Name *date*</code></p>
<p>Powershell kom med en rekke forslag,</p>
<p><img src="docs/images/GetDate01.png" alt="Example image"></p>
<p>Av disse så fant jeg at <code>Get-Date</code> kunne gjøre det jeg var ute etter.</p>
<p><code>Get-Date</code> har properties for å angi Day, Month og Year. Disse brukte jeg for å angi datoen jeg ville ha.</p>
<p><code>$chdt = Get-Date -Year 2022 -Month 11 -Day 17</code> etter å ha satt variabelen $chdt slik jeg ville, var det på tide å hente fram dbtools.</p>
<p>Dbtools har funksjonen <code>Invoke-DbaQuery</code>.</p>
<p><code>invoke-DbaQuery -SqlInstance srv-prod-sql01 -Database VDC_SystemDB -query 'select * from VWUser'</code> henter ut alle records i tabellen VWUser. Jeg er ikke ute etter alle felter. Jeg piper derfor resultatet til <code>Select-Object</code>, på denne måten <code>Select-Object -Property UserId, Username, LastUpdate</code>.</p>
<p>Nå har jeg de feltene jeg trenger, men fortsatt har jeg alt for mange records. Jeg piper derfor resultatet videre til <code>Where-Object</code>. <code>Where-Object {$_.LastUpdate.Date -ge $chdt}</code></p>
<p>Helt til slutt vil jeg ha resultatet lagret i en csv fil. Det gjør jeg ved å pipe resultatet til <code>Export-Csv</code>.</p>
<p>Den fulle onelineren blir derfor</p>
<pre tabindex="0"><code>invoke-DbaQuery -SqlInstance srv-prod-sql01 -Database VDC_SystemDB -query &#39;select * from VWUser&#39; | Select-Object -Property UserId, Username, LastUpdate | Where-Object {$_.LastUpdate.Date -ge $chdt} | Export-Csv F:\Exsitec_Temp\VDC_brukere.csv -NoTypeInformation
</code></pre>]]></content>
</item>

<item>
<title>Kryptert passord</title>
<link>https://orjan-berg.github.io/posts/encryptedcredentials/</link>
Expand Down
15 changes: 9 additions & 6 deletions docs/sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 2,22 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>https://orjan-berg.github.io/</loc>
<lastmod>2023-02-03T15:24:39 01:00</lastmod>
<loc>https://orjan-berg.github.io/posts/getdate/</loc>
<lastmod>2023-03-14T12:05:14 01:00</lastmod>
</url><url>
<loc>https://orjan-berg.github.io/posts/encryptedcredentials/</loc>
<lastmod>2023-02-03T15:24:39 01:00</lastmod>
<loc>https://orjan-berg.github.io/</loc>
<lastmod>2023-03-14T12:05:14 01:00</lastmod>
</url><url>
<loc>https://orjan-berg.github.io/posts/</loc>
<lastmod>2023-02-03T15:24:39 01:00</lastmod>
<lastmod>2023-03-14T12:05:14 01:00</lastmod>
</url><url>
<loc>https://orjan-berg.github.io/tags/powershell/</loc>
<lastmod>2023-02-03T15:24:39 01:00</lastmod>
<lastmod>2023-03-14T12:05:14 01:00</lastmod>
</url><url>
<loc>https://orjan-berg.github.io/tags/</loc>
<lastmod>2023-03-14T12:05:14 01:00</lastmod>
</url><url>
<loc>https://orjan-berg.github.io/posts/encryptedcredentials/</loc>
<lastmod>2023-02-03T15:24:39 01:00</lastmod>
</url><url>
<loc>https://orjan-berg.github.io/tags/dbatools/</loc>
Expand Down
2 changes: 1 addition & 1 deletion docs/tags/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 131,7 @@ <h1>Tags</h1>
<span class="post-title">powershell</span>
<span class="post-day">

Feb 3
Mar 14

</span>
</a>
Expand Down
4 changes: 2 additions & 2 deletions docs/tags/index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 7,11 @@
<generator>Hugo -- gohugo.io</generator>
<language>en-us</language>
<copyright>&lt;a href=&#34;https://creativecommons.org/licenses/by-nc/4.0/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;CC BY-NC 4.0&lt;/a&gt;</copyright>
<lastBuildDate>Fri, 03 Feb 2023 15:24:39 0100</lastBuildDate><atom:link href="https://orjan-berg.github.io/tags/index.xml" rel="self" type="application/rss xml" />
<lastBuildDate>Tue, 14 Mar 2023 12:05:14 0100</lastBuildDate><atom:link href="https://orjan-berg.github.io/tags/index.xml" rel="self" type="application/rss xml" />
<item>
<title>powershell</title>
<link>https://orjan-berg.github.io/tags/powershell/</link>
<pubDate>Fri, 03 Feb 2023 15:24:39 0100</pubDate>
<pubDate>Tue, 14 Mar 2023 12:05:14 0100</pubDate>

<guid>https://orjan-berg.github.io/tags/powershell/</guid>
<description></description>
Expand Down
11 changes: 11 additions & 0 deletions docs/tags/powershell/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 126,17 @@ <h1>powershell</h1>

<ul class="posts-list">

<li class="post-item">
<a href="https://orjan-berg.github.io/posts/getdate/">
<span class="post-title">Get-Date</span>
<span class="post-day">

Mar 14

</span>
</a>
</li>

<li class="post-item">
<a href="https://orjan-berg.github.io/posts/encryptedcredentials/">
<span class="post-title">Kryptert passord</span>
Expand Down
15 changes: 14 additions & 1 deletion docs/tags/powershell/index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 7,20 @@
<generator>Hugo -- gohugo.io</generator>
<language>en-us</language>
<copyright>&lt;a href=&#34;https://creativecommons.org/licenses/by-nc/4.0/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;CC BY-NC 4.0&lt;/a&gt;</copyright>
<lastBuildDate>Fri, 03 Feb 2023 15:24:39 0100</lastBuildDate><atom:link href="https://orjan-berg.github.io/tags/powershell/index.xml" rel="self" type="application/rss xml" />
<lastBuildDate>Tue, 14 Mar 2023 12:05:14 0100</lastBuildDate><atom:link href="https://orjan-berg.github.io/tags/powershell/index.xml" rel="self" type="application/rss xml" />
<item>
<title>Get-Date</title>
<link>https://orjan-berg.github.io/posts/getdate/</link>
<pubDate>Tue, 14 Mar 2023 12:05:14 0100</pubDate>

<guid>https://orjan-berg.github.io/posts/getdate/</guid>
<description>Ofte har man behov for å filtrere data, slik som jeg når jeg skulle finne records i en sql tabell som var endret etter en gitt dato.
Jeg liker å bruke Powershell og spesielt modulen dbatools. Dette ble derfor mine foretrukne verktøy til å løse denne oppgaven.
Har Powershell en cmdlet for å arbeide med datoer?
For å finne ut av dette benyttet jeg Get-Command -CommandType -Name *date*
Powershell kom med en rekke forslag,</description>
</item>

<item>
<title>Kryptert passord</title>
<link>https://orjan-berg.github.io/posts/encryptedcredentials/</link>
Expand Down

0 comments on commit 4adc508

Please sign in to comment.