PowerShell
“PowerShell is a cross-platform task automation and configuration management framework, consisting of a command-line shell and scripting language.”
microsoft: Powershell documentation
Add Date to Filenames
ls *.jpg | rename-item -NewName {$base, $time = $_.basename, $_.creationtime.tostring('yyyy-MM-dd') $_.name -replace $_.basename, "$time-$base"} -whatif
Demo:
What if: Performing the operation "Rename File" on target "Item: /Users/js/foo/file1.jpg Destination: /Users/js/foo/file1-20190914.jpg".
What if: Performing the operation "Rename File" on target "Item: /Users/js/foo/file2.jpg Destination: /Users/js/foo/file2-20190914.jpg".
What if: Performing the operation "Rename File" on target "Item: /Users/js/foo/file3.jpg Destination: /Users/js/foo/file3-20190914.jpg".
To execute, remove the -whatif
argument.
NOTE: Spacing and new line characters is very important.
Rename all:
ls | rename-item -NewName {$base, $time = $_.basename, $_.creationtime.tostring('yyyy-MM-dd') $_.name -replace $_.basename, "$time-$base"} -whatif
PowerShell Script Execution Policy
Given the error:
PS D:\Documents> firebase
firebase : File C:\Users\SamonteTan\AppData\Roaming\npm\firebase.ps1 cannot be loaded because running scripts is
disabled on this system. For more information, see about_Execution_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ firebase
+ ~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
PS D:\Documents\GitHub\Website-Stephen-Tan>
This error is informing you that powershell cannot run powershell scripts due to a permissions error.
TODO: Add Command to view permissions
- View Execution policy Documentation
- Poweshell command to change execution policy of current window to unrestricted:
`> Set-ExecutionPolicy unrestricted -scope Process`
- This will unrestricted access will only be availble until the window is closed.
Journal
- 2020.09.04 Created file
- 2021-04-09 Added
PowerShell Script Execution Policy
section