Invoke-Command -FilePath ....
function foo {
param($a)
"I'm a FOO func on $($env:COMPUTERNAME)- $a"
}
function bar {
param($a)
"I'm a BAR func on $($env:COMPUTERNAME)- $a"
}
# variant 1
$foo = $function:foo
Invoke-Command -ComputerName REMOTE {
Set-Content function:foo $using:foo
foo 'aaa'
}
#variant 2
Invoke-Command -ComputerName REMOTE {
param($bar)
Set-Content function:bar $bar
bar 'aaa'
} -ArgumentList $function:bar
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()