16 March 2017

How to publish your Windows PowerShell script in the PowerShell public gallery

PowerShell Logo
PowerShell is more than just a terminal console. It is developed by Microsoft allowing you to manage their products through command lines or scripts. 

One of the great advantages of belonging to Windows Management Framework (WMF) is that it allows access to:
  • Common Information Model (CMI);
  • Component Object Model (COM);
  • Framework .NET;
  • Server Manager CIM Provider;
  • Server Manager WMI provider;
  • Software Inventory Logging (SIL);
  • Windows Management Infrastructure (WMI);
  • Windows PowerShell;
  • Windows PowerShell Desired State Configuration (DSC);
  • Windows PowerShell Integrated Scripting Environment (ISE);
  • Windows PowerShell Web Services (Management OData IIS Extension);
  • Windows Remote Management (WinRM).

But does it have so many advantages?
Yes, in addition to being able to use the .NET framework you can create scripts to do autonomous jobs that can be executed by parameters, which allows the script to be reusable and updatable.


In PowerShell command lines are called cmdlets and are more complex commands. A cmdlet may even be a script that invokes an API call or other cmdlets. You can see the Cmdlet overview at https://msdn.microsoft.com/pt-br/library/ms714395(v=vs.85).aspx .


It is important to know that new cmdlets or features are only available in the latest versions of the operating system. The latest stable version of WMF is 5.1 which includes:
  • New cmdlets: local users and groups; Get-ComputerInfo;
  • PowerShellGet improvements include enforcing signed modules, and installing JEA modules;
  • PackageManagement added support for Containers, CBS Setup, EXE-based setup, CAB packages;
  • Debugging improvements for DSC and PowerShell classes;
  • Security enhancements including enforcement of catalog-signed modules coming from the Pull Server and when using PowerShellGet cmdlets;
  • Responses to a number of user requests and issues;
WMF Compatibility



WMF 2.0WMF 3.0WMF 4.0WMF 5.0WMF 5.1
Windows XP YesNoNoNoNo
Windows Server 2003YesNoNoNoNo
Windows VistaYesNoNoNoNo
Windows 7 SP1YesYesYesYesYes
Windows Server 2008 SP2Yes
Yes
(Expect IA64)
NoNoNo
Windows Server 2008 R2 SP1Yes
Yes
(Expect IA64)
YesYesYes
Windows 8YesYesYesYesYes
Windows 8.1YesYesYesYesYes
Windows Server 2012 SP1YesYesYesYesYes
Windows Server 2012 R2YesYesYesYesYes
Windows 10YesYesYesYesYes
Windows Server 2016YesYesYesYesYes


As of August 18, 2016 Windows PowerShell became Open-Source which means you can run on MacOS and some Linux distributions. The PowerShell team is using GitHub so anyone can contribute with the project at https://github.com/powershell .

PowerShell Gallery
The PowerShell Gallery is the central repository for PowerShell content. New PowerShell or Desired State Configuration (DSC) commands are present. 

Before you start you must register in https://www.powershellgallery.com/ with a Microsoft account that will be used for publishing.

PowerShell Gallery Login



By accessing your account you can verify that you have an API key and it is this key that is used for submission.
 
PowerShell Gallery - My Account


Script Creation
Before starting the script you need to create the block that includes the script information with the cmdlet 'New-ScriptFileInfo'.  The block will contain the version, GUID that is automatically generated, author, required information and script dependencies.

If you already have a script created add the PSScriptInfo body at the beginning of the script.

cmdlet New-ScriptFileInfo

 
Testing the script
The cmdlet 'Test-ScriptFileInfo' checks the comment block if it has an error it will tell you where it is located or how to fix it.

 
cmdlet Test-ScriptFileInfo


As you can see in the image, no error was displayed and can be sent. The following image has a purposeful error in which a variable is not defined and can not be sent until the error is corrected.



Script publishing
With the tested script you can now publish it to publish you need the API key that you can query in your account.  To publish, use the Publish-Script cmnlet.

Publish-Script -Path <localização do script> -NuGetApiKey <chave API>

An important rule is that the name  of the script must be unique if you try to publish a script with the same ID will return an error and is required to rename the script. 


cmnlet Publish-Script


Manage the script in the gallery
In your Manage My Items account you can manage all submitted modules or scripts. 


You can edit the contents of the script.




The gallery also has the chance to delete the script but is not yet supported by the gallery what it can do is remove the script from the searches.



With successful publishing the script is visible and searchable in the Web Gallery comes as in PowerShell. The gallery hypothesis to save the script without installing with the 'Save-Script' cmldet. If someone wants to install you can use the cmdlet 'Install-Script'.




There is no restriction for publication but you have to be careful that the script or module you want to publish does not contain any sensitive information such as logins, passwords, keys for database links.

Even if the script has passed the tests it is always important to review and test the script before publishing. If it is possible to do it on another machine. 

14 March 2017

Webcast Microsoft Windows Server 2016: the Cloud-ready operating system

On March 16, 2017 you can participate in the Webcast "Microsoft Windows Server 2016: The Cloud-ready operating system" between 16:00 - 18:00 WET through Rumos Live Traning with the trainer Pedro Ferreira Pereira.


This webcast aims to address the Windows Server 2016 news, as well as the course of certification exams to achieve MCSA: Windows Server 2016. 
  • Introduction to exams to achieve MCSA certification: Windows Server 2016.
  • New features of Windows Server 2016.
You can subscribe here: https://www.eventbrite.pt/e/bilhetes-microsoft-windows-server-2016-o-sistema-operativo-cloud-ready-31228289655  .

 The language of the Webcast will be in Portuguese.

Sobre o Webcast 
The Webcast is carried out by the companies of Grupo Rumos , Rumo, Galileu, Flag, Profitecla, Escola Digital Rumos, Escola Professional Braga and Escola Professional Ruiz Costa. 

Cost
It's totally free just have to register in the webcast that Eventbrite is used. You can check the previous events here: https://www.eventbrite.pt/o/rumos-s-a-7582499537?past=1 and view the videos in http://www.livetraining.pt/arquivo.html

Platform 
The webcast uses the Adobe web conferencing platform better known as Adobe Connect and its use is not complicated. You only need to enter the room and take the verification and compatibility test on your computer. To ensure that you can see the video signal and image.


You can ask the speaker all the questions and talk to other participants who are present.



Video and audio quality
It all depends on the speaker's upload. Unfortunately, they do not use a isolated connection for the Webcast. In the last webcast I saw that it was "Be a Game Developer" their upload was so bad that the link was always falling, the voice always failing and it was not possible to follow up with the speaker. Sometimes the speaker did not realize that the voice was not being transmitted and missed a large part of the webcast. 



Even if you can not see the webcast until the end, you will receive an email with  an Internet address that allows you to view the webcast recording, and you may also receive a discount voucher. 

If you want to know more about the webcast of the Grupo Rumos, visit the official web page at www.livetraining.pt.