O R G A N I C / F E R T I L I Z E R: 07.09

Jul 31, 2009

“mid” like functionality in batch script

for awhile, i used for looping to do a lot of manipulation in batch scripts until i ran across this gem.  a friend of mine asked me how to manipulate a date string awhile back.  this is what i came up with.

let’s begin with the date /t command.  running it gives us this output:

Fri 07/31/2009

 

most date formats with respect to dates in filenames generally don’t use “/” or include the short day name “fri”.  my conventional method is to push this through a for loop and break out the thing into tokens.  i’ve done this in below by utilizing “/” and “,” as the delimiters.

for /f "tokens=1,2,3,4 delims=/, " %a in ('date /t') do @echo %b%c%d

 

now we get this output when we echo %b%c%d.

07312009

 

the challenge i got was how to get the date to show up as 090731.  if we tried to use “0” as a delimiter, it would clearly fail as 07 and 09 have zeroes in them.  here’s an example:

for /f "tokens=1-5 delims=/,0 " %a in ('date /t') do @echo 0%e0%b%c

 

we get the output we want but only by forcing 0s into the echo statement.  this can’t be a good idea because eventually the month will increment where there’s no 0 preceding it… like 10, 11, or 12.  that’s when i found this other cool method.

for /f "tokens=1-2 delims= " %a in ('echo %date%') do @set mydate=%b
set mm=%mydate:~0,2%
set dd=%mydate:~3,2%
set yy=%mydate:~8,2%

 

now i can echo back the output as echo %yy%%mm%%dd% and achieve the result we expect.

090731

 

this is what i imagine the syntax to look like:

%[var]:~[1st position],[last position]%

incidentally, it accepts negative numbers as well.  so, you could achieve the same effect using %mydate:~-2%.  this is not the same as %mydate:~0,-2% by the way.

why batch files?  i don’t know.  i guess some people still like them. :)

Jul 30, 2009

excellent demo on using custom composite data types

A teacher writing on a blackboard.

Image via Wikipedia

if you happened to miss the last system center virtual user group, catch the recorded livemeeting.  there’s a great presentation on using composite monitors.  i believe the source is what’s on technet currently, but the explanation and step-by-step demonstration will help cement the idea.  check it out on system center central: http://www.systemcentercentral.com/Details/tabid/147/IndexID/21509/Default.aspx

Jul 24, 2009

sql query to list all manual reset monitors

Batch Monitor

Image via Wikipedia

looking for an easy way to list all of your unit monitors classified as a manual reset?  here’s a sql query that you can execute to list them out.

SELECT mv.name,
mv.enabled,
mv.displayname,
mtv.name,
mpv.name
FROM monitorview mv
inner join monitortypeview mtv on mv.monitortypeid=mtv.id
inner join managementpackview mpv on mtv.managementpackid = mpv.id
WHERE mv.IsUnitMonitor = 'True' and
mtv.name like '%manualreset%'

you can follow the entire thread here.

Jul 23, 2009

bug in notification subscription when using custom fields with opsmgr

back last month, i posted an odd behavior i was seeing in opsmgr.  anytime i used a custom field, the notification subscription would not work.  one of the peeps on the forum called pss to work through the issue and had been informed that it was a bug, completely reproducible.

you can read the entire thread here: http://social.technet.microsoft.com/Forums/en-US/operationsmanagergeneral/thread/260be16a-0f45-4904-8093-7c1caa5ed546

otherwise, here’s a short summary of how to fix the problem:

  • Export the ‘Notifications Internal Library’ Management Pack.
  • Increase the <Version>. For example:
    • <Version>6.1.7221.1</Version>
  • Locate the mistakes for each custom Field, which will look like:
<SimpleExpression xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ValueExpression>
<Property>Custom8</Property>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value>RobsTest</Value>
</ValueExpression>
</SimpleExpression>
  • Update this by changing Custom8 to CustomField8. For example:
<SimpleExpression xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ValueExpression>
<Property>CustomField8</Property>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value>RobsTest</Value>
</ValueExpression>
</SimpleExpression>
  • Save the file & import back into OpsMgr.

thanks goes to graham davies and coentjo!

Jul 22, 2009

configmgr console crashes with error “input string was not in a correct format”

i recently posted a fix to a console crashing condition with configmgr.  looks like it’s round two.  one of the configmgr admins here ran into this issue and asked me about.  this should be an entertaining post, especially when i highlight the advice from microsoft on how to fix this problem.  let’s start, shall we?

to begin with, the console crashes, from any machine, when you try to view the settings of specific active directory discovery methods.  this was occurring on two different servers and not always the same ad discovery method.  the only thing of interest that both servers had in common was that they were migrated to new hardware and had run through the site recovery wizard.

i captured the message that fires up whenever a crash condition occurs.  it looks like the likely offense is this message: Input string was not in a correct format.

image

that usually means site control configuration file corruption to me.  note that if you modify your site control file, you probably won’t get any support from microsoft.  make sure you have a good backup.

 

do not follow these steps

before we go on with how you fix this problem, let’s review how microsoft pss believes you should fix this problem.  here’s the first set of steps.

  1. Logon or RDP to SCCM Server, close mmc and console
  2. Delete the adminconsole cache file from : \document and settings\%username%\application data\microsoft\mmc  ; (NOTE: %username% is the currently logged in user ID)
  3. Start mmc and open sccm console.

hmmm.  apparently the fact that this happens on any console or machine is of no concern.  to say the least, this did not fix the problem.  so we’ll go through the action anyway because you cannot move forward without having done all steps prior and in the end having rebooted your server.  i’m sure that must be coming up…

in all fairness, these are actually good steps in capturing the problem when you’re poking around in the dark, in a very large room, with a very short stick.  after the first steps failed, this is what was sent:

  1. Close sccm console
  2. Install .net framework SP2 - if you don’t have this installed yet : http://www.microsoft.com/downloads/details.aspx?familyid=5B2C0358-915B-4EB5-9B1D-10E506DA9D0F&displaylang=en
  3. Delete adminconsole cache file if it still exist (: \document and settings\%username%\application data\microsoft\mmc )
  4. Enable admin verbose log :
    1. Navigate to <installationpath>\adminui\bin folder
    2. Open adminui.console.dll.config using a text editor or notepad
    3. Change the line <source name="SmsAdminUISnapIn" switchValue="Error" > to <source name="SmsAdminUISnapIn" switchValue="Verbose" >
  5. From registry key : HKEY_CURRENT_USER\\CONTROL PANEL\DESKTOP\HUNGAPPTIMEOUT . The default is 5000, change this value to 10000 and reboot the machine
  6. download procmon from : http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx
  7. RDP to sccm server, (mstsc/console)
  8. Run procmon and reproduce the issue
  9. Please send me :
  10. Procmon log (.pml)
  11. Event logs from event viewer (*.evt)
  12. Adminui.log, smsprov.log

this is great and all but won’t fix the problem.  in fact, it’ll only help the pss engineer eventually arrive at what the exact problem is.  “Input string was not in correct format”.  seems pretty obvious to me.

 

consider these steps

i compared a good sitectrl.ct0 against a bad one for the area with issues.  what i noticed to be the problem was pretty simple to fix, actually.  it seemed the console was expecting to read in an integer value when it ran into a string value.

Exception Type: System.FormatException

Exception Message: Input string was not in a correct format.

Server stack trace:
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)

sure enough, in the sitectrl file, it was hitting a string.  here’s how a good file should look:

BEGIN_COMPONENT
<SMS_AD_SYSTEM_GROUP_DISCOVERY_AGENT>
<6>
<MYSMSSERVER>
PROPERTY <Run Count><><><1>
PROPERTY <SETTINGS><ACTIVE><><0>
PROPERTY <Startup Schedule><0001170000500008><><0>
BEGIN_PROPERTY_LIST
<AD Containers>
<LDAP://OU=myComputers,OU=mySite,DC=myDomain,DC=COM>
<0>
<0>
<LDAP://OU=myComputers,OU=mySite2,DC=myDomain,DC=COM>
<0>
<0>
END_PROPERTY_LIST
BEGIN_PROPERTY_LIST
<Start On Master Site Control File Changes>
<"Component","SMS_AD_SYSTEM_GROUP_DISCOVERY_AGENT|MYSMSSERVER">
END_PROPERTY_LIST
END_COMPONENT

and here’s how the broken one looked:

BEGIN_COMPONENT
<SMS_AD_SYSTEM_GROUP_DISCOVERY_AGENT>
<6>
<MYSMSSERVER>
PROPERTY <Run Count><><><1>
PROPERTY <SETTINGS><ACTIVE><><0>
PROPERTY <Startup Schedule><0001170000500008><><0>
BEGIN_PROPERTY_LIST
<AD Containers>
<LDAP://OU=myComputers,OU=mySite,DC=myDomain,DC=COM>
<0>
<LDAP://OU=myComputers,OU=mySite2,DC=myDomain,DC=COM>
<0>
END_PROPERTY_LIST
BEGIN_PROPERTY_LIST
<Start On Master Site Control File Changes>
<"Component","SMS_AD_SYSTEM_GROUP_DISCOVERY_AGENT|MYSMSSERVER">
END_PROPERTY_LIST
END_COMPONENT
 
notice the difference?  yes, the good file has two integers following the ldap location.  you’re asking yourself what these values represent, right?  good.  i wanted to capture it for later reference anyway.  i’m sure you would have figured this out on your own.  turns out they’re search options.  starting with the first one…
  • <0> – Recursive
  • <0> – Include groups
if the value is checked, it’s represented as <0>.  otherwise, unchecked is represented as <1>.  i put it in graphical format… :)
 
image

Jul 9, 2009

management pack university is live!

The University of Sydney established in 1850, ...

Image via Wikipedia

