I wanted a way to query individual values from the Windows Operating System to build better groups in Ninja. The default OS field is not very easy to work with, so this is what I did.
In Ninja, you need to create 4 text fields and add them to your roles. (This assumes you know how to create Custom Fields in Ninja.)
- windowsOsName
- windowsOsInstallDate
- windowsOsVersion
- windowsOsBuildNumber
Then import this script and add it either to a task or scheduled scripts:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
try{ $osinstalldate = ([WMI]'').ConvertToDateTime((Get-WmiObject Win32_OperatingSystem).InstallDate) | Out-String $osname = (Get-WMIObject win32_operatingsystem).caption.replace("Microsoft ","") $osversion = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name DisplayVersion).DisplayVersion #$osbuild = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name CurrentBuildNumber).CurrentBuildNumber $osbuild = (Get-ComputerInfo).OsHardwareAbstractionLayer Ninja-Property-Set windowsOsInstallDate $osinstalldate | Out-Null Ninja-Property-Set windowsOsName $osname | Out-Null Ninja-Property-Set windowsOsVersion $osversion | Out-Null Ninja-Property-Set windowsOsBuildNumber $osbuild | Out-Null } catch{ Write-Error "Failed to generate, retrieve or parse data: $($_.Exception.Message)" } |