Refactored all SCCM queries to one file since they share the same constants
This commit is contained in:
parent
b20d2f22a6
commit
433be9b928
|
|
@ -1,22 +1,6 @@
|
||||||
Function Get-Apps($ComputerName, $TableView) {
|
Function Get-Apps($ComputerName, $TableView) {
|
||||||
|
|
||||||
$SCCMServer = "shscm01.int.samhealth.net"
|
$86apps, $64apps = Get-SCCM_Apps $ComputerName
|
||||||
|
|
||||||
$SCCMNameSpace = "root\sms\site_100"
|
|
||||||
|
|
||||||
$SCCMX64Query = "select SMS_G_System_ADD_REMOVE_PROGRAMS_64.DisplayName, SMS_G_System_ADD_REMOVE_PROGRAMS_64.Version, SMS_G_System_ADD_REMOVE_PROGRAMS_64.Publisher, SMS_G_System_ADD_REMOVE_PROGRAMS_64.InstallDate from SMS_R_System inner join SMS_G_System_ADD_REMOVE_PROGRAMS_64 on
|
|
||||||
SMS_G_System_ADD_REMOVE_PROGRAMS_64.ResourceId = SMS_R_System.ResourceId inner join SMS_G_System_SYSTEM on
|
|
||||||
SMS_G_System_SYSTEM.ResourceId = SMS_R_System.ResourceId where SMS_G_System_SYSTEM.Name = '$ComputerName'"
|
|
||||||
|
|
||||||
$SCCMX86Query = "select SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName, SMS_G_System_ADD_REMOVE_PROGRAMS.Version, SMS_G_System_ADD_REMOVE_PROGRAMS.Publisher, SMS_G_System_ADD_REMOVE_PROGRAMS.InstallDate from SMS_R_System inner join SMS_G_System_ADD_REMOVE_PROGRAMS on
|
|
||||||
SMS_G_System_ADD_REMOVE_PROGRAMS.ResourceID = SMS_R_System.ResourceId inner join SMS_G_System_SYSTEM on
|
|
||||||
SMS_G_System_SYSTEM.ResourceID = SMS_R_System.ResourceId where SMS_G_System_SYSTEM.Name = '$ComputerName'"
|
|
||||||
|
|
||||||
$64apps = Get-WmiObject -namespace $SCCMNameSpace -DirectRead -computer $SCCMServer -query $SCCMX64Query |
|
|
||||||
Select-Object -Property DisplayName | Add-Member -NotePropertyName x86/x64 -NotePropertyValue 64 -PassThru | Sort-Object -Property DisplayName
|
|
||||||
|
|
||||||
$86apps = Get-WmiObject -namespace $SCCMNameSpace -DirectRead -computer $SCCMServer -query $SCCMX86Query |
|
|
||||||
Select-Object -Property DisplayName | Add-Member -NotePropertyName x86/x64 -NotePropertyValue 32 -PassThru | Sort-Object -Property DisplayName
|
|
||||||
|
|
||||||
#Checks if local computer
|
#Checks if local computer
|
||||||
if ($comp -eq $env:COMPUTERNAME) {
|
if ($comp -eq $env:COMPUTERNAME) {
|
||||||
|
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
Function Get-AssetConversion($ComputerName){
|
|
||||||
|
|
||||||
$SiteName="100"
|
|
||||||
|
|
||||||
$SCCMServer="shscm01.int.samhealth.net"
|
|
||||||
|
|
||||||
$SCCMNameSpace="root\sms\site_100"
|
|
||||||
#Set Asset Tag to $comp
|
|
||||||
$assetTagSCCM = $ComputerName
|
|
||||||
|
|
||||||
$SCCMQuery = "select SMS_R_System.Name from SMS_R_System inner join SMS_G_System_SYSTEM_ENCLOSURE on SMS_G_System_SYSTEM_ENCLOSURE.ResourceId = SMS_R_System.ResourceId Where SMS_G_System_SYSTEM_ENCLOSURE.SMBIOSAssetTag = '$assetTagSCCM'"
|
|
||||||
|
|
||||||
#Set $comp to find hostname of PC
|
|
||||||
$nameHolder = Get-WmiObject -namespace $SCCMNameSpace -DirectRead -computer $SCCMServer -query $SCCMQuery | Select-Object -First 1 -ExpandProperty Name
|
|
||||||
|
|
||||||
if($null -ne $nameHolder){
|
|
||||||
$ComputerName = $nameHolder
|
|
||||||
return $ComputerName
|
|
||||||
}
|
|
||||||
|
|
||||||
return $null
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
Function HostnamesByPrinter($ComputerName){
|
|
||||||
|
|
||||||
$SiteName="100"
|
|
||||||
|
|
||||||
$SCCMServer="shscm01.int.samhealth.net"
|
|
||||||
|
|
||||||
$SCCMNameSpace="root\sms\site_100"
|
|
||||||
|
|
||||||
$FindHostnamesByPrinterQuery = "select SMS_R_System.Name from SMS_R_System inner join SMS_G_System_PRINTER_DEVICE on
|
|
||||||
SMS_G_System_PRINTER_DEVICE.ResourceId = SMS_R_System.ResourceId where SMS_G_System_PRINTER_DEVICE.Name = '$ComputerName'"
|
|
||||||
|
|
||||||
$FindHostnamesByPrinterSCCM = Get-WmiObject -namespace $SCCMNameSpace -DirectRead -computer $SCCMServer -query $FindHostnamesByPrinterQuery |
|
|
||||||
Select-Object -ExpandProperty Name
|
|
||||||
|
|
||||||
Return $FindHostnamesByPrinterSCCM
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -430,3 +430,78 @@ function Get-SCCM_PCFromMAC($mac) {
|
||||||
|
|
||||||
return (Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $pcFromMacQuery).Name
|
return (Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $pcFromMacQuery).Name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Get-SCCM_Apps($ComputerName) {
|
||||||
|
|
||||||
|
$SCCMX64Query = "select SMS_G_System_ADD_REMOVE_PROGRAMS_64.DisplayName, SMS_G_System_ADD_REMOVE_PROGRAMS_64.Version, SMS_G_System_ADD_REMOVE_PROGRAMS_64.Publisher, SMS_G_System_ADD_REMOVE_PROGRAMS_64.InstallDate from SMS_R_System inner join SMS_G_System_ADD_REMOVE_PROGRAMS_64 on
|
||||||
|
SMS_G_System_ADD_REMOVE_PROGRAMS_64.ResourceId = SMS_R_System.ResourceId inner join SMS_G_System_SYSTEM on
|
||||||
|
SMS_G_System_SYSTEM.ResourceId = SMS_R_System.ResourceId where SMS_G_System_SYSTEM.Name = '$ComputerName'"
|
||||||
|
|
||||||
|
$SCCMX86Query = "select SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName, SMS_G_System_ADD_REMOVE_PROGRAMS.Version, SMS_G_System_ADD_REMOVE_PROGRAMS.Publisher, SMS_G_System_ADD_REMOVE_PROGRAMS.InstallDate from SMS_R_System inner join SMS_G_System_ADD_REMOVE_PROGRAMS on
|
||||||
|
SMS_G_System_ADD_REMOVE_PROGRAMS.ResourceID = SMS_R_System.ResourceId inner join SMS_G_System_SYSTEM on
|
||||||
|
SMS_G_System_SYSTEM.ResourceID = SMS_R_System.ResourceId where SMS_G_System_SYSTEM.Name = '$ComputerName'"
|
||||||
|
|
||||||
|
$64apps = Get-WmiObject -namespace $SCCMNameSpace -DirectRead -computer $SCCMServer -query $SCCMX64Query |
|
||||||
|
Select-Object -Property DisplayName | Add-Member -NotePropertyName x86/x64 -NotePropertyValue 64 -PassThru | Sort-Object -Property DisplayName
|
||||||
|
|
||||||
|
$86apps = Get-WmiObject -namespace $SCCMNameSpace -DirectRead -computer $SCCMServer -query $SCCMX86Query |
|
||||||
|
Select-Object -Property DisplayName | Add-Member -NotePropertyName x86/x64 -NotePropertyValue 32 -PassThru | Sort-Object -Property DisplayName
|
||||||
|
|
||||||
|
return $86apps, $64apps
|
||||||
|
}
|
||||||
|
|
||||||
|
Function Get-AssetConversion($ComputerName){
|
||||||
|
|
||||||
|
#Set Asset Tag to $comp
|
||||||
|
$assetTagSCCM = $ComputerName
|
||||||
|
|
||||||
|
$SCCMQuery = "select SMS_R_System.Name from SMS_R_System inner join SMS_G_System_SYSTEM_ENCLOSURE on SMS_G_System_SYSTEM_ENCLOSURE.ResourceId = SMS_R_System.ResourceId Where SMS_G_System_SYSTEM_ENCLOSURE.SMBIOSAssetTag = '$assetTagSCCM'"
|
||||||
|
|
||||||
|
#Set $comp to find hostname of PC
|
||||||
|
$nameHolder = Get-WmiObject -namespace $SCCMNameSpace -DirectRead -computer $SCCMServer -query $SCCMQuery | Select-Object -First 1 -ExpandProperty Name
|
||||||
|
|
||||||
|
if($null -ne $nameHolder){
|
||||||
|
$ComputerName = $nameHolder
|
||||||
|
return $ComputerName
|
||||||
|
}
|
||||||
|
|
||||||
|
return $null
|
||||||
|
}
|
||||||
|
|
||||||
|
Function HostnamesByPrinter($ComputerName){
|
||||||
|
|
||||||
|
$FindHostnamesByPrinterQuery = "select SMS_R_System.Name from SMS_R_System inner join SMS_G_System_PRINTER_DEVICE on
|
||||||
|
SMS_G_System_PRINTER_DEVICE.ResourceId = SMS_R_System.ResourceId where SMS_G_System_PRINTER_DEVICE.Name = '$ComputerName'"
|
||||||
|
|
||||||
|
$FindHostnamesByPrinterSCCM = Get-WmiObject -namespace $SCCMNameSpace -DirectRead -computer $SCCMServer -query $FindHostnamesByPrinterQuery |
|
||||||
|
Select-Object -ExpandProperty Name
|
||||||
|
|
||||||
|
Return $FindHostnamesByPrinterSCCM
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Function Get-ServiceTagConversion($ComputerName){
|
||||||
|
|
||||||
|
#Set Service Tag to $comp
|
||||||
|
$ServiceTagSCCM = $ComputerName
|
||||||
|
|
||||||
|
$SCCMQuery = "select SMS_R_System.Name from SMS_R_System inner join SMS_G_System_SYSTEM_ENCLOSURE on
|
||||||
|
SMS_G_System_SYSTEM_ENCLOSURE.ResourceId = SMS_R_System.ResourceId where SMS_G_System_SYSTEM_ENCLOSURE.SerialNumber = '$ServiceTagSCCM'"
|
||||||
|
|
||||||
|
#Set $comp to find hostname of PC
|
||||||
|
$nameHolder = Get-WmiObject -namespace $SCCMNameSpace -DirectRead -computer $SCCMServer -query $SCCMQuery | Select-Object -First 1 -ExpandProperty Name
|
||||||
|
|
||||||
|
if($null -ne $nameHolder)
|
||||||
|
{
|
||||||
|
$ComputerName = $nameHolder
|
||||||
|
return $ComputerName
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Function Get-SCCM_UserLastLoggedOn($user) {
|
||||||
|
$SCCMUserQuery = "select distinct SMS_R_System.Name from SMS_R_System where SMS_R_System.LastLogonUserName = '$user'"
|
||||||
|
|
||||||
|
$computerSCCM = Get-WmiObject -namespace $SCCMNameSpace -DirectRead -computer $SCCMServer -query $SCCMUserQuery | Select-Object -ExpandProperty Name
|
||||||
|
return $computerSCCM
|
||||||
|
}
|
||||||
|
|
@ -38,15 +38,7 @@
|
||||||
}
|
}
|
||||||
$manager = $UserInfo.Manager.Split("=,")[1]
|
$manager = $UserInfo.Manager.Split("=,")[1]
|
||||||
|
|
||||||
$SiteName="100"
|
$computerSCCM = Get-SCCM_UserLastLoggedOn $user
|
||||||
|
|
||||||
$SCCMServer="shscm01.int.samhealth.net"
|
|
||||||
|
|
||||||
$SCCMNameSpace="root\sms\site_100"
|
|
||||||
|
|
||||||
$SCCMUserQuery = "select distinct SMS_R_System.Name from SMS_R_System where SMS_R_System.LastLogonUserName = '$user'"
|
|
||||||
|
|
||||||
$computerSCCM = Get-WmiObject -namespace $SCCMNameSpace -DirectRead -computer $SCCMServer -query $SCCMUserQuery | Select-Object -ExpandProperty Name
|
|
||||||
$computerList = $computerSCCM -join ", "
|
$computerList = $computerSCCM -join ", "
|
||||||
$props = [ordered]@{
|
$props = [ordered]@{
|
||||||
Name=$UserInfo.DisplayName
|
Name=$UserInfo.DisplayName
|
||||||
|
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
Function Get-ServiceTagConversion($ComputerName){
|
|
||||||
|
|
||||||
$SiteName="100"
|
|
||||||
|
|
||||||
$SCCMServer="shscm01.int.samhealth.net"
|
|
||||||
|
|
||||||
$SCCMNameSpace="root\sms\site_100"
|
|
||||||
#Set Service Tag to $comp
|
|
||||||
$ServiceTagSCCM = $ComputerName
|
|
||||||
|
|
||||||
$SCCMQuery = "select SMS_R_System.Name from SMS_R_System inner join SMS_G_System_SYSTEM_ENCLOSURE on
|
|
||||||
SMS_G_System_SYSTEM_ENCLOSURE.ResourceId = SMS_R_System.ResourceId where SMS_G_System_SYSTEM_ENCLOSURE.SerialNumber = '$ServiceTagSCCM'"
|
|
||||||
|
|
||||||
#Set $comp to find hostname of PC
|
|
||||||
$nameHolder = Get-WmiObject -namespace $SCCMNameSpace -DirectRead -computer $SCCMServer -query $SCCMQuery | Select-Object -First 1 -ExpandProperty Name
|
|
||||||
|
|
||||||
if($null -ne $nameHolder)
|
|
||||||
{
|
|
||||||
$ComputerName = $nameHolder
|
|
||||||
return $ComputerName
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -6,7 +6,6 @@
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
$SiteName = "100"
|
|
||||||
$RemoteViewerPath = "C:\Program Files (x86)\ConfigMgr\bin\i386\CmRcViewer.exe"
|
$RemoteViewerPath = "C:\Program Files (x86)\ConfigMgr\bin\i386\CmRcViewer.exe"
|
||||||
$RemoteViewerPathAdd = "C:\Program Files (x86)\ConfigMgr Console\bin\i386\CmRcViewer.exe"
|
$RemoteViewerPathAdd = "C:\Program Files (x86)\ConfigMgr Console\bin\i386\CmRcViewer.exe"
|
||||||
$RemoteViewerPathAdd2 = "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\i386\CmRcViewer.exe"
|
$RemoteViewerPathAdd2 = "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\i386\CmRcViewer.exe"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue