No omitted results
I am using little snippets to detect server roles with powershell and I am having some issues getting results ommited.
My Code:
Import-module servermanager ; Get-WindowsFeature | where-object {$_.Installed -eq $True} | format-list DisplayName
There here you specific which role to check:
Import-module servermanager ; (Get-WindowsFeature -name hyper-v).Installed
However whenever I try use the role "Backup" I get no results. I have also tried Backup-Features, Backup-Tools,Backup-cmdlets as specified at: https://technet.microsoft.com/en-us/library/cc732757.aspx
If I try the other roles they come back either True or False, but Backup doesnt display any results, could this be a bug in the module?
-
Edited by
EDTRUD
11 hours 55 minutes ago
September 14th, 2015 3:07pm
Have you tried
Get-WindowsFeature *backup*
As the actual name looks to be Windows-Server-Backup
September 14th, 2015 3:26pm
Try not typing everything on one line.
Import-moduleservermanager
Get-WindowsFeature -name '*backup*'|select name,installed|ft -auto
September 14th, 2015 3:31pm
Does that mean I have to filter out the description if I want to create an IF statement based on whether a specific role is installed or not. Because previously it would only say true or False
September 14th, 2015 3:44pm
What role are you asking about?
September 14th, 2015 3:46pm
This works just fine:
Get-WindowsFeature -name backup|select name,installed|ft -auto
September 14th, 2015 3:47pm
Hmm, what version of powershell are you running? I think mine needs to be updated to work
September 14th, 2015 4:02pm
It works on all current versions of PowerShell.
September 14th, 2015 4:07pm
Tried this on 3 different servers and I am receiving no output.
Get-WindowsFeature -name backup|select name,installed|ft -auto
September 14th, 2015 4:18pm
Works fine for the rest of us.
Perhaps you are not an admin? Perhaps you are not running elevated? Perhaps you have a bad installation?
There are many reasons that things fail. The answer is correct and works.
This will not work on any workstation or any server pre WS2008R2.
September 14th, 2015 4:27pm
Tested this on:
(3) Server 2012 Std's - Didnt work
(2) SBS 2011's - Worked
(2) 2008 R2's - Worked
I am curious as to why its not working on 2012
September 14th, 2015 4:40pm
Backup is not on WIndpws Server 2012. Use this:
Get-WindowsFeature Windows-Server-Backup
September 14th, 2015 5:25pm
That worked, is there any way to make it only return a true or false value? So I could use something like
if $role = false then fail
September 14th, 2015 6:26pm
PowerShell 101
if( -not (Get-WindowsFeature Windows-Server-Backup).Installed){
Write-Host 'Not installed'
}else{
Write-Host 'installed'
}
September 14th, 2015 6:35pm
That worked, is there any way to make it only return a true or false value? So I could use something like
if $role = false then fail
Test on the Installed pro
September 14th, 2015 6:36pm