Visit the Ironworks Gaming Website Email the Webmaster Graphics Library Rules and Regulations Help Support Ironworks Forum with a Donation to Keep us Online - We rely totally on Donations from members Donation goal Meter

Ironworks Gaming Radio

Ironworks Gaming Forum

Go Back   Ironworks Gaming Forum > Ironworks Gaming Forums > General Discussion
FAQ Calendar Arcade Today's Posts Search

Reply
 
Thread Tools Search this Thread
Old 06-26-2007, 12:15 AM   #1
Hivetyrant
Jack Burton
 

Join Date: August 24, 2002
Location: Aussie now in the US of A!
Age: 38
Posts: 5,403
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 ]
Hivetyrant is offline   Reply With Quote
Old 06-26-2007, 05:45 AM   #2
dplax
Jack Burton
 

Join Date: July 19, 2003
Location: an expat living in France
Age: 40
Posts: 5,577
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 ]
__________________

dplax is offline   Reply With Quote
Old 06-26-2007, 07:41 PM   #3
Hivetyrant
Jack Burton
 

Join Date: August 24, 2002
Location: Aussie now in the US of A!
Age: 38
Posts: 5,403
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 is offline   Reply With Quote
Old 06-26-2007, 09:39 PM   #4
Hivetyrant
Jack Burton
 

Join Date: August 24, 2002
Location: Aussie now in the US of A!
Age: 38
Posts: 5,403
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!
Hivetyrant is offline   Reply With Quote
Old 06-28-2007, 03:29 AM   #5
dplax
Jack Burton
 

Join Date: July 19, 2003
Location: an expat living in France
Age: 40
Posts: 5,577
You're welcome!
__________________

dplax is offline   Reply With Quote
Old 07-04-2007, 08:41 AM   #6
wellard
Dracolisk
 

Join Date: November 1, 2002
Location: Australia ..... G\'day!
Posts: 6,123
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
__________________


fossils - natures way of laughing at creationists for over 3 billion years
wellard is offline   Reply With Quote
Old 07-04-2007, 12:06 PM   #7
pritchke
Bastet - Egyptian Cat Goddess
 

Join Date: September 5, 2001
Location: Calgary, AB
Age: 50
Posts: 3,491
quotes are so annoying.

[ 07-04-2007, 12:11 PM: Message edited by: pritchke ]
pritchke is offline   Reply With Quote
Old 07-04-2007, 05:42 PM   #8
Hivetyrant
Jack Burton
 

Join Date: August 24, 2002
Location: Aussie now in the US of A!
Age: 38
Posts: 5,403
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 )
Hivetyrant is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
URGENT HELP jamalez Baldurs Gate II: Shadows of Amn & Throne of Bhaal 7 03-16-2003 09:02 AM
Please help me! its urgent! GREENK Baldurs Gate II: Shadows of Amn & Throne of Bhaal 3 09-25-2002 08:49 AM
In Urgent Need of Help =( Estasios Baldurs Gate II: Shadows of Amn & Throne of Bhaal 15 05-09-2002 01:00 PM
Urgent...Sig Help Please onthepequod General Conversation Archives (11/2000 - 01/2005) 13 04-07-2002 02:31 PM
Urgent help !!! please help me ball Darkstone 1 04-12-2000 03:41 PM


All times are GMT -4. The time now is 05:06 AM.


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