Skip to content

Instantly share code, notes, and snippets.

View constructor-igor's full-sized avatar

Igor Ziselman constructor-igor

View GitHub Profile
@constructor-igor
constructor-igor / powershell-custom-type
Created December 2, 2014 16:22
Can I write a class using powershell?
#
# http://stackoverflow.com/questions/6848741/can-i-write-a-class-using-powershell
#
C:\PS>$source = @"
public class BasicTest
{
public static int Add(int a, int b)
{
return (a + b);
@constructor-igor
constructor-igor / powershell-excel-intro
Created December 2, 2014 16:21
powershell: how to create and set data to excel
[array] $dataX = 0, 1, 2, 3, 4
[array] $dataY = 0.9, 0.5, 0.2, 0.9, 0.99
$excel = New-Object -ComObject Excel.Application
$excel.Visible = $true
$workbook = $excel.Workbooks.Add()
$sheet = $workbook.ActiveSheet
$counter = 0
$counter = 1
@constructor-igor
constructor-igor / powershell-list-of-all-outlook-contacts
Created November 27, 2014 12:59
Powershell: list of all Outlook contacts
$Outlook=NEW-OBJECT –comobject Outlook.Application
$Contacts=$Outlook.session.GetDefaultFolder(10).items
$Contacts | Format-Table FullName,MobileTelephoneNumber
@constructor-igor
constructor-igor / powershell-list-of-all-entries-from-Outlook-GAL
Last active January 12, 2022 23:32
Powershell: list of all entries from Outlook Global Address List (GAL)
[Microsoft.Office.Interop.Outlook.Application] $outlook = New-Object -ComObject Outlook.Application
$entries = $outlook.Session.GetGlobalAddressList().AddressEntries
$count = $entries.Count
$count
foreach($entry in $entries)
{
[console]::WriteLine("{0}: {1}", $entry.Name, $entry.GetExchangeUser().MobileTelephoneNumber)
}
@constructor-igor
constructor-igor / powershell-embed-2-images-to-Outlook-emails-body
Created November 26, 2014 15:34
Powershell: embed 2 images to Outlook emails body
function SendEmailWithEmbeddedImages([String] $to, [String] $subject, [String] $body, [String] $attachment, [array] $imageFiles)
{
$htmlText = "<HTML>{0}</HTML>"
foreach ($imageFile in $imageFiles) {
$fileName = ExtractFileName $imageFile
$imageTag = [string]::Format("<img src='cid:{0}'>", $fileName)
$htmlText = $htmlText + $imageTag
}
@constructor-igor
constructor-igor / gist:18e88b456833f3dc9d7f
Created November 26, 2014 13:00
powershell: google chart api sample (small numbers, scaling)
#
# sample:
#$title = "MyChart"
#$size = "700x350"
#$url = CreateChartUrl $valueArray $labelArray $title $size
#
function CreateChartUrl ($valueArray, $labelArray, [string]$title, $size) {
$chartType = "lc"
$chartData = [string]::join(",", $valueArray)
@constructor-igor
constructor-igor / powershell-send-email-via-Outlook-and-insert-image-to-body
Last active September 5, 2018 17:55
Powershell: send email via Outlook and insert image to body
function SendEmailWithEmbeddedImage([String] $to, [String] $subject, [String] $body, [String] $attachment, [String] $imageFile)
{
#$htmlHeader = "<HEAD>Text<B>BOLD</B> <span style='color:#E36C0A'>Color Text</span></HEAD>"
$htmlText = "<HTML>{0}</HTML><img src='cid:{1}'>"
$Outlook = New-Object -ComObject Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.To = $to #"boss@company.com"
$Mail.Subject = $subject
$Mail.HTMLBody = [string]::Format($htmlText, $body, ExtractFileName $imageFile)
@constructor-igor
constructor-igor / include-simulation-in-powershell
Created November 25, 2014 11:32
Include simulation in powershell
. "$PSScriptRoot\genericFunctions.ps1"
#
#
#
<actual powershell source, can use functions from file genericFunction.ps1>
@constructor-igor
constructor-igor / create-zip-file-powershell
Last active August 29, 2015 14:10
create Zip file (powershell)
#
# http://stackoverflow.com/questions/1153126/how-to-create-a-zip-archive-with-powershell
#
#
# $zipFileName contains path to new .zip file
# $sourceDir contains path to folder with source data
#
ZipFiles $zipFileName $sourceDir
@constructor-igor
constructor-igor / create-msqueue-and-send-message
Last active August 29, 2015 14:10
create-msqueue-send-message-and-receive-message (powershell)
#
#
# References:
# http://ardalis.com/How-Can-I-View-MSMQ-Messages-and-Queues
# to see queue, search via "Computer Mamagment"
#
# simular sample: http://blogs.msdn.com/b/sajay/archive/2010/03/18/powershell-script-to-create-an-msmq.aspx
#
[Reflection.Assembly]::LoadWithPartialName("System.Messaging")