Tag Archives: Bash

Updated Events GitHub repository – Convert pptx to pdf

As I have been speaking at a number of events recently I also have been updating my GitHub Events repository. Usually I include a markdown file with a short description, my demos and my slides. I had been uploading my files as .pptx and I noticed that the repository edged over 100 MB. This prompted me into reconsidering this approach, I felt I needed to address the following:

  • Use the most compatible format available, presentations should be viewable on any device
  • Fonts should be correctly represented
  • File size should be minimal

In an effort to more efficiently use the space I have available and to use a more compatible format I decided to convert my presentations to .pdf.

Because I do not like doing stuff manually I decided to use PowerShell in combination with a bit of bash scripting to get my repository updated. First lets take a look what kind of data we are dealing with:

1
2
Get-ChildItem C:\git\Events -File -Filter *pptx -Recurse |
Select-Object -Property FullName

In total 29 presentations uploaded in .pptx format, if I would have to convert these by hand it would take about 30 minutes. Taking a look at what is possible with the PowerPoint.Application Com-Object took about 5 minutes and an additional 5 to put together the following script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Get-ChildItem C:\git\Events -File -Filter *pptx -Recurse |
ForEach-Object -Begin {
    $null = Add-Type -AssemblyName Microsoft.Office.Interop.PowerPoint
    $SaveOption = [Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType]::ppSaveAsPDF
    $PowerPoint = New-Object -ComObject "PowerPoint.Application"
} -Process {
    $Presentation = $PowerPoint.Presentations.Open($_.FullName)
    $PdfNewName  = $_.FullName -replace '\.pptx$','.pdf'
    $Presentation.SaveAs($PdfNewName,$SaveOption)
    $Presentation.Close()
} -End {
    $PowerPoint.Quit()
    Stop-Process -Name POWERPNT -Force
}

This script will recursively look for all .pptx files in the Events repository and the run the following code:

  • In the begin block load the PowerPoint Com-Object and the required type for storing files as .pdf
  • For each presentation, open the presentation, generate a new name and convert it to .pdf
  • Finally at the end close the PowerPoint application and afterwards using Stop-Process to close the window, note that if you had any other PowerPoint windows open they will also be closed.

Now I have both the .pdf and the .pptx stored in the folder, let’s take a look what the difference in file size is:

1
2
3
4
5
6
7
8
9
foreach ($Extension in ('pptx','pdf')) {
    Get-ChildItem C:\git\Events -File -Filter "*$Extension" -Recurse |
    Measure-Object -Property Length -Sum | ForEach-Object {
        [pscustomobject]@{
            'SizeinMB'  = [math]::Round($_.Sum/1MB,2)
            'Extension' = $Extension
        }
    }
}

A nice decrease in size and a format that is more suitable for sharing, this is looking good. After verifying that the .pdf files are looking good we can remove the .pptx files with the following code:

1
2
Get-ChildItem C:\git\Events -File -Filter *pptx -Recurse |
Remove-Item -Force

The last step is to commit everything to GitHub and make it available to everyone. I found a nice Stack Overflow thread that explained how to mass remove files:

Removing multiple files from a Git repo that have already been deleted from disk

Which left me with the following commands to run to commit everything to the repository using bash:

1
2
3
4
git ls-files --deleted -z | xargs -0 git rm 
git add *
git commit -m "Removed pesky pptx and added glorious pdf"
git push origin master

And to view the result here is what is looks like on GitHub now and the commit:

GitHub – JaapBrasser – Events – Commits

Let me know what you think, is .pdf a more useful format over .pptx to share presentations or would you rather see it the other way around?

Share

Speaking at TUGA IT

With the PowerShell Conference Europe fresh in my mind, it is already time to look ahead. Next week, 18-20 of May, I am speaking at TUGA IT in Lisbon Portugal. To quote TUGA from their website:

TUGA IT’s mission is to deliver a premium multi-discipline conference for IT Professionals and Companies. TUGA IT is positioned as a forward looking technological event (v-Next), focused on unreleased or recently released technologies, both from Microsoft and the Open Source worlds. TUGA IT is proudly organized by TUGA, a non-profit Portuguese association whose mission is to promote and share knowledge, with the participation of several technical communities and Microsoft MVPs.

During this three day conference I will be among 75 speakers of which 34 MVPs and many other technical experts. The following topics will be covered during the conference:

  • Microsoft Data Platform
  • Open-Source Data Platform
  • SharePoint
  • Office 365
  • Enterprise Integration
  • Microsoft Azure
  • Development Methodologies
  • Programming & Professional Development
  • DevOps

I will delivering the following two sessions at the conference:

  • From zero to hero – Learn how to automate from the GUI
  • A brave new world – MacOS, PowerShell and Linux
Share

Windows 10 – Start Windows applications from Bash

Working with Bash on Windows, I can say that it significantly simplified the way I can work cross-platform. It has allowed me to use native Linux tools, when working with Linux systems, which is a big step up from using a mix of compiled for Windows Unix tools and GUI applications. Because of this unique functionality Windows 10 has a big lead over any other platform as my day-to-day platform.

For example it is possible to add a new Windows users account directly by using the net.exe tools:

1
net.exe user /add testaccount

Alternatively it is also possible to start Windows PowerShell in Bash to execute a command, for example it becomes possible to use PowerShell to determine which processes are running in the Windows environment and the ps command to determine what is running in Linux:

1
2
powershell.exe -nop -command "Get-Process | Select-Object -First 10"
ps -aux

For me the greatest advantage is the fact that Windows executable files can also be directly called from bash, simplifying the interaction between the different OSes. An example of this is opening explorer in your current working folder in the bash terminal:

1
explorer.exe .

When a path is not accessible for the Windows application, for example anywhere in the Unix file system, a proper error message will be displayed:

1
explorer.exe .

Using this same method it is also possible to add the path to your favorite script editor to the Bash on Windows path allowing them to be directly called from the console. In the following example I will show how to open VSCode directly from Bash:

1
2
3
ls README.md
export PATH=$PATH:/mnt/c/Program\ Files\ \(x86\)/Microsoft\ VS\ Code/
Code.exe README.md

For more information and example of what is possible with the Bash commandline on Windows or I recommend following the Windows Command Line Tools For Developers blog on MSDN.

Share

Path of Linux User-Mode filesystem in Windows 10

Over the past few weeks I have been using the new functionality in the latest Windows 10 insider builds that allows you to run Ubuntu in User Mode on Windows 10. Or as it is also known: Windows Subsystem for Linux. The file system of Ubuntu is located at the following location:

%userprofile%\appdata\local\lxss

To navigate to this location from PowerShell the following code can be used:

1
2
Set-Location -LiteralPath 'C:\Users\Jaap Brasser\appdata\local\lxss\'
Set-Location -LiteralPath "${env:userprofile}\appdata\local\lxss\"

LinuxBashonWindows

By accessing this location it is easy to copy files from the Windows filesystem directly into the Linux file system.

For more information in regards to Linux User-Mode on Windows 10, please refer to the following links:

Links in this Article
Blog – Windows Command Line Tools For Developers
Announcing Windows 10 Insider Preview Build 14316
Video – Running Bash on Ubuntu on Windows!

Share