Ironworks Gaming Forum

Ironworks Gaming Forum (http://www.ironworksforum.com/forum/index.php)
-   General Discussion (http://www.ironworksforum.com/forum/forumdisplay.php?f=36)
-   -   Need urgent VBScript help!!! (http://www.ironworksforum.com/forum/showthread.php?t=97498)

Hivetyrant 06-26-2007 12:15 AM

Rightio people's, I have a problem.

My scripting knowledge is very limited (And I intend to keep it that way) however I need to add to a script at work to fix a problem we have.
Long story short, we use Microsoft SMS to roll out our SOE images and once the OS has been built, we run a script which does all the configuration. A little while ago we found that some computers were being built and added to the domain with the name “Telstra” and a random number sequence instead of “NML” followed by the Dell service tag, after some problem analysis we found that a certain part of the script (The part that renames the machine and rejoins the domain, was failing if the computer already exists in AD, seeing as how netdom cannot remove objects from AD I need to add something to the script before that step which searches AD for the machine and deletes it if something is found.

So basically, my script can find the Dell Service tag (called “sAssetTag” in the script) and I can search through AD and delete an object based on the location details that are found by the search, however I can’t figure out how to tell the search to find a computer object with the name ‘sAssetTag’, if I specifically state what the name is I am looking for, such as “8DFGN1S” the whole thing works, but I want the search to find a computer in AD based on the result of “sAssetTag”. Effectively making it a one script fits all sort of thing.

Hope that explains it….

Anyways, below is the script I am using:

I’m sure it’s not the perfect script, and I can probably take some things out and shorten it, however it (sort of) works and I don’t know enough about scripting to make it more efficient!

Quote:


Dim sAssetTag, strComputer, objWMIService, colComputers
Dim objComputer, colBIOS, objBIOS, Err

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

'Obtain Asset Tag
Set colBIOS = objWMIService.ExecQuery _
("Select * from Win32_BIOS")
For Each objBIOS In colBios
sAssetTag = objBIOS.SerialNumber
Next

'Delete Computer object from domain if it exists

Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
"Select ADsPath from " &_
"'LDAP://DC=Domain,DC=com,DC=au' where objectClass='computer'" &_
" and name = (Computername here) "
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
if objRecordSet.EOF then

cfound=false
Wscript.Echo "not cool"
Wscript.echo sassettag
else
cfound=true
Wscript.Echo objRecordSet.Fields("ADsPath").Value
Wscript.Echo "cool"

set objComputer = GetObject(objRecordSet.Fields("ADsPath").Value)
objComputer.DeleteObject (0)
end if
So yeah, as you can see, the (Computername here) part is where I specify what to search for, and I’m not sure how to tell it to look for sAssetTag (‘sAssetTag’) doesn’t work…..
I removed the Domain name intentionally…

And don’t worry about the “cool” and “not cool” parts [img]tongue.gif[/img] That’s just to tell me what part it’s getting to!

Any help would be great!

[ 06-26-2007, 03:33 AM: Message edited by: Hivetyrant ]

dplax 06-26-2007 05:45 AM

Since you're on the inside of a string (objCommand.CommandText takes a string) you need to concatenate the computer name inside it, so something like:

Quote:

objCommand.CommandText = _
"Select ADsPath from " &_
"'LDAP://DC=Domain,DC=com,DC=au' where objectClass='computer'" &_
" and name = " & sAssetTag & " "
[ 06-26-2007, 05:47 AM: Message edited by: dplax ]

Hivetyrant 06-26-2007 07:41 PM

Yeah, that was one of the first things I tried, but the script fails on line 32:
Quote:

Set objRecordSet = objCommand.Execute
I'm pretty sure it just means that the " & sAssetTag & " isn't right or I have done something wrong :(

Appreciate the help though [img]smile.gif[/img]

Hivetyrant 06-26-2007 09:39 PM

Phew, problem solved....

It was actually quite simple [img]tongue.gif[/img]

Dplax, you pretty much had it, but I needed to put single quotes outside the double quotes [img]smile.gif[/img]

Thanks for your help!

dplax 06-28-2007 03:29 AM

You're welcome!

wellard 07-04-2007 08:41 AM

Mate you should be more worried about this VB script problem Hives [img]graemlins/cheers.gif[/img]

The alcohol content of Victoria Bitter beer is to be reduced by 0.1 percent as part of brewer Foster's plan to save millions of dollars.

Foster's is also set to increase the wholesale price of all its packaged beers — including VB, Carlton, Crown Lager and Pure Blonde — by two percent next month.

The VB alcohol content will drop from 4.9 percent to 4.8 percent, which according to experts is enough to save Foster's $20 million in annual beer tax.

Story ninemsn Wednesday July 4

pritchke 07-04-2007 12:06 PM

<font face="Verdana" size="3" color="#009999">quotes are so annoying.</font>

[ 07-04-2007, 12:11 PM: Message edited by: pritchke ]

Hivetyrant 07-04-2007 05:42 PM

Quote:

Originally posted by wellard:
Mate you should be more worried about this VB script problem Hives [img]graemlins/cheers.gif[/img]

The alcohol content of Victoria Bitter beer is to be reduced by 0.1 percent as part of brewer Foster's plan to save millions of dollars.

Foster's is also set to increase the wholesale price of all its packaged beers — including VB, Carlton, Crown Lager and Pure Blonde — by two percent next month.

The VB alcohol content will drop from 4.9 percent to 4.8 percent, which according to experts is enough to save Foster's $20 million in annual beer tax.

Story ninemsn Wednesday July 4

Yeah, I saw that yesterday :(

Good thing I don't drink VB or Carlton!
(XXXX Gold man here :D )


All times are GMT -4. The time now is 02:33 PM.

Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
©2024 Ironworks Gaming & ©2024 The Great Escape Studios TM - All Rights Reserved