Get-Windowsfeature/WMI/Invoke-Command/

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Vivekanand Rapaka Vivekanand Rapaka 6 months, 3 weeks ago.

  • Author
    Posts
  • #39031
    Profile photo of Vivekanand Rapaka
    Vivekanand Rapaka
    Participant

    Hi All,

    I have a multiple servers [2008 r2 & 2012 r2] on which i need to install a roles from server manager. So, to start with, i wrote a script that uses
    "Get-Windowsfeature -computername servername -Name role1,role2 " then i wanted to pipe it to "Install-Windowsfeature"

    When i ran this on 2012 boxes, it was giving the output that i wanted.
    1.Couple of them errored out with RPC error on 2012 boxes.
    2. On 2008 boxes, it gave me the following error. So

    PS C:\> Get-WindowsFeature -ComputerName $server -Name telnet*
    Get-WindowsFeature : The request could not be processed. Verify that you are running the command targeted at a server
    that is running Windows Server 2012.

    So, i rewrote the below script to determine the O.S first and then use the appropriate cmdlets [Install-Windowsfeature & Add-Windowsfeature] that are supported.

    Most of my servers in the environment are not PSremoting enabled. Once psremoting is enabled at the server level, do i need to get any other ports opened by my networking team other than 5985,5986.

    Also in my below script, to determine the O.S part of the server, i'm using gwmi. So, which ports are needed to be opened for wmi to function so, that i dont run into RPC error. all the dynamic port range [49152 – 65535]? or what would be the best way to get the info...

    Lastly, i'm wondering on why "Get-Windowsfeature -computername" isn't supported on win2008 boxes when i run from a win2012 machine.

    Thanks in advance for answering.

    Function Add-Servercomponents()
    {
    $i=0
    $servers=type $home\desktop\servers.txt
    $count = $servers.count
    Foreach($server in $servers)
    {
    $i=$i+1
    $rem=$count-$i
    Write-Progress -Activity "Components Installation on $count servers" -Status "$rem servers remaining" -CurrentOperation "$server in progress"
    Try{

    $os=Gwmi win32_operatingsystem -computername $server | Select -expand caption
    if($os -like '*2008*')
    {
    Write-Output "$server is $os"
    Invoke-Command -computer $server {Import-Module ServerManager; Get-WindowsFeature -Name AS-NET-Framework,AS-Ent-Services }
    }
    Else
    {
    Get-WindowsFeature -Name AS-NET-Framework,AS-Ent-Services -computername $server
    }

    }
    Catch
    {
    Write-Output "Failed on $server"

    }
    }

    }Add-Servercomponents

  • #39215
    Profile photo of Don Jones
    Don Jones
    Keymaster

    So, 2008 used Add-WindowsFeature. That changed later, but the newer servers should still have the Add-WindowsFeature alias, so that command should work on everything.

    5985 is for HTTP Remoting, 5986 is for HTTPS Remoting. Those are the only ports.

    Win2008 does not enable Remoting by default, meaning you may need to enable it.

    I'm not sure that Win2008's WindowsFeature commands supported remote connectivity.

  • #39230
    Profile photo of Vivekanand Rapaka
    Vivekanand Rapaka
    Participant

    Thanks for your reply Don...I'll take it up from here.

You must be logged in to reply to this topic.