Powershell: Copy-Item doesn’t work when file name contains square bracket ([]) characters

I have a file whose name contains square bracket characters, and I want to copy the file to another location via Powershell. So I use the Copy-Item founcation to do this. like this: Copy-Item -Path "C:\FileTest\1\[Control]Test.txt" -Destination "C:\FileTest\2\[Control]Update.txt" No errors occurred when executing the script, but the target file was not copied either. After looking …

Powershell does not support pass Boolean parameter when -File parameter is used

Let’s say there is a Powershell script file named test.ps1 with the following content: param ([Boolean] $FromSchTask) if ($FromSchTask) { echo Yes } else { echo No } When I run this script with -File parameter in command prompt by powershell.exe, for example: C:\>powershell.exe -ExecutionPolicy bypass -File ./test.ps1 -FromSchTask $True It will throw the following …

[Powershell]Clear docker images by Invoke-RestMethod to docker api

# 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] 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 …

Proudly powered by WordPress