The Deployment Bunny

OS Deployment, Virtualization, Microsoft based Infrastructure…

  • Archives

  • Meta

Archive for the ‘PowerShell’ Category

Nice to Have – Ilo Connect

Posted by Mikael Nystrom on November 5, 2018

image
Ilo Connect.

Working in the lab, lots of HPE servers, yes I use ILO. However, using the ILO webpage is to slow, using the command line is to messy, and setting up the BIG HPE solution is out, no, let us spend one hour to create a PowerShell script that reads data from a XML file, present a button with connect, saves me lot’s of time. In the background it uses the stand alone ILo connect, that you need to download from HPE first. Here it is Ilo Connect.

Get it from GitHub – https://github.com/DeploymentBunny/IloConnect

/Mike

Posted in Nice to Have, PowerShell | Tagged: , | Leave a Comment »

Nice to Know – Classroom Connect

Posted by Mikael Nystrom on November 5, 2018

image
The Classroom Connect tool.

Classroom Connect

Me and Mr. Johan Arwidmark was working on a class room solution. In such solution there is a reason to be able to connect, and there are few built in to Windows 10 and Windows Server 2016.

Remote Desktop

Absolutely needed for poking around but does not solve all scenarios.

Remote Desktop using a shadow session

This is great, it connects to the host and then does a shadow session for the logged-on student

Remote Assistance

A nice feature, but it does require the end user accept a connection from the helper

Command line utility = Scriptable

All method above can be used with command line tools, and that gives us the ability to create some nice scripts, but to make it a bit finnier, lets do it as a UI in PowerShell. The only trick we had, was that a shadow copy is connected to a session, and since the built-in RDS PowerShell tools cannot be used, since we don’t have a “solution” deployed, we found a way to use qwinsta.exe and then filter the result to find the student name when it matches the machine name, and hey, we have the session ID and now we can connect using mstsc.exe using /shadow

So, after spending one hour on a Sunday evening at a hotel in Phoenix, here is Classroom Connect.

Get it from GitHub – https://github.com/DeploymentBunny/ClassroomConnect/

/mike

Posted in Nice to Have, PowerShell | Tagged: , | Leave a Comment »

Nice to Know – Learn PowerShell from Windows Admin Center

Posted by Mikael Nystrom on October 16, 2018

Windows Admin Center is great, it is actually fantastic to be honest. I have been working with it for a long time and in one of the latest releases the have added something really cool.

The ability to “borrow” PowerShell code that are being used by Windows Admin Center, the one symbol you are looking for is this:

image

a very tine, but very nice improvement. and if you select it, you will see this:

image

As you can see Windows Admin Center shows one function that you can copy and use, but if you use the dropdown list, hey, there is an entire list of nice functions to use as you can see

image

Not only that, each separate solution in each separate node has its own list (some are still empty), but, here you go, use it!

Download Windows Admin Center and start copy code (or use it as is) http://aka.ms/WACDownload

/mike

Posted in PowerShell, Windows Admin Center | Tagged: , | Leave a Comment »

Nice to Know – GUI based Tool to completely remove a virtual machine from a Hyper-V host, including all files (update 1)

Posted by Mikael Nystrom on September 21, 2018

I have had this tool for some years, but without a UI, working with customer, they need to ability to build and remove virtual machines on each dev computer, so I created it.

– Update: The tool will now remove all snapshots in a smart “non waiting” way as requested by a friend of mine.

image

It is pretty simple to use, select and delete, done.

I did a recording on how to use the tool:

image

You can download it from https://github.com/DeploymentBunny/Files/tree/master/Tools/RemoveVMwUI

/Mike

Posted in Hyper-V, PowerShell | Tagged: , | Leave a Comment »

PowerShell is King – New-VIARandomPassword

Posted by Mikael Nystrom on April 6, 2017

Long time ago i needed a function that creates random passwords that can be used when creating accounts, we have been using this for a long time, a few minutes ago Johan Arwidmark asked where the script is. The answer is, it is in one of the modules that I have on GitHub

Link to the module: https://github.com/DeploymentBunny/Functions/blob/master/VIAUtilityModule.psm1

You download it, import it an then you have a new command

New-VIARandomPassword

Import-Module C:\Setup\Functions\VIAUtilityModule.psm1
New-VIARandomPassword -PasswordLength 15
New-VIARandomPassword -PasswordLength 15 -Complex $true

 

image

Very easy to use, you can select to do it standard or complex and if you need many of them just loop it.

/mike

Posted in Functions, PowerShell | Tagged: , | Leave a Comment »

PowerShell is King – Building a Reference Image Factory (v 3.2)

Posted by Mikael Nystrom on February 23, 2017

The Image Factory has been re-worked and updated. It also has moved to GitHub https://github.com/DeploymentBunny/ImageFactoryV3ForHyper-V/

Concept and flow

The idea is the same, we use MDT, create refimages task sequences that runs without any questions. A PowerShell script will grab all enabled Task Sequences in a specified folder, create a VM for each of them. Grab the Bios Serial number from each om them, update customsettings ini with that information, start the VM’s (number of concurrent VM’s determine how many VM’s can run at the same time, wait until all VM’s are done and finally removes all VM’s for a cleanup process. You can run the script as is (if you store it in C:\Setup\ImageFactoryV3ForHyper-V on you MDT server), or you can open it in ISE and run section by section to see what happens.

The XML file (C:\Setup\ImageFactoryV3ForHyper-V\ImageFactoryV3.xml)

Is a control file for settings, pretty straightforward, just make sure that all values are correct.

image

The Script C:\Setup\ImageFactoryV3ForHyper-V\ImageFactoryV3-Build.ps1

The script contains some functions and logic, each section is described so you do know what it does. There are switches to the script,

  • -UpdateBootImage
  • -EnableMDTMonitoring
  • -TestMode

UppdateBoot image $True, updates the bootimage before copy, EnableMDTMonitoring require that MDT monitoring is enabled of the deployment share and testmode is not yet working (I’ll get back on that)

image

The PSINI Module

One big change is that instead of using a hack, (using KVP) I switched over to use a module called PSINI, it basically turns customsettings.ini into a hash table, making it easy to configure using PowerShell. That also means you need to download that module from TechNet Gallery http://gallery.technet.microsoft.com/scriptcenter/ea40c1ef-c856-434b-b8fb-ebd7a76e8d91and all credit for that module goes to http://oliver.lipkau.net/blog

Have Fun

/Mike

Posted in MDT, PowerShell, Reference Image | Tagged: , , | 26 Comments »

Nice to Know – The Deployment Bunny is now on GitHub

Posted by Mikael Nystrom on November 25, 2016

I have been on GitHub for a while, but lately I have started to move everything I do to GitHub, for various reasons. One is that is easier for you to get the files directly, another is that I get source control. But there are many more reasons for this. There are many different repositories, the two main repositories are Functions and The Bunny Files and when I do demo script they will usually end up in the Demo Script folder.

image
The Bunny at GitHub.

Can I “Steal” your script?

Yes, you can, but it would be nice to get cred for the work, so include the link to the blog or to the GitHub repository. However, I don’t like to see my scripts ending up in PowerShell Gallery or the TechNet Gallery without asking me first…

How can I use the scripts directly from my scripts?

That is easy, you do something like this:

Invoke-WebRequest "https://raw.githubusercontent.com/DeploymentBunny/Files/master/Tools/Enable-NestedHyperV/EnableNestedHyperV.ps1" -OutFile ~/EnableNestedHyperV.ps1
Import-Module ~/EnableNestedHyperV.ps1
Enable-NestedHyperV -VMname TEST100

How will this affect the future?

This basically means that everything I do will end up at GitHub first and later most of this will then have a related blogpost, but not all, and not the same day.

/mike

Posted in GitHub, PowerShell | Tagged: , | 5 Comments »

Working in the Datacenter – I need to know everything about my VHD’s in my SCVMM environment

Posted by Mikael Nystrom on November 25, 2016

I was asked about getting more information about all the VHDs in a SCVMM environment (you now how you are). It is actually easy to do this, so i created a function that uses the SCVMM PowerShell module to grab all data and does a calculation on the expansion rate in percent for all disks, it pretty much gives you this:

image
Result.

The result will be that you now know where they are, sizes, expansion, type, parents, and some more info as well, and if you know, you can act.

You can grab the module from GitHub: https://github.com/DeploymentBunny/Files/tree/master/Tools/Get-VIASCVMMDiskInfo

/mike

Posted in PowerShell, System Center 2012 R2, System Center 2016, System Center Virtual Machine Manager | Tagged: , , , | Leave a Comment »

PowerShell is King – Find VM Configuration files (.vmcx) that have not been imported/registered

Posted by Mikael Nystrom on November 9, 2016

Sometime you need to move a large number of VMs, or you need to recover from a broken hyper-v host, or similar. If you have a few VM’s, that will be easy, but if you have many you will most likely use PowerShell to import the VM’s. That works perfectly fine, but you have a few VM’s that did weren’t imported correctly you will end in a state when you ask your self –Which VM’s are imported and which ones are not?

(You can download the script from GitHub: https://github.com/DeploymentBunny/Files/tree/master/Tools/Get-VIAUnimportedvmcxFiles )

Find the not yet imported VM configurations

That will of course be done using PowerShell, and here is the function that I use

image
Script and output.

Function Get-VIAUnimportedvmcxFiles
{
    <#
    .Synopsis
        Script used find not yet imported Hyper-V Configurations
    .DESCRIPTION
        Created: 2016-11-07
        Version: 1.0
        Author : Mikael Nystrom
        Twitter: @mikael_nystrom
        Blog   : http://deploymentbunny.com
        Disclaimer: This script is provided "AS IS" with no warranties.
    .EXAMPLE
        Get-VIAUnimportedvmcxFiles
    #>    
    [CmdletBinding(SupportsShouldProcess=$true)]
    
    Param(
    [string]$Folder
    )

    if((Test-Path -Path $Folder) -ne $true){
        Write-Warning "I'm sorry, that folder does not exist"
        Break
    }

    $VMsIDs = (Get-VM).VMId
    $VMConfigs = (Get-ChildItem -Path $Folder -Filter *.vmcx -Recurse).BaseName

    $obj = Compare-Object -ReferenceObject $VMsIDs -DifferenceObject $VMConfigs

    $Configs = foreach($Item in ($obj.InputObject)){
        $Items = Get-ChildItem -Path $Folder -Recurse -File -Filter *.vmcx  | Where-Object -Property Basename -Like -Value "*$Item" 
        $Items | Where-Object -Property FullName -NotLike -Value "*Snapshots*"
        }
    Return $Configs.FullName
}

/mike

Posted in Hyper-V, PowerShell | Tagged: , | Leave a Comment »

PowerShell is King – Find VHDs that are not connected to a VM

Posted by Mikael Nystrom on November 8, 2016

Working with VM’s in Hyper-V means that you will eventually have VHD’s that are not connected, not not even in use. That happens when you remove the VM configuration from Hyper-V manager, but you told your self “I will remove the data files later”, later very rarely happens, at least not for my lab and my demo environment (in production we use SCVMM and this issues is much less). In many cases this consumes space and I can use that space for other purposes.

(The script is available at GitHub: https://github.com/DeploymentBunny/Files/tree/master/Tools/Get-VIADisconnectedVHDs)

Get-VM, Get-ChildItems and Compare-Object solves the problem

Here is a function that will return an array of files from a folder you specify that is not directly connected to a VM.

image
In this case one disk is returned and this disk is not in use.

Function Get-VIADisconnectedVHDs
{
    <#
    .Synopsis
        Script used find .VHD files that are not connected to VM's
    .DESCRIPTION
        Created: 2016-11-07
        Version: 1.0
        Author : Mikael Nystrom
        Twitter: @mikael_nystrom
        Blog   : http://deploymentbunny.com
        Disclaimer: This script is provided "AS IS" with no warranties.
    .EXAMPLE
        Get-Get-VIADisconnectedVHDs
    #>    
    [CmdletBinding(SupportsShouldProcess=$true)]
    
    Param(
    [string]$Folder
    )

    if((Test-Path -Path $Folder) -ne $true){
        Write-Warning "I'm sorry, that folder does not exist"
        Break
    }

    #Get the disk used by a VM
    $VMs = (Get-VM | Where-Object -Property ParentSnapshotName -EQ -Value $null).VMId

    if(($VMs.count) -eq '0'){
        Write-Information "Sorry, could not find any VM's"
        Break
    }
    $VHDsActive = foreach($VMsID in $VMs){
        Get-VMHardDiskDrive -VM (Get-VM -Id $VMsID)
    }

    #Get the disk in the folder
    $VHDsAll = Get-ChildItem -Path $Folder -Filter *.vhd* -Recurse
    if(($VHDsAll.count) -eq '0'){
        Write-Information "Sorry, could not find any VHD's in $folder"
        Break
    }

    $obj = Compare-Object -ReferenceObject $VHDsActive.Path -DifferenceObject $VHDsAll.FullName

    #Compare and give back the list of .vhd's that are not connected
    Return ($obj | Where-Object -Property SideIndicator -EQ -Value =>).InputObject
}

/Mike

Posted in Hyper-V, PowerShell | Tagged: , | Leave a Comment »