I have written a post about PowerShell keyboard shortcuts on my new site. Go to https://get-note.net/2018/12/12/powershell-shortcuts/ to read it.
For a long time I have been using PowerShell ISE for writing PowerShell scripts. But a few months ago I switched to Visual Studio Code.
The main reason for me was the built-in support for Git. This makes it so much easier for using Git. Specially if you just have started using Git. There is no need to remember commands for the Git command line or to use a separate Gui.
Another reason for me was that it not only supports PowerShell but also many other languages. Some have built-in support. For others you can install an extension. You can find many extension at the Visual Studio Code Marketplace. At my work we use Puppet for configuration management. And there is extension for Puppet. So I can use one editor for all my scripts.
Because Visual Studio Code supports extensions it is easy to customize the editor for you own needs. There are extension for themes, languages, keymaps, debuggers, linters etc.
To get started with VSCode I found the blog posts on the Hey Scripting Guy blog very helpful.
I you do not use Visual Studio Code I suggest you take a look at it. Ohhhhh, and it is free also!
For Windows System Administrators it is getting more important to know how to use Git and GitHub. On the Microsoft Virtual Academy you can find a free training on how to use it.
It has been more than 2 years ago that I wrote my last post on this blog. With a new year started it is time to make a new start and reboot this blog.
The last years I have been busy with many new things. And my work changed from being to traditional System Administrator to doing more devops. Working with Scrum, Git, Puppet. But still Windows related. This involved also a lot of PowerShell scripting.
Expect to see more about these things here. But also about IIS, Web Hosting and the Microsoft Deployment Toolkit.
In the last 2 posts I shared two PowerShell functions for extracting an archive and creating a new zip file from a folder. Today I will share a new function, New-ArchiveFromFile.
This function you can use when you want to compress a single file. This can be useful for log management. Instead of archiving log files in one big zip file I prefer archive log files in separate zip files. This way it is much easier and faster to remove older files that you don’t want to keep.
Creates a new archive from a file
Creates a new archive with the contents from a file. This function relies on the
.NET Framework 4.5. On windwows Server 2012 R2 Core you can install it with
New-ArchiveFromFile -Source c:\test\test.txt -Destination c:\test.zip
# Param1 help description
# Param2 help description
[System.Reflection.Assembly]::LoadWithPartialName(“System.IO.Compression.FileSystem”) | Out-Null
Write-Verbose “Creating archive $Destination….”
$zipEntry = “$Source“ | Split-Path -Leaf
$zipFile = [System.IO.Compression.ZipFile]::Open($Destination, ‘Update’)
$compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
Write-Verbose “Created archive $destination.”
Write-Host “ERROR: The source $source does not exist!” -ForegroundColor Red
Write-Host “ERROR: The file $Source is in use or $destination already exists!” -ForegroundColor Red
Write-Host “ERROR: You are not authorized to access the source or destination” -ForegroundColor Red
This is just a basic version. It could use some improvements.