Tag: Module

Updated PowerShellGet and PackageManagment

Update PowerShellGet and PackageManagement

Since I am just setting up a new work machine, I wanted to share some information how you can update PowerShellGet and PackageManagement to the latest version. This will give you the usual bug fixes and performance enhancements. Since you don’t get the latest version in Windows PowerShell nor PowerShell Core, you will need to update it manually.

PowerShellGet is a PowerShell module with commands for discovering, installing, updating and publishing the PowerShell artifacts like Modules, DSC Resources, Role Capabilities and Scripts. For example you use PowerShellGet to install the Azure PowerShell module, or other modules.

PowerShellGet module is also integrated with the PackageManagement module as a provider, users can also use the PowerShell PackageManagement cmdlets for discovering, installing and updating the PowerShell artifacts like Modules and Scripts.

(source: GitHub)

How to update PowerShellGet and PackageManagement

Updating to the latest version of PowerShellGet and the PackageManagement module is simple. Since both modules are part of the PowerShell Gallery, you can update them using a couple of simple commands.

You can find both modules in the PowerShell Gallery:

First lets check which versions of the modules you have available. If you use Update-Module, it will automatically load PowerShellGet and PackageManagement and list them as loaded PowerShell modules. Of course you can also use Get-Module -ListAvailable.

PowerShell Modules PowerShellGet and PackageManagement

 
Get-Module -ListAvailable PackageManagement, PowerShellGet

As you can see, In my default installation, I got PowerShellGet version 1.6.7 and PackageManagement 1.1.7.2. If you have a look at PSGallery, you will see that these are pretty old versions and that there are newer available.

To get the latest version from PowerShell Gallery, you should first install the latest Nuget provider. You will need to run PowerShell as an Administrator for all  the following commands.

 
Install-PackageProvider Nuget –Force
Exit

If you run PowerShell 5.0 or newer, you can install the latest PowerShellGet using the following command. PowerShell 5.0 is included in Windows 10, Windows Server 2016, Windows Server 2019, any system with WMF 5.0 and 5.1 or a system running PowerShell 6.

 
Install-Module –Name PowerShellGet –Force
Exit

Two quick tips, first of, you will need to set the execution policy to RemoteSigned to allow the new module to run. Secondly in some cases you will need to use the -AllowClobber parameter to install the updated version of the module.

 
Set-ExecutionPolicy RemoteSigned
 
Install-Module –Name PowerShellGet –Force -AllowClobber

You can then use Update-Module to get newer versions:

 
Update-Module -Name PowerShellGet
Exit

Updated PowerShellGet and PackageManagment

After that you will see the latest versions of PowerShellGet and PackageMangement available

If you run older versions of PowerShell you can check out the full documention on the PowerShell Docs. I hope this blog post helps you to update PowerShellGet and benefit from the latest versions. If you have any questions, please let me know in the comments.



Install Azure PowerShell Az Module

How to Install the Azure PowerShell Module

This blogs post describes how you can install the Azure PowerShell module. Microsoft a couple of weeks ago released version one of their new Azure PowerShell module on .NET Core called the Az module. The Az module will replace the AzureRM module over time. however, the AzureRM module is still supported. The new Az module is a cross-platform module.

Well if you are working with Microsoft Azure you may need the PowerShell Modules for automation and some settings which are only available in PowerShell. With the latest releases you can install the Azure PowerShell Module using the package management in PowerShell, and install the Azure PowerShell module form the PowerShell Gallery.

Az module features

  • Az is a replacement for AzureRM and AzureRM.Netcore.
  • Runs on PowerShell 5.1 and PowerShell Core.
  • It is always up to date with the latest tooling for Azure services.
  • Az ships in Cloud Shell.
  • It shortens and normalizes cmdlet names. All cmdlets use “Az” as their noun prefix.
  • Az will simplify and normalize module names. Data plane and management plane cmdlets for each service will use the same Az module.
  • It ships with new cmdlets to enable script compatibility with AzureRM (Enable/Disable-AzureRmAlias).

Supported platforms

  • PowerShell 5.1 – Windows 7 or greater with .Net Framework 4.7.2 or greater installed
  • PowerShell Core 6.0 – Windows, Mac OS, Linux
  • PowerShell Core 6.1 – Windows, Mac OS, Linux

Install Azure PowerShell module

For me using the PowerShell Package Management and the PowerShell Gallery is may the easiest and fastest way to install it. In Windows 10 or a computer with the Windows Management Framework 5 installed, you can use the following PowerShell cmdlets to install it.

You should not install Az side-by-side with AzureRM. Remove all AzureRM modules before installing Az.

 
Install-Module Az

You can also update the AZ module using the following command:

 
Update-Module Az

And you can use the following command to login:

 
Connect-AzAccount

You can also see the Azure PowerShell Modules and versions using the PowerShell Package Management:

 
Find-Module -ListAvailable *Az*

AzureRM compatibility

