function Start-Ranger {
[CmdletBinding()]
param (
[Parameter()]
[string]
$Path = $pwd.Path
# The assignment is neede to treat the return value of sed as array | |
IFS=$'\n' pictures=($(cat /home/mbatsching/git/abtis-cmp/deploy/powerbi/powerbi-update-datasource-credentials.template.html | grep img | sed -E 's/.*img src="([^"]+)".*/\1/g')) |
[CmdletBinding(SupportsShouldProcess)] | |
param ( | |
# Path to the script with "requires module" statements | |
[Parameter(Mandatory)] | |
[string] | |
$Path | |
) | |
$dependencies = Get-ChildItem $Path | | |
Select-String -Pattern "^#Requires -Module (@{ ModuleName = '[^']+'; RequiredVersion = '[0-9.]+';? })" | |
Haven't you always wondered how to bring Sergio Lepore's wonderful ChristBASHTree to PowerShell?
For this to work you need:
- WSL2 running your favorite linux distribution
- A PowerShell session (even 5.1 in the default console host if you feel nostalgic)
- A cup of steaming hot mullet wine
- The following function:
az storage entity merge --entity PartitionKey=$user RowKey=$user Active="false" --table-name AcademyUser --account-name sajedoxlab8idgyu4918oj
Padding a Number with zeros:
j=12
Academy${(l:3::0:)j}
# ==> Academy012
Use arithmetic evaluation:
Az CLI has many advantages over the Az
PowerShell modules, but natively it does not integrate very nicely with PowerShell scripts. That is mainly because of two reasons:
- The output of AZ CLI needs to be parsed in order to chain commands together
- Exception handling within PowerShell's try-catch clauses is not possible
Both problems can be tackled with a very simple wrapper function:
function paz {
Add the following to your profile:
how()
{
command="${@//[ ]/+}"
curl cheat.sh/"$command"
print -S "`curl -s cheat.sh/\"$command?QT\"`"
}
Imagine you have a policy to not keep files on an azure file share that are older than a specified time, lets say 5 days.
The Az.Storage
powershell module provides the cmdlet Get-AzStorageFile that can be used to retrive the files from an Azure file share, but there are two shortcomings of this cmdlet, that makes our task a bit difficult (at least in the module's current version when writing this article: 5.1.0):
- Files are not retrieved recursively. If you hit a folder, you need to call
Get-AzStorageFile
on this folder, if you want to list it's content. - File properties like LastModified are not retrieved. You need to manually call the
FetchAttributes()
method to fill this attributes with value.
Fortunately PowerShell 7 makes it relatively easy to address both problems with a simple wrapper function: