Powershell examples

Date: 2020-11-18
$magick = 'C:\Program Files\ImageMagick-7.0.10-Q16-HDRI\magick.exe'
Write-Host $magick
# loop over *.svg files in current directory
$files = Get-ChildItem -Path "." -Filter *.svg
foreach($file in $files)
{
	$newFile = $file.BaseName + '.png';
	# construct the argument array
	$args = @('convert', '-background', 'none', '-density', '600', '-resize', '64x64',  $file, $newFile)
	Write-Host $magick $args
	# run the command
	&$magick $args
}
# read first line of file
$firstLine = Get-Content ./myfile.txt -First 1
# loop throug object properties recursively
function Resolve-Properties 
{
  param([Parameter(ValueFromPipeline)][object]$InputObject)

  process {
    foreach($prop in $InputObject.psobject.Properties){
      [pscustomobject]@{
        Name = $prop.Name
        Value = $prop.Value
      }
      Resolve-Properties $prop.Value
    }
  }
}
# a function

function Test-MrCmdletBinding {

    [CmdletBinding()] #<<-- This turns a regular function into an advanced function
    param (
        $ComputerName
    )

    Write-Output $ComputerName

}
42950cookie-checkPowershell examples