I found a solution that is working for me:
1. Custom Inventory Field
- Build a custom inventory field in you K1000 by going to "Inventory", "Software" and then select "New" from the "Choose Action"-menu.
- Enter a name for your field, "Server roles and features" e.g.
- Select all operating systems that this field should be evaluated on by holding the CTRL-key and clicking each of the required entries.
In our case it makes sense to select Windows Server OS only since the query won't work on any Windows client OS.
In my tests I found this one works on Windows Server 2008 R2 and above.
If you need to support Windows Server 2008 Non-R2 (but not older!), see the alternative command in the next step.
IMPORTANT: If new Windows Server OS come into your K1000's managed device inventory make sure you come back here and enable these new server OS as well - the K1000 won't do that for you! - In the field "Custom Inventory Rule" enter the following:
ShellCommandTextReturn(%windir%\SysNative\WindowsPowerShell\v1.0\powershell -NoLogo -NonInteractive -NoProfile -Command "Get-WindowsFeature | where-object {$_.Installed -eq $True} | foreach {$_.Name}")
If you need to support Windows Server 2008 Non-R2 enter the following command INSTEAD. According to Microsoft, this query method is deprecated since Windows Server 2012 - on my 2012 and 2012 R2 servers this is working anyway.
So here is the "old school" command:
ShellCommandTextReturn(wmic /namespace:\\root\CIMV2:Win32_ServerFeature PATH Win32_ServerFeature Get Name) - After running inventory on your server(s), you should now have a custom inventory field (in the "Software" section) showing you all installed roles and features of the server.
2. Smart Label
When the custom inventory field is available and working we can use the smart label editor to build filters on that.
- First of all, you need to identify the "core" role name(s) of the roles you are looking for. Note that a roles "Display Name" may be localized, that's why I suggest to use the "Name" field instead to make this one work on all machines.
To find out what your roles name is open a PowerShell command line on one of your servers and run the following command:
Get-WindowsFeature | where-object {$_.Installed -eq $True} | ft DisplayName,Name
This will give you a list of "Name" and "DisplayName" side-by-side. In my case, I want to see the servers with "Remotedesktop-Sitzungshost" (German for the RDS Session Host) - that roles name is "RDS-RD-Server".
If you used the "old school" command above you need to check the names listed by the WMIC command instead. - Now open a smart label editor in your "Inventory" "Device" overview and select your new custom inventory field from above in the list of available fields.
Switch the operator to "contains" and enter your desired role name in the right field.
Test your label configuration. If everything is OK, enter a name for your smart label, hit "Save" - and you're done!
You can also define combinations, e.g. "contains RDS-RD-Server AND contains RDS-Web-Access" to find your RemoteApp host etc. - Wait for the next inventory to run to see your label getting populated!
Another nice idea to use this field is in reports. You could create a report that shows all servers having the role "Desktop-Experience" installed or not having .NET-Framework 3.5 installed (choose "does not contain" as operator and "NET-Framework-Features" as role name!)
If you want to use this for your client machines, please note the PowerShell query is different. We need to use the Win32_OptionalFeature-class here. The PowerShell command would be
Get-WmiObject -query 'select * from win32_optionalfeature where installstate=1' | foreach {$_.Name}
then, so you could use the following custom inventory command:
Get-WmiObject -query 'select * from win32_optionalfeature where installstate=1' | foreach {$_.Name}
then, so you could use the following custom inventory command:
ShellCommandTextReturn(%windir%\System32\WindowsPowerShell\v1.0\powershell -NoLogo -NonInteractive -NoProfile -Command "Get-WmiObject -query 'select * from win32_optionalfeature where installstate=1' | foreach {$_.Name}")
Comments