Search This Blog

Tuesday, October 9, 2018

Powershell SVG Maker

I was going to sit around ill at hone and make an SVG one little square at a time in Inkscape of this image I use...



However, after 4 dots I got bored.

I know that an SVG file is an XML based descriptor of images and shapes and know that I can use  minimal information to make a test file that is similar to the following 2x2 block...

<xml version="1.0" encoding="UTF-8"?>
<svg version="1.1" baseProfile="full" width="20" height="20" xmlns="http://www.w3.org/2000/svg">
<rect fill="#000000" x="0" y="0" width="10" height="10"/>
<rect fill="#000000" x="10" y="0" width="10" height="10"/>
<rect fill="#ffffff" x="0" y="10" width="10" height="10"/>
<rect fill="#000000" x="10" y="10" width="10" height="10"/>
</svg
>

So... by grabbing the image, and looping through the pixels we can create all the rects we need. we can even keep the original color of the pixels. This routine also has a scaling factor in it.


$FilePath = 'LesleyatHonda.12.Dither.Part.White.png' $Image = [System.Drawing.Image]::FromFile($filePath) # Simple dirty UTF-8 outfile << THIS IS MPORTANT!! $OutFilePath = 'LesleyatHonda.svg' $SVGScale = 10 '<?xml version="1.0" encoding="UTF-8"?>' | Out-File $OutFilePath -Encoding utf8 '<svg version="1.1" baseProfile="full" width="'+($Image.Width*$SVGScale)+'" height="'+($Image.Width*$SVGScale)+'" xmlns="http://www.w3.org/2000/svg">' | Out-File $OutFilePath -Append -Encoding utf8 For($ypos=0;$ypos -lt $Image.Height;$ypos++){ For($xpos=0;$xpos -lt $Image.Width;$xpos++){ $Pixel = $Image.GetPixel($xpos,$ypos) '<rect fill="#'+($Pixel.Name.substring(2,6))+'" x="'+($xpos*$SVGScale)+'" y="'+($ypos*$SVGScale)+'" width="'+$SVGScale+'" height="'+$SVGScale+'"/>' | Out-File $OutFilePath -Append -Encoding utf8 } }; '</svg>' | Out-File $OutFilePath -Append -Encoding utf8














Thursday, October 4, 2018

Notes View Exporter


Modify the variables at the top and let'r rip!




## Notes View Exporter in Powershell

Set-Location 'C:\Program Files (x86)\IBM\Notes' ## Notes Program Dir
$dominoServiceName = 'Appsrv001/MyCompany'
$dbName = 'names.nsf'
$viewName = 'Groups'


$session = $null; $session = New-Object -ComObject Lotus.NotesSession; $session.Initialize(); 'Notes version: '+$session.NotesVersion
$db = $null; $db = $session.GetDatabase($DominoServiceName, $dbName, 1);'DB Title: '+$db.Title
$view = $null; $view = $db.GetView($viewName);'Entry Count: '+$view.EntryCount

$oOut=@(); $count = 0;     $dtStart = (get-date)
if($view.EntryCount -gt 0){
    $doc = $view.getFirstDocument();
    $viewcolumns = $view | select -ExpandProperty Columns
    While ($doc -ne $null){
        if (($count/100) -eq [int]($count/100)){$dtCurr = (get-date); 'Count: '+$count+' of '+$view.EntryCount+': '+$dtCurr.Hour.ToString('#0')+':'+$dtCurr.Minute.ToString('#0')+':'+$dtCurr.Second.ToString('#0')+'.'+$dtCurr.Millisecond.ToString('###0')}                   
        $oItem = $null; $oItem = New-Object PSObject
        for ($i=0;$i-lt$viewcolumns.count;$i++){
            $val=$null;$val=if($viewcolumns[$i].Formula -gt ''){$viewcolumns[$i].Formula}else{$viewcolumns[$i].Itemname};
            $oItem = $oItem | Add-Member @{(''+$i+'. '+$viewcolumns[$i].title)=[string]''+($session.Evaluate($val,$doc))} -PassThru
        };
        $oOut += $oItem
        $doc=$view.GetNextDocument($doc); $count++
    }
}

