- set_fact:
var_{{ item.index }}: "{{ item.value }}"
loop:
- index: x1
value: 'aaa'
- index: x2
value: 'bbb'
- debug: var=var_x1
- debug: var=var_x2
Received: from mail-ua1-f41.google.com (mail-ua1-f41.google.com [209.85.222.41])
(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
(No client certificate requested)
by xxx.xxx.ru (Postfix) with ESMTPS id 537297EC5E
for <xxx@xxx.ru>; Fri, 15 May 2020 11:58:38 +0300 (MSK)
Received: by mail-ua1-f41.google.com with SMTP id c17so510696uaq.13
for <xxx@xxx.ru>; Fri, 15 May 2020 01:58:38 -0700 (PDT)
$config1.Custom.Property, $config2.AnyProperty | sort-object -unique
#если без фильтрации чтобы сделать массив плоским вместо sort
... foreach-object { $_ }
Get-ChildItem -Recurse | Where-Object {$_.PSIsContainer}
--> Get-ChildItem -Directory -Recurse
$params =@{}
Get-Content d:\params.ini | foreach-object {
If $_ -match '\[param:(^]+)\]\s*=\s*(.*)' { $params[$matches[1]}=$matches[2] }
}
$filelist = get-childitem d:\work *json,*sql
Foreach $file in$filelist {
Get-content $file | foreach-object {
If $_ -match 'Тут нужный regex для файла' -and $params.contains($matches[1]){
$_=$_ - replace 'тут тоже регекс', $params[$atches[1])
}
} |set-content $file
}
$myscriptblock = { mysupercommand $args }
& $myscriptblock $myparams
$scriptblock = { param($fg,$bg, $text) Write-Host -Foreground $fg -Background $bg $text }
& $scriptblock yellow blue text
PS> $text = 'first'
PS> $sb = { "my Text - $text" }
PS> & $sb
my Text - first
PS> $text = 'second'
PS> &$sb
my Text - second
function Invoke-MyTool {
param(
[ValidateSet('ping','write')]
[parameter()]
[string]$cmd,
[parameter(mandatory=$false, position=1, ValueFromRemainingArguments=$true)]$args
)
)
$config = @{
ping = { ping },
'write' = { param($text, $fg, $bg) write-host $text -fore $fg -back $bg }
}
& $config[$cmd] $args
}