If you would like to run scripts developed for AzureRM using Az, use the Enable/Disable-AzureRmAlias cmdlets to add or remove aliases from AzureRM cmdlets to Az cmdlets.

This can be enabled and disabled:

 
Enable-AzureRmAlias
 
Disable-AzureRMAlias

Run Azure PowerShell from Cloud Shell

You can also run the latest Azure PowerShell module version directly from Cloud Shell, with no need to install it.

This blog post was updated with the release 1.0.0 of the Azure Az module based on .NET Core. You can find more about the new Azure PowerShell module on the GitHub repo.

Also check out my blog post: Mastering Azure using Cloud Shell



Import MSOnline PowerShell Module

Manage Windows Azure AD using Windows PowerShell

Well I am a huge fan of Microsoft Office 365 and we are not only using this in our company, I am also using Office 365 for my mothers restaurant. It helps us organzise stuff very easily and allows us to work from everywhere. Now the great thing about using Office 365 and Windows Azure Active Directory it that I can manage it with the same management tools I also use for my on-premise Active Directory. My favorit is of course Windows PowerShell.

To manage Windows Azure Active Directory with PowerShell, where also your Office 365 users are stored, you have to do some simple steps.

First make sure you have installed the .NET Framework 3.5 on your management machine.

Enable-WindowsOptionalFeature -FeatureName NetFx3

Install Microsoft Online Services Sign-in Assistant: Install the appropriate version of the Microsoft Online Services Sign-in Assistant for your operating system from the Microsoft Download Center. Microsoft Online Services Sign-In Assistant for IT Professionals RTW.

Install Windows Azure AD Module for Windows PowerShell: Install the appropriate version of the Windows Azure AD Module for Windows PowerShell for your operating system from the Microsoft Download Center:

Import the MSOnline Windows PowerShell module

Import-Module MSOnline

Import MSOnline PowerShell Module

Connect to your Windows Azure Active Directory Tenant or your Office 365 Tenant:

Connect-MsolService

This will open a popup windows where you have to enter your credentials.

Now now you can start working with your Windows Azure Active Directory.

Connect Windows Azure AD via PowerShell



Hyper-V: “Version 3 kills them all”

Windows Server 8 Server Manager Dashboard

Microsoft showed the latest version of Hyper-V at build conference together with Windows 8 and Windows Server 8. Microsoft showed a lot of new Hyper-V features which turn Hyper-V in really powerful hypervisor.

Some days ago I posted a blog post about new features which Microsoft showed before the build conference, now it’s time to extend the list of new features. There are a lot of even more powerful features than the once I posted back then.

Windows Server 8 as Cloud OS

First let’s start with Windows Server 8 as the base of Microsoft Cloud strategy. Microsofts focus in Windows Server 8 was to make it easy for all to build public and private cloud solutions. There are a lot of improvements to manageability, security, scalability, extensibility, predictability and reliability which will also improve the possibilities with Hyper-V. In technical terms Microsoft made a lot of improvements how you can manage a lot of servers and services, Storage, Networking and Powershell. Of course there is a lot more, but this are the parts I think are the most important. And here are some keywords to the improvements in Windows Server 8:

  • Storage improvements – SMB 2.2, SMB transparent Failover, Data deduplication, Storage Spaces, online filesystem repairs, 64TB NTFS volume etc.
  • NIC Teaming
  • Powershell v3 – You can now just do everything in Powershell and even more with 23000 PowerShell cmdlets.
  • Server Dashboard – The new Dashboard lets you manage all servers, or even better, all Services from one place.
  • Multi-tenant – everything seems to be made for that
  • Performance Counters

Windows Server 8 Hyper-V Manager

Hyper-V Host improvements

Hyper-V gets not only a lot of improvements to Virtual Machine, also the Hyper-V Hosts get some new limit improvements.

  • up to 160 logical CPUs
  • supports up to 2TB RAM
  • no more vCPU:pCPU ration limit

Hyper-V Virtual Machine improvements

Microsoft did a lot to extend the existing Virtual Machine hardware to support even high workload Virtual Machines. I will not write a lot about this because the facts here will tell more that a lot of words.

  • VHDX Format – supports up to 64TB Virtual Disks
  • 32 CPUs per VM
  • 512GB RAM per VM
  • Support for Fibre Channel Adapters
  • Supporting Virtual Active Directory Servers

Hyper-V Networking improvements

Hyper-V got a lot of improvements in terms of networking. Microsoft realized that networking features are really important if you start to create private and public cloud scenarios and now even create a mix of public and private cloud scenarios without creating a lot of work for the IT teams to reconfigure Virtual Machines.

  • QoS and flexible bandwidth allocation
  • Support for SR-IOV (Direct Access to the physical Network adapter)
  • Network Virtualization
  • PVLAN support
  • Dynamic Virtual Machine Queue (D-VMQ)
  • Receive Side Coalescing (RSC)
  • DHCP Guard
  • Extensible virtual switch
  • IPsec Task offload

Hyper-V Clustering improvements