$YYYYMMDDhhmmss = $dtStart.year.ToString('###0')+$dtStart.Month.ToString('#0')+$dtCurr.Day.ToString('#0')+$dtCurr.Hour.ToString('#0')+$dtCurr.Minute.ToString('#0')+$dtCurr.Second.ToString('#0')
$oOut | export-csv ('c:\data\notesviewexport'+$YYYYMMDDhhmmss+'.csv')
$oOut | Export-Clixml ('c:\data\notesviewexport'+$YYYYMMDDhhmmss+'.xml')

Tuesday, July 31, 2018

Getting to Office 365 Calendar entries

I occasionally have to do low level analysis on items in a mailbox. Here's a how I typically have to do it.

Basically its.. 


  1. Get credentials
  2. Instantiate environment & containers
  3. Create collection
  4. Do stuff with collection

like this...

## Generic work session stuff start
##
$ExCreds = get-credential


<# I put this stuff in my profile and is a little more than needed for this topic
Enable-PSRemoting -Force
Set-ExecutionPolicy RemoteSigned -Force
Import-Module AzureAD
Import-Module LyncOnlineConnector
Import-Module MSOnline
Import-Module SkypeOnlineConnector
#>

Connect-AzureAD -Credential $ExCreds
Connect-MsolService -Credential $ExCreds
$ExchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri"https://outlook.office365.com/powershell-liveid/" -Credential $ExCreds -Authentication "Basic" -AllowRedirection
Import-PSSession $ExchangeSession
$lyncSession = New-CsOnlineSession -Credential $ExCreds
Import-PSSession $lyncSession
## 
## Generic work session stuff end


$usermail='lesley@mycompany.com'

$ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013_SP2
$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService($ExchangeVersion)
# $service.UseDefaultCredentials = $true
$creds = New-ObjectSystem.Net.NetworkCredential($ExCreds.UserName.ToString(),$ExCreds.GetNetworkCredential().password.ToString()) 
$service.Credentials = $creds 
Add-Type -Path "C:\Program Files\Microsoft\Exchange\Web Services\2.0\Microsoft.Exchange.WebServices.dll" 
$folderid= new-objectMicrosoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar,$Usermail)   
$service.Url = $uri

