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-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 / 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-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-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-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-chart
Created December 2, 2014 16:36
Powershell to create line chart from EXCEL
#
# http://stackoverflow.com/questions/25331407/powershell-to-create-line-chart-from-excel
#
#Test Data
$Data=("8/15/2014",3091),("8/14/2014",240),("8/13/2014",519),("8/12/2014",622),("8/11/2014",2132),("8/10/2014",1255),("8/9/2014",3240)|ForEach{[PSCustomObject][Ordered]@{'Date_to_Display'=$_[0];'Number_of_Computers'=$_[1]}}
$xlConditionValues=[Microsoft.Office.Interop.Excel.XLConditionValueTypes]
$xlTheme=[Microsoft.Office.Interop.Excel.XLThemeColor]
$xlChart=[Microsoft.Office.Interop.Excel.XLChartType]
@constructor-igor
constructor-igor / powershell-problematic-excel-chart-sample
Created December 2, 2014 16:41
Problematic powershell chart sample
#Test Data
#$Data=("8/15/2014",3091),("8/14/2014",240),("8/13/2014",519),("8/12/2014",622),("8/11/2014",2132),("8/10/2014",1255),("8/9/2014",3240)|ForEach{[PSCustomObject][Ordered]@{'Date_to_Display'=$_[0];'Number_of_Computers'=$_[1]}}
$xlConditionValues=[Microsoft.Office.Interop.Excel.XLConditionValueTypes]
$xlTheme=[Microsoft.Office.Interop.Excel.XLThemeColor]
$xlChart=[Microsoft.Office.Interop.Excel.XLChartType]
$xlIconSet=[Microsoft.Office.Interop.Excel.XLIconSet]
$xlDirection=[Microsoft.Office.Interop.Excel.XLDirection]
$xl = new-object -ComObject Excel.Application
@constructor-igor
constructor-igor / svn-diff-bypowershell
Created December 16, 2014 12:23
How to get changes files from SVN between two revisions with PowerShell
#
# from http://hmemcpy.com/2014/12/how-to-get-changes-files-from-svn-between-two-revisions-with-powershell/
#
function Export-SvnDiff($repo, $fromRevision, $toRevision, $outputDirectory)
{
$xpath = "/diff/paths/path[@kind='file' and (@item='added' or @item='modified')]"
[xml]$output = & svn diff -r $("{0}:{1}" -f $fromRevision, $toRevision) $repo --summarize --xml
$output | Select-Xml -XPath $xpath | % { $_.node."#text" } | % {
$targetFile = Resolve-FullPath (Join-Path $outputDirectory ($_ -replace $repo))
@constructor-igor
constructor-igor / nested-brackets
Created April 22, 2015 12:55
parsing nested parentheses in python, grab content by level
#http://stackoverflow.com/questions/4284991/parsing-nested-parentheses-in-python-grab-content-by-level
def parenthetic_contents(string):
"""Generate parenthesized contents in string as pairs (level, contents)."""
stack = []
for i, c in enumerate(string):
if c == '(':
stack.append(i)
elif c == ')' and stack:
start = stack.pop()
yield (len(stack), string[start + 1: i])
@constructor-igor
constructor-igor / split-string-with-nested-sep
Created April 22, 2015 13:36
Splitting a String Python within a list
#http://stackoverflow.com/questions/23219400/splitting-a-string-python-within-a-list
>>> import re
>>> i = 'john(is,great),paul,school'
>>> re.split(r',+(?=[^()]*(?:\(|$))', i)
['john(is,great)', 'paul', 'school']