<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://entorb.net//wiki/index.php?action=history&amp;feed=atom&amp;title=PowerShell</id>
	<title>PowerShell - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://entorb.net//wiki/index.php?action=history&amp;feed=atom&amp;title=PowerShell"/>
	<link rel="alternate" type="text/html" href="https://entorb.net//wiki/index.php?title=PowerShell&amp;action=history"/>
	<updated>2026-05-06T11:29:52Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>https://entorb.net//wiki/index.php?title=PowerShell&amp;diff=4936&amp;oldid=prev</id>
		<title>Torben at 20:57, 30 October 2024</title>
		<link rel="alternate" type="text/html" href="https://entorb.net//wiki/index.php?title=PowerShell&amp;diff=4936&amp;oldid=prev"/>
		<updated>2024-10-30T20:57:27Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Category:Coding]][[Category:Windows]]&lt;br /&gt;
===run===&lt;br /&gt;
single command&lt;br /&gt;
 powershell -c &amp;quot;$lastmonth = (Get-Date).addMonths(-3); $lastmonth.tostring(\&amp;quot;yyyy-MM\&amp;quot;)&amp;quot;&lt;br /&gt;
script file&lt;br /&gt;
 powershell -executionpolicy bypass -File ./del-old-dirs.ps1&lt;br /&gt;
&lt;br /&gt;
===echo/print===&lt;br /&gt;
 Write-Host &amp;quot;Hello World&amp;quot;&lt;br /&gt;
 pause&lt;br /&gt;
&lt;br /&gt;
===date===&lt;br /&gt;
get current date e.g. YYYY-MM&lt;br /&gt;
 powershell -c &amp;quot;$lastmonth = (Get-Date).addMonths(-3); $lastmonth.tostring(\&amp;quot;yyyy-MM\&amp;quot;)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===strings===&lt;br /&gt;
get substring of string &lt;br /&gt;
 $var = &amp;#039;Hello World&amp;#039;&lt;br /&gt;
 $result = $var.substring(0, 5)&lt;br /&gt;
 $result-&amp;gt; Hello&lt;br /&gt;
merge stings&lt;br /&gt;
 $dest = $rootPath + &amp;quot;\&amp;quot; +$subFolder&lt;br /&gt;
&lt;br /&gt;
===filesystem access===&lt;br /&gt;
check a dir exists&lt;br /&gt;
 if (Test-Path $dest) { ... }&lt;br /&gt;
del / delete file&lt;br /&gt;
 Remove-Item -Path &amp;quot;C:\dir\file.txt&amp;quot; &lt;br /&gt;
mkdir / create dirctory&lt;br /&gt;
 New-Item -ItemType directory -Path C:\newDir&lt;br /&gt;
&lt;br /&gt;
====select old files from directory====&lt;br /&gt;
 $limit = (Get-Date).AddDays(-90)&lt;br /&gt;
 $scope = Get-ChildItem -Path $dir -Force | Where-Object { $_.PSIsContainer -and $_.CreationTime -lt $limit }&lt;br /&gt;
 #&lt;br /&gt;
 # Filters:&lt;br /&gt;
 # -Filter &amp;quot;*.dfq&amp;quot;&lt;br /&gt;
 # Where&lt;br /&gt;
 # $_.PSIsContainer  =&amp;gt; dirs&lt;br /&gt;
 # !$_.PSIsContainer =&amp;gt; files&lt;br /&gt;
 # &lt;br /&gt;
 # write scope to CSV file&lt;br /&gt;
 $scope | Select-Object FullName, CreationTime | Export-Csv -Path .\$logfile -NoTypeInformation &lt;br /&gt;
 # -Append &lt;br /&gt;
 # delete files in scope&lt;br /&gt;
 $scope | Remove-Item -Force&lt;br /&gt;
&lt;br /&gt;
====delete old files====&lt;br /&gt;
delete old files (from [https://stackoverflow.com/questions/17829785/delete-files-older-than-15-days-using-powershell])&lt;br /&gt;
 $limit = (Get-Date).AddDays(-15)&lt;br /&gt;
 $path = &amp;quot;C:\Some\Path&amp;quot;&lt;br /&gt;
 # delete files older than the $limit.&lt;br /&gt;
 Get-ChildItem -Path $path -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit } | Remove-Item -Force &lt;br /&gt;
 # delete any empty directories left behind after deleting the old files.&lt;br /&gt;
 Get-ChildItem -Path $path -Recurse -Force | Where-Object { $_.PSIsContainer -and (Get-ChildItem -Path $_.FullName -Recurse -Force | Where-Object { !$_.PSIsContainer }) -eq $null } | Remove-Item -Force -Recurse&lt;br /&gt;
&lt;br /&gt;
===if / else===&lt;br /&gt;
if folder exists&lt;br /&gt;
 if (Test-Path $dirDone) { ... }&lt;br /&gt;
&lt;br /&gt;
====exit with error code====&lt;br /&gt;
 exit (1)&lt;br /&gt;
&lt;br /&gt;
===loops===&lt;br /&gt;
 $dirs = Get-ChildItem -Path .\ -Directory&lt;br /&gt;
 foreach ($d in $dirs) { ... }&lt;br /&gt;
&lt;br /&gt;
===mount network share===&lt;br /&gt;
 net use q: \\server\dir1\dir2&lt;br /&gt;
 net use q: /delete&lt;/div&gt;</summary>
		<author><name>Torben</name></author>
	</entry>
</feed>