$Calendar = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)
$exportCollection = @()
#Define Date to Query
$StartDate = (Get-Date).AddDays(-1)
$EndDate = (Get-Date).AddDays(7)
$CalendarView = New-ObjectMicrosoft.Exchange.WebServices.Data.CalendarView($StartDate,$EndDate,1000)   
$CalendarItems = $service.FindAppointments($Calendar.Id,$CalendarView

$counter =  0''foreach ($CalendarItem in $CalendarItems){''+$counter+' '+$CalendarItem.subject;$counter++}
'''Total entries: '+$CalendarItems.TotalCount


0 Ape Pilot Check-Ins
1 Final prep for leadership meeting
2 Catch-up
Elfs Pilot Area Check In
4 Q1 ADM Pre-Review (before Pam)
5 Foundations for a Leader
6 FTL - Module 4
7 WildSpark Monthly - Don't be McFly
8 POD Pilot Visit
9 Mad Pilot Area Check-In
10 POD Staffing Plan Update to Comp
11 HR Project - Team Meeting
12 POD Career Path Policies - Open Items
13 Reporting in High
14 Foundations for a Leader - Facilitator Touch Base
15 High Reporting
16 Review 1 with Dept Mgrs
17 Weekly POD Meeting
18 Monthly Connect/Update
19 Review for POD
20 Follow Up on Staffing Plan for Org Design
21 Smart Shine
22 Dental Cleaning
23 FTL Touchbase
24 Weekly POD Project
25 Ape Pilot Check-Ins
26 Back to School Forms
27 Elfs Pilot Area Check In
28 Org Design Staffing Plan

Total entries: 29



Thursday, February 16, 2017

VLC Transcode

Disclaimer: It's easy to have less-than-optimal-settings and create resulting files with jumpy video and audio. If you run into problems, take a look at your settings. There are some additional references at the end.


My Story...



Earlier I created a video demonstrating an issue for another support group. But due to size limitations in email, I needed to shrink it down a little bit.

Using VideoLAN's VLC I can use a command similar to the following... (which I stick in a TranscodeIMG_7401.bat file)
"C:\Program Files (x86)\VideoLAN\VLC\vlc" "e:\data\video\IMG_7401.MOV" :sout=#transcode{vcodec=h264,vb=1024,acodec=mp2a,ab=192,scale=0.25,channels=2,deinterlace,audio-sync}:std{access=file,mux=ps,dst="e:\data\video\IMG_7401.MPG"}  vlc://quit
This creates MPEG output at 1/4 the original canvas size.

As you can see, the original file IMG_7401.MOV, with a ~61 seconds of video, is just over 100MB. The resulting output, IMG_7401.MPG, is just over 9MB.











Interestingly, the MPEG compression is the real gainer in space. The canvas size adjustment only affected the output slightly and apparently increased it! IMG_7401-2.MPG is at the original canvas size.

Here is TranscodeIMG_7401-2.bat's contents...

"C:\Program Files (x86)\VideoLAN\VLC\vlc" "e:\data\video\IMG_7401.MOV" :sout=#transcode{vcodec=h264,vb=1024,acodec=mp2a,ab=192,scale=1,channels=2,deinterlace,audio-sync}:std{access=file,mux=ps,dst="e:\data\video\IMG_7401-2.MPG"}  vlc://quit


The Files


I suggest you download the files and try them in your viewer to see the difference.


If you don't like that interface try: https://drive.google.com/drive/folders/0B9hFc_9eg0ciazdfZVlnemZ2eXc


Additional References...


VideoLAN... http://www.videolan.org Go here to Download VLC
Docs... https://wiki.videolan.org/Documentation
Forums... https://forum.videolan.org
Google Search... https://www.google.com/search?&q=vcl%20transcode%20jumpy%20video

Monday, March 21, 2016

Domino Port Audit

Pretend some server admins were going to change out their IPs from their 208 addresses for some new IPs and you needed to test for connectivity for all the IPs involved; server and services. You may want to do something similar to the following...

## The Scripting Guys Test-Port script
## https://gallery.technet.microsoft.com/scriptcenter/97119ed6-6fb2-446d-98d8-32d823867131

## Pretend I got IBM Domino servers in cluster pairs like this...
 app001/srv/mycompany 10.10.10.23
 app011/srv/mycompany 10.10.10.24
 app021/srv/mycompany 208.109.4.218   # godaddy.com is not my server.
 app022/srv/mycompany 208.109.4.219   # I don't know who this is.
 app002/srv/mycompany 10.10.2.54
 app012/srv/mycompany 10.10.2.55

## From a cmd I can issue these commands and capture the results
ping 10.10.10.23
ping 10.10.10.24
ping 208.109.4.218
ping 208.109.4.219
ping 10.10.2.54
ping 10.10.2.55

tracert 10.10.10.23
tracert 10.10.10.24
tracert 208.109.4.218
tracert 208.109.4.219
tracert 10.10.2.54
tracert 10.10.2.55

## I Want to see the successful connection to the NRPC port
start telnet 10.10.10.23 1352
start telnet 10.10.10.24 1352
start telnet 208.109.4.218 1352
start telnet 208.109.4.219 1352
start telnet 10.10.2.54 1352
start telnet 10.10.2.55 1352

## Domino console batch saved as trace.txt and piped in to the console
trace 10.10.10.23
trace 10.10.10.24
trace 208.109.4.218
trace 208.109.4.219
trace 10.10.2.54
trace 10.10.2.55
## When your done with this you can search the log for messages like...
## Network: 10.10.10.23 is the server address of server CN=app001/OU=srv/O=mycompany
## I typically just search on " is the server address of server CN=" 
## Make sure to include the double quotes.

## Singular test 
$tcpObject = New-Object System.Net.Sockets.TcpClient
$tcpConnect = $tcpObject.BeginConnect('10.10.10.23','1352',$null,$null)
$tcpConnect.AsyncWaitHandle.WaitOne(1000)
$tcpObject.Close()

## playing around
$Server = '10.10.10.23'
$Server = '10.10.10.24'
$Server = '208.109.4.218'
$Server = '208.109.4.219'
$Server = '10.10.2.54'
$Server = '10.10.2.55'

## Lets to a batch
$ServerList = @('10.10.10.23',
                '10.10.10.24',
                '208.109.4.218',
                '208.109.4.219',
                '10.10.2.54',
                '10.10.2.55')
$port=1352
foreach($Server in $ServerList){
   $tcpObject = New-Object System.Net.Sockets.TcpClient
   $tcpConnect = $tcpObject.BeginConnect($Server,$port,$null,$null)
   $wait = $tcpConnect.AsyncWaitHandle.WaitOne(1000)
   ($server+" "+$wait)
   $wait=$null
   $tcpObject.Close()
}
This batch audit at the end creates a result similar to ...
10.10.10.23 True
10.10.10.24 True
208.109.4.218 False
208.109.4.219 False
10.10.2.54 True
10.10.2.55 True

Tuesday, March 8, 2016

Getting Started with Powershell and Office365 scripting

Here's what I know today...
# Managing Office 365 and Exchange Online with Windows PowerShell
# https://support.office.com/en-us/article/Managing-Office-365-and-Exchange-Online-with-Windows-PowerShell-06a743bb-ceb6-49a9-a61d-db4ffdf54fa6

#Connect to Office 365 PowerShell
$UserCredential = Get-Credential
$MsolService = Connect-MsolService -Credential $UserCredential
    # do stuff here like... 
    Get-Module
    Get-Command -Module MSOnline
# no remove: https://technet.microsoft.com/en-us/library/dn568015.aspx#Step8

# Connect to Exchange Online using remote PowerShell
Set-ExecutionPolicy RemoteSigned
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
    # do stuff here like... 
    Get-Module
    Get-Command -Module tmp_mjopwmqk.4nu #or whatever it is named

Remove-PSSession $Session

# Connect to Office 365 Compliance Center PowerShell - need a role first
Set-ExecutionPolicy RemoteSigned
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
    # do stuff here?
Remove-PSSession $Session #Security limits 3 connections only - Clean up!

# Connecting to Skype for Business Online by using Windows PowerShell 
$UserCredential = Get-Credential
$Session = New-CsOnlineSession -Credential $UserCredential
    # do stuff here
Remove-CsOnlineSession $Session

# Set up the SharePoint Online Management Shell Windows PowerShell environment 
$UserCredential = Get-Credential
$URL ='https://MyCompany-my.sharepoint.com'
Connect-SPOService -Url $URL -credential $UserCredential
    # do stuff here
Disconnect-SPOService

I wonder what I'll know tomorrow...

Thursday, November 19, 2015

Sharepoint Redirect to Notes://

I couldn't get my Sharepoint admin to add support to another link type so I created an html file to store in my Sharepoint's Site Assets as a redirector. Then I could embed the shortcut to the html redirector in any Sharepoint content.

HowToStartNotes.html ==========================================
<!DOCTYPE html> <!-- app001/srv/mycompany 10.10.10.23 app002/srv/mycompany 10.10.02.54 app003/srv/mycompany 10.10.132.132 app004/srv/mycompany 10.10.214.03 Not everyone has access via the Domino server's name in their region's DNS. So, replacing the link's server name with the server IP makes it globally accessible. --> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>How To Link</title> <meta http-equiv="refresh" content="0;URL='Notes://10.10.132.132/1234567890123456/12345678901234567890123456789012/12345678901234567890123456789012'" /> </head> <body> <p>This page is an automatic link to to the <a href="Notes://10.10.132.132/1234567890123456/12345678901234567890123456789012/12345678901234567890123456789012"> How to start Notes</a> article in the <a href="Notes://10.10.132.132/1234567890123456"> Notes How To database</a>. <br> <br> Contact the Helpdesk if it is not working as needed. </p> </body> </html>