Hyper-V gets also a lot of Cluster improvements. But you have to be aware that Clusters are for really high availability and this adds a lot of costs to projects and solutions. Microsoft is working on Cloud solutions which will give great availability to low cost. For example Hyper-V Replica or Live Migration to another host over the Ethernet without the need for a shared storage. But if you need real HA you will need the Failover Cluster.

  • supporting up to 4000 VMs per cluster
  • supporting up to 64 Cluster nodes
  • improved Cluster Manager Console
  • VM Monitoring – Application health detection inside the virtual machine
  • New Placement policies – Virtual Machine Priority and enhanced placement
  • Storage Live Migration
  • Hyper-V Replica supporting clustering
  • No need for Block Storage – you can use SMB Shares
  • Support for Storage Spaces
  • Automated Node Draining – like Maintenance mode in SCVMM
  • Cluster Aware Updating (CAU)
  • Cluster Shared Volume Improvements – BitLocker support, a lot of performance improvements, Self-Healing
  • Live Migration Queing
  • Migrate multiple Virtual Machine at the same time

Windows Server 8 Hyper-V VM Move

Hyper-V Storage improvements

A I mentioned earlier Microsoft made a lot of improvements in terms of storage in Windows Server 8 and Hyper-V can take advantage of those which are quiet impressive. For example with the new features in SMB 2.2 you can now use SMB file shares to store your Virtual Machines.

  • VHDX
  • ODX
  • RDMA
  • SMB 2.2 – Transparent Failover
  • 4K native disk support
  • Data Deduplication
  • Virtual Fiber Channel
  • VM boot from SAN

Hyper-V Management Improvements

As everywhere in Windows Server 8 PowerShell is the key. And the new Server Manager Dashboard Microsoft enable to create Server Groups to manage multiple servers from a single console.

  • Powershell for Hyper-V
  • Powershell Workflows – Commands and Tasks across servers
  • Hyper-V Extensible Switch – lets vendors to create “plugins”. Could be very interesting for Cisco UCS installations.
  • Server Manager Dashboard – lets you manage multiple Hyper-V host from a single console.
  • SCVMM 2012 – not a part of Windows Server 8 but will add great management solutions

Windows Server 8 Hyper-V Powershell

Hyper-V HA and Data Protection

Now I think this is maybe the greatest new feature. You can now live migrate a Virtual Machine from one Hyper-V Host to another without Shared Storage or Cluster configuration. And with this option Microsoft also included a new feature called Hyper-V Replica which includes the option to replicate Virtual Machine to another host which can be hosted in the same network or even in the cloud.

  • Live Migration
  • Live Storage Migration
  • Live Migration to another Hosts (Not clustered) over the Ethernet
  • Hyper-V Replica – Replicated Virtual Machines to another Hyper-V host on-premise or public cloud
  • BitLocker support for CSV

This are not all of the new features Windows Server 8 Hyper-V has to offer but I tried to list the important ones. And if Microsoft sticks with their licensing model, it will be a really strong competitor to the VMWare vShpere 5.

 



office365 powershell

Office 365 – How to connect with Powershell

In Office 365 you can do and automate a lot with Windows Powershell. Now this small post shows you how you can connect to Office 365 with Powershell.

  1. Install the Microsoft Online Services Sign-In Assistant
    32-bit
    64-bit
  2. Install the Microsoft Online Services Module for Windows PowerShell
    32-bit
    64-bit
  3. Open Powershell and import the MsOnline Module or use the desktop shortcut which was created by the installer.
    Import-Module MsOnline
  4. Connect to your Microsoft Office 365 account
    Connect-MsolService

    Use your Office 365 LiveID to login (for example [email protected])

  5. Now you can start working with Windows Powershell in your Office 365 account, if you need some more help about the available Powershell cmdlets you can list them with
    Get-Command -Module MsOnline


How to create a Powershell v2 Module

Powershell Header

If you need some functions a lot in different scripts you create maybe external function files. This is a good way to clean up your code. To get this functions running in your mainscript.ps1 you can call this other file “dotsourced”:

. C:\PSscript\output\sayhello.ps1

If you have more than one external function you have to call each file:

. C:\PSscript\Modules\Output\sayhello.ps1
. C:\PSscript\Modules\Output\saygoodday.ps1
. C:\PSscript\Modules\Output\saybye.ps1

In Powershell v2 you can create your own modules, which you can call by:

Import-Module C:\PSscript\Modules\Output

Now how can you create this output module?

  • First you create a directory for the all modules, called Modules
  • Secound you create a directory for the Output module, called Output
  • Than copy all of your Powershell Scripts (.ps1 files) in to this folder
  • Now create a file called Output.psm1. Its important that this file has the same name as the folder
  • In this file write the following code (for each file in this folder):
    . ./Modules/Output/sayhello.ps1
    . ./Modules//Output/saygoodday.ps1
    . ./Modules//Output/saybye.ps1

Now you can use the Import-Module to import your own module called output.

There are a lot of other things you can use to make everything a little bit easier, like system variables for the module and script paths.