Insights for productivity and tech related info

Windows Powershell

2019-09-28 Code.Reportwindows

PowerShell is a task automation and configuration management framework from Microsoft

It consisting of a command-line shell and associated scripting language. Initially a Windows component only, known as Windows PowerShell, it was made open-source and cross-platform on August 2016 with the introduction of PowerShell Core. This shell is based on the .NET framework, and it includes a command-line shell and a scripting language.

Powershell contains hundreds of commands, which are called Cmdlets. We can easely list them all with

Get-Command -Type Cmdlet

In this example I will show you how I made a simple automation process to build and publish this blog, which is made in GatsbyJS and published at github pages.

First part of the script, it cleans and build the react app (gatsbyjs project)

gatsby clean
gastby build

Then it will wipe the old build, which was cloned on a directory. Keep in mind that I had to keep the .git folder, so we are passing a parameter to exclude the .git folder while cleaning all other files on C:\git\\ recursively

Remove-Item -recurse C:\git\\* -exclude C:\git\\.git\

Then it will create a file named CNAME and it will add a text called inside

New-Item C:\git\\CNAME
Set-Content C:\git\\CNAME ''

The last thing I had to do is to copy all the contents of the gatsby build located on C:\git\cdrp\public* onto C:\git\, the -Recurse parameter states that the copy must include all files and subfolders

Copy-Item -Path C:\git\cdrp\public\* -Destination C:\git\\ -Recurse