PowerShell z API Windows

http://blogs.technet.com/b/heyscriptingguy/archive/2013/06/25/use-powershell-to-interact-with-the-windows-api-part-1.aspx
$MethodDefinition = @'

[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]

public static extern bool CopyFile(string lpExistingFileName, string lpNewFileName, bool bFailIfExists);

'@

$Kernel32 = Add-Type -MemberDefinition $MethodDefinition -Name 'Kernel32' -Namespace 'Win32' -PassThru

# You may now call the CopyFile function

# Copy calc.exe to the user's desktop

$Kernel32::CopyFile("$($Env:SystemRoot)\System32\calc.exe", "$($Env:USERPROFILE)\Desktop\calc.exe", $False) 

SSH w powershell:

#based on https://github.com/darkoperator/Posh-SSH

$IP="192.168.1.1"
$credS ="secretpasswordby" # $password = "mypassword" | ConvertTo-SecureString -asPlainText -Force | ConvertFrom-SecureString
$credN = "uzytkownik"

$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $credN ,($credS | ConvertTo-SecureString)
New-SSHSession -ComputerName $IP -Credential ($cred)
Invoke-SSHCommand -Index 0 -Command "#bash command"

Pobranie adresu email z wiadomości w formacie SMTP:

function GetSenderSMTPAddress([object] $mail)
{
    $PR_SMTP_ADDRESS =  "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
    if (!$mail)
    {
        $URL_Format_Error = "email object empty throw execption"
       Write-Error $URL_Format_Error
    }Po
    if ($mail.SenderEmailType -eq "EX")
    {
        $sender = $mail.Sender
        if  (-not (!$sender))
        {
            #Now we have an AddressEntry representing the Sender
            if (($sender.AddressEntryUserType -eq 0) -or ($sender.AddressEntryUserType -eq 5))
            {
                #Use the ExchangeUser object PrimarySMTPAddress
              $exchUser = $sender.GetExchangeUser()
                if (-not (!$exchUser))
                {
                    return $exchUser.PrimarySmtpAddress
                }
                else
                {
                    return "unknow@address"
                }
            }
            else
            {
                
                return $($sender.PropertyAccessor.GetProperty($PR_SMTP_ADDRESS))
            }
        }
        else
        {
            return "unknow@address"
        }
    }
    else
    {
        return $mail.SenderEmailAddress
    }
}

Iteracja po wielopoziomowych Hash'ach:

foreach($hash in $hashall.GetEnumerator()){
    write-host "$($hash.Name)"
        foreach ($property in $($hash.Value).GetEnumerator())
        {
            write-host "          $($property.Name)"
        }
}

 

Outlook iteracja po mailach:

    $skrzynka = "mail@test.pl"
    $Folder = "Skrzynka odbiorcza"

    Add-Type -assembly "Microsoft.Office.Interop.Outlook"
    $Outlook = New-Object -ComObject Outlook.Application
    $Namespace = $Outlook.GetNameSpace("MAPI")
    $AllEmail = $NameSpace.Folders.Item($skrzynka).Folders.Item($Folder).Items

 

Outlook iteracja po mailach:

    $skrzynka = "mail@test.pl"
    $Folder = "Skrzynka odbiorcza"

    Add-Type -assembly "Microsoft.Office.Interop.Outlook"
    $Outlook = New-Object -ComObject Outlook.Application
    $Namespace = $Outlook.GetNameSpace("MAPI")
    $AllEmail = $NameSpace.Folders.Item($skrzynka).Folders.Item($Folder).Items

 

Pobranie metod obiektu:

$obiekt | gm