Invoke-Command -ComputerName $complist { $Env:LOGONSERVER }
nltest /sc_query:DOMAIN /server:ComputerName
if (([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
"I'm Admin"
}
else {
"Im NOT"
}
Add-Type -Path DotNetZip.dll
$zip = New-Object Ionic.Zip.ZipFile 'myarchive.zip'
# поглядеть на свойства/методы
Get-Member -InputObject $zip
# тут же с готовым объектом можно и побаловаться, попробовать что-то
$zip.AddDirectory('D:\111')
$zip.Save()
$zip.Dispose()
[void][System.Reflection.Assembly]::LoadWithPartialName("MySql.Data")
$myconnection = New-Object MySql.Data.MySqlClient.MySqlConnection
$myconnection.ConnectionString = "database=access;server=myserver;Persist Security Info=false;user id=root;pwd=root"
$myconnection.Open()
$command = $myconnection.CreateCommand()
$command.CommandText = "show tables;"
$r = $command.ExecuteReader()
while ($r.Read()) {
$r[0]
}
$r.close()
$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
}