# Clear expired docker images with in specific namespace (30 days ago)
(Invoke-RestMethod http://localhost:2375/images/json) | Where-Object { $_.RepoTags -Like '*/q1game/*' -And ((New-TimeSpan -Start (Get-Date '1970-1-1') -End (Get-Date).ToUniversalTime()).TotalSeconds - $_.Created) -GT (30 * 24 * 60 * 60)} | ForEach-Object{ docker.exe rmi $_.RepoTags }
Powershell
[Powershell] Create folder, copy file and verify file hash, regex usage
Method #1:
$hashPattern = "^MD5\s+(\w+)\s+";
$sourceFile = "C:\temp\6372241e-591e-4063-b15d-8aa34ae1ac63.txt";
$destFolder = "C:\app\social space\data\scp";
$destFileName = "test.txt";
$destFile = Join-Path -Path $destFolder -ChildPath $destFileName;
New-Item -ItemType Directory -Force -Path $destFolder | Out-Null;
Copy-Item $sourceFile -Destination $destFile -Force | Out-Null;
Get-FileHash $destFile -Algorithm MD5 | Out-String -Stream | Select-String -Pattern $hashPattern | % {$_.matches.Groups[1]} | % {$_.Value};
Key points:
1. Out-String, single String
2. Out-String -Stream, output each line one by one
Method #2:
$hashPattern = "^MD5\s+(\w+)\s+";
$sourceFile = "C:\temp\6372241e-591e-4063-b15d-8aa34ae1ac63.txt";
$destFolder = "C:\app\social space\data\scp";
$destFileName = "test.txt";
$destFile = Join-Path -Path $destFolder -ChildPath $destFileName;
New-Item -ItemType Directory -Force -Path $destFolder | Out-Null;
Copy-Item $sourceFile -Destination $destFile -Force | Out-Null;
certutil.exe -hashFile $destFile MD5 | Out-String | % {($_ -split '\r?\n')[1]};
Export Windows Event log by Powershell
Get-EventLog -LogName System -Source Microsoft-Windows-Hyper-V-VmSwitch -After '2021-09-22 23:07:00' | Select-Object -Property Index,EntryType,EventID,TimeGenerated,Source,Message | Export-CSV -Path c:\q1autoops\temp\Hyper-v.csv -NoClobber