Hi All.. This little function can be run on your site servers with the MP role installed, where it will check to ensure the server has access to the MSSQL DB. Obviously add FileExist paths or remove as required.
strMPState = MPGETAUTH()
Function MPGETAUTH()
On Error Resume Next
MPGETAUTH = "N/A"
i = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("C:\Program Files\SMS\Logs\MP_GetAuth.log") Then
Set objFile = objFSO.OpenTextFile("C:\Program Files\SMS\Logs\MP_GetAuth.log", 1)
ElseIf objFSO.FileExists("C:\windows\system32\ccm\logs\MP_GetAuth.log") Then
Set objFile = objFSO.OpenTextFile("C:\windows\system32\ccm\logs\MP_GetAuth.log", 1)
ElseIf objFSO.FileExists("C:\Program Files\System Center Configuration Manager 2007\Logs\MP_GetAuth.log") Then
Set objFile = objFSO.OpenTextFile("Program Files\System Center Configuration Manager 2007\Logs\MP_GetAuth.log", 1)
Else
'wscript.echo "Cannot find MP_GetAuth.log"
MPGETAUTH = "NOFILE"
Exit Function
End If
Do Until objFile.AtEndOfStream
Redim Preserve arrLines(i)
arrLines(i) = objFile.readline
i = i + 1
Loop
For l = Ubound(arrLines)-20 to Ubound(arrLines)
If InStr(arrLines(l),": 0x80004005") Then
'wscript.echo "DB NOT DEFINED IN MP"
MPGETAUTH = "DBNODEF"
Exit Function
ElseIf InStr(arrLines(l),": 0x80004001") Then
MPGETAUTH = "DBAUTH"
Exit Function
'wscript.echo "DB DEFINED IN MP BUT NO PERMISSION"
End If
Next
objFile.Close
End Function
Thursday, 17 May 2012
SCCM - MSSQL Find Possible Broken Packages
I know one of the biggest things people come across as an SCCM administrator is trying to quickly identify sites where packages are broken. This query gives a basic rundown of identifying potential pain points in your package distribution:
use SMS_000
use SMS_000
go
Select R.PackageID,
s1.Name,
R.SiteCode,
R.ServerNALPath,
s1.SourceVersion as
"ActualSourceVersion",
R.SourceVersion as
"SiteSourceVersion",
R.State,
R.SummaryDate,
R.InstallStatus
from dbo.v_PackageStatusDistPointsSumm
as r
full join dbo.v_Package
as s1 on s1.PackageID = r.PackageID
where R.State <> 0
GO
Stop logon scripts running on servers
This small script I created around Feb 2011 to stop administrators with logonscripts assigned to the Active Directory profile from running(which I’m sure you know can cause havoc)
Just place it as high up the standard logon script as possible so this runs before anything else(Obviously you can modify to run on specific servers etc if need be)
' Stop-server-logon-script
' Sean Wright v1.0 08/02/11
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
osnamed = objOperatingSystem.Caption
res = InStr(UCase(osnamed), "SERVER")
if res > 0 then
wscript.echo "YOUR ON A SERVER LOGON SCRIPT WILL NOT RUN!!"
wscript.quit
end if
NextSCCM - ClientAgent - Check Site Assignment
This script subroutine will quickly check the SMSAgent(ccmexec.exe) site assignment to ensure it is assigned to the correct SiteCode. This version is written for a multi-hierarchy site configuration. Modify/extend as required.
Sub CheckSite()
On Error Resume Next
wscript.echo "Checking site assignment"
Dim oSMSClient, Site, objSysInfo, domain, strSiteCode
Set objSysInfo = CreateObject("ADSystemInfo")
domain = ucase(objSysInfo.DomainDNSName)
Set objSysInfo = Nothing
If Len(domain) < 0 Then
domain = GetDomain
End If
wscript.echo "Computer Domain: " & domain
Set oSMSClient = CreateObject("Microsoft.SMS.Client")
If Err.Number <> 0 Then
strMsg = "SMSAgent is not installed correctly or not running." & vbCrLf & _
"Object Microsoft.SMS.Client does not exist"
wscript.MsgBox(strMsg)
Err.Clear
Exit Sub
End If
Site = ucase(oSMSClient.GetAssignedSite)
If Len(Site) < 1 Then
wscript.echo "The machine is not assigned to a valid sitecode"
strSiteCode = FindSiteCode(domain)
wscript.echo "Should be set to " & strSiteCode
If strSiteCode = "999" Then
strMsg = "Site code could not be found correctly for domain"
wscript.msgbox(strMsg)
Exit Sub
End If
oSMSClient.SetAssignedSite(strSiteCode)
If Err.Number <> 0 Then
strMsg "Site reassign failed with error: " & Err.Number
wscript.msgbox(strMsg)
Err.Clear
Else
wscript.echo "Site reassignment successful"
End If
Else
wscript.echo "Site: " & Site
End If
mgmt = oSMSClient.GetCurrentManagementPoint
wscript.echo "Mgmt Point: " & mgmt
Set oSMSClient = Nothing
End Sub
Function FindSiteCode(dom)
On Error Resume Next
Dim FQDN
FQDN = ".blah.com"
Select Case dom
Case "0" & FQDN
FindSiteCode="000"
Case "1" & FQDN
FindSiteCode="001"
Case "2" & FQDN
FindSiteCode="002"
Case "3" & FQDN
FindSiteCode="003"
Case "4" & FQDN
FindSiteCode="004"
Case "5" & FQDN
FindSiteCode="005"
Case "6" & FQDN
FindSiteCode="006"
Case "7" & FQDN
FindSiteCode="007"
Case "8" & FQDN
FindSiteCode="008"
Case "9" & FQDN
FindSiteCode="009"
Case "10" & FQDN
FindSiteCode="010"
Case Else
FindSiteCode="999"
' site cannot be found for the domain
End Select
End Function
Sub CheckSite()
On Error Resume Next
wscript.echo "Checking site assignment"
Dim oSMSClient, Site, objSysInfo, domain, strSiteCode
Set objSysInfo = CreateObject("ADSystemInfo")
domain = ucase(objSysInfo.DomainDNSName)
Set objSysInfo = Nothing
If Len(domain) < 0 Then
domain = GetDomain
End If
wscript.echo "Computer Domain: " & domain
Set oSMSClient = CreateObject("Microsoft.SMS.Client")
If Err.Number <> 0 Then
strMsg = "SMSAgent is not installed correctly or not running." & vbCrLf & _
"Object Microsoft.SMS.Client does not exist"
wscript.MsgBox(strMsg)
Err.Clear
Exit Sub
End If
Site = ucase(oSMSClient.GetAssignedSite)
If Len(Site) < 1 Then
wscript.echo "The machine is not assigned to a valid sitecode"
strSiteCode = FindSiteCode(domain)
wscript.echo "Should be set to " & strSiteCode
If strSiteCode = "999" Then
strMsg = "Site code could not be found correctly for domain"
wscript.msgbox(strMsg)
Exit Sub
End If
oSMSClient.SetAssignedSite(strSiteCode)
If Err.Number <> 0 Then
strMsg "Site reassign failed with error: " & Err.Number
wscript.msgbox(strMsg)
Err.Clear
Else
wscript.echo "Site reassignment successful"
End If
Else
wscript.echo "Site: " & Site
End If
mgmt = oSMSClient.GetCurrentManagementPoint
wscript.echo "Mgmt Point: " & mgmt
Set oSMSClient = Nothing
End Sub
Function FindSiteCode(dom)
On Error Resume Next
Dim FQDN
FQDN = ".blah.com"
Select Case dom
Case "0" & FQDN
FindSiteCode="000"
Case "1" & FQDN
FindSiteCode="001"
Case "2" & FQDN
FindSiteCode="002"
Case "3" & FQDN
FindSiteCode="003"
Case "4" & FQDN
FindSiteCode="004"
Case "5" & FQDN
FindSiteCode="005"
Case "6" & FQDN
FindSiteCode="006"
Case "7" & FQDN
FindSiteCode="007"
Case "8" & FQDN
FindSiteCode="008"
Case "9" & FQDN
FindSiteCode="009"
Case "10" & FQDN
FindSiteCode="010"
Case Else
FindSiteCode="999"
' site cannot be found for the domain
End Select
End Function
Subscribe to:
Posts (Atom)