The Deployment Bunny

OS Deployment, Virtualization, Microsoft based Infrastructure…

  • Archives

  • Meta

Archive for the ‘PowerShell’ Category

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 switches 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: , , | 14 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 »

PowerShell is King – Find out what Differencing disks that are in use

Posted by Mikael Nystrom on November 7, 2016

I use Hyper-V, in both production as well as for lab. One very effective way to spin up systems very fast is to use differencing disks, it also saves space. So I use differencing disks basically. After a while you tend to have some VM’s in your environment, and when it comes to a lab environment, well lets put it this way, I have disks all over the place.

(The function is on GitHub: https://github.com/DeploymentBunny/Files/tree/master/Tools/Get-VIAActiveDiffDisk)

I need to know what Parent hard drives that are active and in use

So, PowerShell to the rescue. First we get all hard disks that are connected to any of my VM’s, then we grab each disk that has a parent disk, an then we present that. That should give me a list of what parent disks are actually used.

   
Function Get-VIAActiveDiffDisk{
    <#
    .Synopsis
        Script used to Deploy and Configure Fabric
    .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-VIAActiveDiffDisk
    #>    
    [CmdletBinding(SupportsShouldProcess=$true)]
    param(
    )

    $VMHardDiskDrives = Get-VMHardDiskDrive -VM (Get-VM)
    $ActiveDisks = foreach($VMHardDiskDrive in $VMHardDiskDrives){
        $Diffs = Get-VHD -Path $VMHardDiskDrive.Path | Where-Object -Property VhdType -EQ -Value Differencing
        $Diffs.ParentPath
    }
    $ActiveDisks | Sort-Object | Select-Object -Unique
}

On my laptop that gives the the following return:

image
The output.

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

PowerShell is King – Generate an array of server names, with the same length and the same prefix

Posted by Mikael Nystrom on November 4, 2016

Basic Idea and Challenge

PowerShell is all about automation, and creating a loop in PowerShell that creates an array of numbers is easy, add a prefix to that and hey you have an array

   
1..10 | ForEach-Object {"LC-SRV-" + $_}    

image
The output.

The Magical -F

But, there is a small issue, the names of the server names that i need to be generated is kind of correct, but wrong, or “almost” great, I need the length to be the same. That can be fixed by using the magical –f.

   
1..10 | ForEach-Object {"LC-SRV-{0:D3}" -f $_}    

image
The Output.

The Function

So, now it looks the way I need it to be, and if you need to use it often, let’s create a function for it.

   
Function Create-VIAComputerName{    
Param(    
$ComputerPrefix,    
$LowNumber,    
$HigNumber    
)
  
$Servers = $($LowNumber..$HigNumber| ForEach-Object {"$ComputerPrefix{0:D3}" -f $_})   
Return $Servers    
}
  
Create-VIAComputerName -ComputerPrefix LC-SRV- -LowNumber 1 -HigNumber 64   

 

image
The Output.

/mike

Posted in PowerShell | Tagged: | Leave a Comment »

OSD – BIOS upgrade during OS Deployment in MDT/ConfigMgr (v3)

Posted by Mikael Nystrom on July 20, 2016

This is the third version of the script solution; it is very simple. You detect make/model in any way you would like to, create a rule based on BIOS version, if the rule match, nothing happens, otherwise it runs any command you want. That said, you could use this for other task as well. Most common question is “does it work with any Make/Model”`No, there are some vendors that does not provide the ability to run a BIOS upgrade silently without reboot without control, that is, the darn thing reboots immediately and that usually breaks the Task Sequence. I have one thing for those vendors to say “Shame on you!”

here are older posts on the subject

https://deploymentbunny.com/2011/05/20/step-by-step-upgrading-bios-during-litetouch-deployment-for-dell-hewlett-packard-and-lenovo/

https://deploymentbunny.com/2013/12/16/step-by-step-upgrading-bios-during-litetouchzerotouch-deployment-for-dell-hewlett-packard-and-lenovo-v2/

Detect the Model

The detection in the script is actually whatever you want, it is just a “If-then”  here are two sample lines detection that you will find in the script

if($((Get-WmiObject Win32_ComputerSystem).model) -eq 'HP EliteBook 8560w'){}
if($ModelAlias -eq 'HP EliteBook 8460p'){}

Use the detection method for each model you like, very simple

Detect the BIOS version

This is also not that hard, here are 2 sample lines from the script

if($((Get-WmiObject Win32_Bios).SMBIOSBIOSVersion) -ne '68SCF Ver. F.63'){}
if($((Get-WmiObject Win32_Bios).SMBIOSBIOSVersion) -ne '786G1 v01.27'){}

Store the upgrade files

The upgrade files are stored with the model name, like this:

image

The Silent Command

You also need to figure out the command, not really hard, download the bios upgrade, read how to run it from a command line, update the script and you are done, here is a sample of one of those sections.

$Exe = 'hpqflash.exe'
$Location = "$SCRIPTDIR\Source\HP EliteBook 8460p"
$Executable = $Location + "\" + $exe
Set-Location -Path $Location
Invoke-Exe -Executable "$Executable" -Arguments "/s /f 68SCE.CAB" –Verbose

Run the script

in MDT you can import the folder with the script as a application and set this as the command line:

PowerShell.exe -ExecutionPolicy Bypass -File Install-BIOSUpgrade.ps1

In ConfigMgr you can import this as a Package and then run the command line the same way

It is also possible to run this outside of a task sequence if you like, it works as a stand alone script, however, you cannot use the integration with MDT of course.

If you want it is possible to add a custom property in customsettings.ini, something like “NeedReboot”, then you can add the following to happen if the BIOS has been upgraded

$tsenv.Value(“NeedReboot”) = “YES”

If you then in the step after this, set a condition on a reboot step, well then it will reboot when needed, otherwise not, you can read about that in one of my old postings here

https://deploymentbunny.com/2013/12/16/step-by-step-upgrading-bios-during-litetouchzerotouch-deployment-for-dell-hewlett-packard-and-lenovo-v2/

The result

BiosUpgradeResult
It was needed.

BiosUpgradeResultNotNeeded
It was not needed.

The Script


Function Import-SMSTSENV{
    try
    {
        $tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment
        Write-Output "$ScriptName - tsenv is $tsenv "
        $MDTIntegration = "YES"
        
        #$tsenv.GetVariables() | % { Write-Output "$ScriptName - $_ = $($tsenv.Value($_))" }
    }
    catch
    {
        Write-Output "$ScriptName - Unable to load Microsoft.SMS.TSEnvironment"
        Write-Output "$ScriptName - Running in standalonemode"
        $MDTIntegration = "NO"
    }
    Finally
    {
    if ($MDTIntegration -eq "YES"){
        $Logpath = $tsenv.Value("LogPath")
        $LogFile = $Logpath + "\" + "$ScriptName.log"

    }
    Else{
        $Logpath = $env:TEMP
        $LogFile = $Logpath + "\" + "$ScriptName.log"
    }
    }
}
Function Start-Logging{
    start-transcript -path $LogFile -Force
}
Function Stop-Logging{
    Stop-Transcript
}
Function Invoke-Exe{
    [CmdletBinding(SupportsShouldProcess=$true)]
 
    param(
        [parameter(mandatory=$true,position=0)]
        [ValidateNotNullOrEmpty()]
        [string]
        $Executable,
 
        [parameter(mandatory=$false,position=1)]
        [string]
        $Arguments
    )
 
    if($Arguments -eq "")
    {
        Write-Verbose "Running $ReturnFromEXE = Start-Process -FilePath $Executable -ArgumentList $Arguments -NoNewWindow -Wait -Passthru"
        $ReturnFromEXE = Start-Process -FilePath $Executable -NoNewWindow -Wait -Passthru
    }else{
        Write-Verbose "Running $ReturnFromEXE = Start-Process -FilePath $Executable -ArgumentList $Arguments -NoNewWindow -Wait -Passthru"
        $ReturnFromEXE = Start-Process -FilePath $Executable -ArgumentList $Arguments -NoNewWindow -Wait -Passthru
    }
    Write-Verbose "Returncode is $($ReturnFromEXE.ExitCode)"
    Return $ReturnFromEXE.ExitCode
}

# Set vars
$SCRIPTDIR = split-path -parent $MyInvocation.MyCommand.Path
$SCRIPTNAME = split-path -leaf $MyInvocation.MyCommand.Path
$SOURCEROOT = "$SCRIPTDIR\Source"
$SettingsFile = $SCRIPTDIR + "\" + $SettingsName
$LANG = (Get-Culture).Name
$OSV = $Null
$ARCHITECTURE = $env:PROCESSOR_ARCHITECTURE

#Try to Import SMSTSEnv
. Import-SMSTSENV

# Set more vars
$Make = $tsenv.Value("Make")
$Model = $tsenv.Value("Model")
$ModelAlias = $tsenv.Value("ModelAlias")
$MakeAlias = $tsenv.Value("MakeAlias")

#Start Transcript Logging
. Start-Logging

#Output base info
Write-Output ""
Write-Output "$ScriptName - ScriptDir: $ScriptDir"
Write-Output "$ScriptName - SourceRoot: $SOURCEROOT"
Write-Output "$ScriptName - ScriptName: $ScriptName"
Write-Output "$ScriptName - Current Culture: $LANG"
Write-Output "$ScriptName - Integration with MDT(LTI/ZTI): $MDTIntegration"
Write-Output "$ScriptName - Log: $LogFile"
Write-Output "$ScriptName - Model (win32_computersystem): $((Get-WmiObject Win32_ComputerSystem).model)"
Write-Output "$ScriptName - Name (Win32_ComputerSystemProduct): $((Get-WmiObject Win32_ComputerSystemProduct).Name)"
Write-Output "$ScriptName - Version (Win32_ComputerSystemProduct): $((Get-WmiObject Win32_ComputerSystemProduct).Version)"
Write-Output "$ScriptName - Model (from TSENV): $Model"
Write-Output "$ScriptName - ModelAlias (from TSENV): $ModelAlias"

#Check Model
if($((Get-WmiObject Win32_ComputerSystem).model) -eq 'HP EliteBook 8560w'){
    Write-Output "Model is $((Get-WmiObject Win32_ComputerSystem).model)"
    Write-Output "Checking BIOS Version"
    Write-Output "Version is $((Get-WmiObject Win32_Bios).SMBIOSBIOSVersion)"
    if($((Get-WmiObject Win32_Bios).SMBIOSBIOSVersion) -ne '68SVD Ver. F.50'){
        Write-Output "Needs upgrade"
        $Exe = 'hpqflash.exe'
        $Location = "$SCRIPTDIR\Source\HP EliteBook 8560w"
        $Executable = $Location + "\" + $exe
        Set-Location -Path $Location
        Invoke-Exe -Executable "$Executable" -Arguments "/s /p LCadmin1.bin" -Verbose
    }
    else
    {
        Write-Output "No Need to upgrade"
    }
}
if($((Get-WmiObject Win32_ComputerSystem).model) -eq 'HP ProBook 6570b'){
    Write-Output "Model is $((Get-WmiObject Win32_ComputerSystem).model)"
    Write-Output "Checking BIOS Version"
    Write-Output "Version is $((Get-WmiObject Win32_Bios).SMBIOSBIOSVersion)"
    if($((Get-WmiObject Win32_Bios).SMBIOSBIOSVersion) -Like '*ICE*'){
        if($((Get-WmiObject Win32_Bios).SMBIOSBIOSVersion) -ne '68ICE Ver. F.62'){
            Write-Output "Needs upgrade"
            $Exe = 'hpqflash.exe'
            $Location = "$SCRIPTDIR\Source\HP ProBook 6570b"
            $Executable = $Location + "\" + $exe
            Set-Location -Path $Location
            Invoke-Exe -Executable "$Executable" -Arguments "/s /f 68ICE.cab" -Verbose
        }
        else
        {
            Write-Output "No Need to upgrade"
        }
    }
    if($((Get-WmiObject Win32_Bios).SMBIOSBIOSVersion) -Like '*ICF*'){
        if($((Get-WmiObject Win32_Bios).SMBIOSBIOSVersion) -ne '68ICF Ver. F.62'){
            Write-Output "Needs upgrade"
            $Exe = 'hpqflash.exe'
            $Location = "$SCRIPTDIR\Source\HP ProBook 6570b"
            $Executable = $Location + "\" + $exe
            Set-Location -Path $Location
            Invoke-Exe -Executable "$Executable" -Arguments "/s /f 68ICF.cab" -Verbose
        }
        else
        {
            Write-Output "No Need to upgrade"
        }
    }
}
if($ModelAlias -eq 'HP EliteBook 8460p'){
    Write-Output "Model is $((Get-WmiObject Win32_ComputerSystem).model)"
    Write-Output "Checking BIOS Version"
    Write-Output "Version is $((Get-WmiObject Win32_Bios).SMBIOSBIOSVersion)"
    if($((Get-WmiObject Win32_Bios).SMBIOSBIOSVersion) -Like '*SCF*'){
        if($((Get-WmiObject Win32_Bios).SMBIOSBIOSVersion) -ne '68SCF Ver. F.63'){
            Write-Output "Needs upgrade"
            $Exe = 'hpqflash.exe'
            $Location = "$SCRIPTDIR\Source\HP EliteBook 8460p"
            $Executable = $Location + "\" + $exe
            Set-Location -Path $Location
            Invoke-Exe -Executable "$Executable" -Arguments "/s /f 68SCF.CAB" -Verbose
            }
        else
            {
            Write-Output "No Need to upgrade"
        }
    }
    if($((Get-WmiObject Win32_Bios).SMBIOSBIOSVersion) -Like '*SCE*'){
        if($((Get-WmiObject Win32_Bios).SMBIOSBIOSVersion) -ne '68SCE Ver. F.63'){
            Write-Output "Needs upgrade"
            $Exe = 'hpqflash.exe'
            $Location = "$SCRIPTDIR\Source\HP EliteBook 8460p"
            $Executable = $Location + "\" + $exe
            Set-Location -Path $Location
            Invoke-Exe -Executable "$Executable" -Arguments "/s /f 68SCE.CAB" -Verbose
            }
        else
            {
            Write-Output "No Need to upgrade"
        }
    }
}
if($((Get-WmiObject Win32_ComputerSystem).model) -eq 'HP Compaq dc7900 Small Form Factor'){
    Write-Output "Model is $((Get-WmiObject Win32_ComputerSystem).model)"
    Write-Output "Checking BIOS Version"
    Write-Output "Version is $((Get-WmiObject Win32_Bios).SMBIOSBIOSVersion)"
    if($((Get-WmiObject Win32_Bios).SMBIOSBIOSVersion) -ne '786G1 v01.27'){
        Write-Output "Needs upgrade"
        $Exe = 'hpqflash.exe'
        $Location = "$SCRIPTDIR\Source\HP Compaq dc7900 Small Form Factor\HPQFlash"
        $Executable = $Location + "\" + $exe
        $SourceFile = $Location + "\" + "Password01.bin"
        $Destination = $env:TEMP
        $DestinationFile = $Destination + "\" + "Password01.bin"
        Copy-Item -Path $SourceFile -Destination $DestinationFile -Force -Verbose 
        Set-Location -Path $Location
        Invoke-Exe -Executable $Executable -Arguments "/s /p $DestinationFile"
    }
    else
    {
        Write-Output "No Need to upgrade"
    }
}

#Stop Logging
. Stop-Logging


/mike

Posted in BIOS, ConfigMgr, MDT, OS Deployment, OSD, PowerShell | Tagged: , , , , , | 4 Comments »

PowerShell is King – Getting a massive amount of hotfixes from the Windows Update Site

Posted by Mikael Nystrom on June 30, 2016

Working for a customer in Norway, I received a list of “hotfixes” that needs to be downloaded and imported into WSUS for distribution, number of patches was 90. I have not found any great way to automate download from the Update Catalog into WSUS (there must be). So the here is the ugly version:

The ugly PowerShell script that starts Internet Explorer and add every patch to a separate tab

$Urls = Get-Content -Path C:\Temp\hotfixes.txt

$TabSettings = 0x1000;
$ie = New-Object -ComObject InternetExplorer.Application
$ie.Navigate2("http://www.microsoft.com");
foreach($Url in $Urls){
    $ie.Navigate2("$Url", $TabSettings);
}
$ie.Visible = $true;

The content of hotfixes.txt

http://catalog.update.microsoft.com/v7/site/Search.aspx?q=2965733
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=2981330
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3000123
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3014795
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3020813
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3020773
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3022333
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3027115
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3027110
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3025080
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3027108
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3023894
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3020717
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=2970653
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3033917
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3036614
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3042121
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3046481
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3042127
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3044457
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3046826
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3031598
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3036173
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3047296
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3018489
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3049448
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3047280
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3052122
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3049443
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3061460
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3060678
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3063283
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3068445
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3072380
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3068444
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3072381
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3077354
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3075610
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3076950
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3076946
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3075161
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3078411
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3080728
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3078584
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3076953
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3012714
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3073062
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3087856
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3078420
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3025091
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3078631
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3094197
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3053667
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3093571
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3090322
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3093272
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3094199
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3094209
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3095711
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3082343
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3093899
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3093550
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3095319
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3091403
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3084093
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3095308
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3091057
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3090973
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3092005
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3095663
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3091402
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3063109
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3102354
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3105881
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3100527
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3101694
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3087288
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3092604
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3100477
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3080141
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3084463
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3102770
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3109099
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3102997
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3114133
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3109973
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3123538
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3127673
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3123593
http://catalog.update.microsoft.com/v7/site/Search.aspx?q=3107677

Posted in PowerShell | Tagged: | Leave a Comment »

PowerShell is King – Simple function to test a VMSwitch is present

Posted by Mikael Nystrom on May 27, 2016

When building VM’s, they are usually connected to a Hyper-V switch, so when working for a customer I suddenly needed to verify that the switch actually exists before building the VM. One way to solve this is of course to use Get-VMSwitch –Name, but if it cant find it, it blows up and turns red and angry, the other way is to use “Count”, that way I can return whatever I need, in this case I Return True or False.

Usage:

Create a .psm1 file, copy the content, paste into the file, save the file and use the Import-Module function. After that you can test it by running commands similar to this.

image
Using the function to test a VMswitch is present on the local machine.

The Function:

Function Test-FAVMSwitchexistence
{
    Param(
        [string]$VMSwitchname
    )
        $Item = (Get-VMSwitch | Where-Object -Property Name -EQ -Value $VMSwitchname).count
        If($Item -eq '1'){Return $true}else{Return $false}
}

Mike

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