i’m not sure if you’ve seen or heard about mp university.  after sharing a link, some folks were surprised about where i found the content.  mp university is live!  if you’re interested in checking it out, here’s a link: http://technet.microsoft.com/en-us/opsmgr/cc671407.aspx.

there are two tracks so far, one for beginner content and the other for advanced topics.  once you get to the site, use the link “management pack university videos”.  great stuff!

Jul 7, 2009

understanding the “ad op master is inconsistent” alert

i use the term “understanding” loosely.  this is by far no definitive guide on this particular alert, just a few things i have picked up in my attempt to understand it.

let’s look at the context of the alert:

The Domain Controller's Op Master is inconsitent. See additional alerts for details.

first of all, it gives very little information.  the only particularly useful detail is that it indicates which server is having the issue.  other than that, just a spelling error as there are no additional critical alerts to look at for details.

this rule, as you know, comes from a sealed mp.  therefore, we can’t modify anything in it except the overrides.  the couple i’ve tinkered with are:

  • interval (sec)
  • log success event

to begin with, interval (sec) is just set way too high.  the default is 60 seconds.  why on earth would anyone want to know that your op master consistency may be off, every minute?  actually, i could think of a few reasons, but really, it’s overkill.  the way the script works (which has a copyright of 2001, by the way, and apparently briefly modified for opsmgr by stripping out the createevent calls and replacing them with property bag calls) is to check all replication partners for op master consistency.  on a bridgehead server, that’s quite a big number.  i ended up dropping the value to 3600.

i mentioned earlier that the alert has no useful context.  here’s why.  if you look inside the script, the functions for createevent route to this subroutine:

Sub CreateEvent(lngEventID, lngEventType, strMessage)

oAPI.LogScriptEvent "AD Replication Partner Op Master Consistency", lngEventID, lngEventType, strMessage

if lngEventID=EVENTID_CANT_DETERMINE_OP_MASTER or lngEventID=EVENTID_OP_MASTERS_INCONSISTENT then
bState=1
End if
End Sub
 

depending on the condition, bState either goes 0 or 1.  this next snippet indicates what to do with the bState condition:

if bState=0  then
set oBag = oAPI.CreateTypedPropertyBag(StateDataType)
oBag.AddValue "State", "GOOD"
oBag.AddValue "EventID", EVENTID_GOOD
oAPI.AddItem oBag
END IF
if bState=1 then
set oBag = oAPI.CreateTypedPropertyBag(StateDataType)
oBag.AddValue "State", "BAD"
oBag.AddValue "EventID", EVENTID_BAD
oAPI.AddItem oBag
END If

and as you can see, the state is captured as well as the event id.  no other detail.  for this reason, you can’t figure out whether bad is really bad or just maybe bad.  i mean, is it really inconsistent, or can the agent simply not retrieve the required data? 

this is where the other override i mentioned earlier, comes into play – log success event.  if you choose to turn this on, you can view the associated events of the health service to see the details it stores.  it will show you every consistent partner – which could potentially be useful.  this is what a “good” event would look like:

AD Replication Partner Op Master Consistency : Op Master PDC 'myDC1.MYDOMAIN.COM' consistent with replication partner 'myDC2.MYDOMAIN.COM'.

and the inverse (logs regardless of log success event override):

AD Replication Partner Op Master Consistency : The script 'AD Replication Partner Op Master Consistency' failed to executethe following LDAP query: '<LDAP://myDC1.myDomain.com/CN=Schema,CN=Configuration,DC=myDomain,DC=com>;(&(objectClass=dMD)(fSMORoleOwner=*));fSMORoleOwner;Subtree'.
The error returned was 'Table does not exist.' (0x80040E37)



AD Replication Partner Op Master Consistency : Unable to determine schema Op Master on domain controller 'myDC1.myDomain.com'.


that’s actually two events that i pulled out of the operations manager event log on the dc in question.  those events are not captured by opsmgr by default.

when you view the data, it tells you everything you need to know.  first of all, don’t panic.  there’s no inconsistency!  the error is because the partner dc can’t be reached.  (yes, that is a problem obviously but not a data integrity type problem).

i mentioned that there are no additional critical alerts to look at for details.  if you switch to the warning alerts, you will find detail on why the particular alert fired.  for example, here are two that relate to the event messages above:

AD Replication Partner Op Master Consistency : The script 'AD Replication Partner Op Master Consistency' failed to executethe following LDAP query: '<LDAP://myDC1.myDomain.com/CN=Configuration,DC=myDomain,DC=com>;(&(objectClass=crossRefContainer)(fSMORoleOwner=*));fSMORoleOwner;Subtree'.
The error returned was 'Table does not exist.' (0x80040E37)



AD Replication Partner Op Master Consistency : Unable to determine domain naming Op Master on domain controller 'myDC1'.


looks remarkably alike, right?

if you want to see it all in one view, i suggest using the dc active alerts view which will show you all the alerts stacked up for easier correlation.

image

optionally, search for the computer name in question.  don’t expect to find it under dc events.  as stated earlier, these events are not picked up by default.

hope that helps!