Calling MoveComputerToOU WebService from VBS

Mar 1, 2010 at 8:20 PM

Hi Guys,

Having some problems with calling the MoveComputerToOU WebService from a VBS script. Now, Im not great at scripting and have kinda put the following together which is probably completely wrong. Hopefull you can give me a pointer....

Set WshShell = WScript.CreateObject("WScript.Shell")

Set http = CreateObject("Microsoft.XmlHttp")
http.open "POST", "http://dc/MDT/ad.asmx/MoveComputerToOU", FALSE

http.setRequestHeader "POST /mdt/ad.asmx" , "HTTP/1.1"
http.setRequestHeader "Host:" ,"dc"
http.setRequestHeader "Content-Type:" ,"text/xml; charset=utf-8"
http.setRequestHeader "Content-Length:", "255"
http.setRequestHeader "SOAPAction:" , "http://dc/mdt/MoveComputerToOU"

SOAP = "<?xml version=1.0 encoding=utf-8?>"
SOAP = SOAP &"<soap:Envelope xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:xsd=http://www.w3.org/2001/XMLSchema xmlns:soap=http://schemas.xmlsoap.org/soap/envelope/>"
SOAP = SOAP &"<soap:Body>"
SOAP = SOAP &"<MoveComputerToOU xmlns=http://dc/MDT/>"
SOAP = SOAP &"<ComputerName>test</ComputerName>"
SOAP = SOAP &"<OUPath>OU=staging, DC=Deployment</OUPath>"    
SOAP = SOAP &"</MoveComputerToOU>"
SOAP = SOAP &"</soap:Body>"
SOAP = SOAP &"</soap:Envelope>"


http.send SOAP

Help would be massively appreciated!!!!

Cheers

Adam

Coordinator
Mar 12, 2010 at 8:24 AM

Hi Adam,

I recommend having a look on the example scripts available at http://mdtcustomizations.codeplex.com/releases/view/32093. Have a look in the ZTIDataAccess.vbs script. That's actually doing the "dirty" work of calling the webservice and parsing the response.

Maik

Mar 25, 2010 at 1:43 PM

Hi Maik,

Sorry i havent replied sooner. Ive abandoned the above idea and have just followed the steps on your from your instructions. I am running this on an LTI deployment where the computername is collected in the wizard by the engineer entering it manually.

here is my custom settings.ini

[Settings]
Priority=Default
Properties=_SMSTSOrgName, StagingOU

[Default]
StagingOU=OU=_To be assigned,OU=Company Computers,DC=Domain,DC=co,DC=uk
MachineObjectOU=OU=_To be assigned,OU=Company Computers,DC=Domain,DC=co,DC=uk

[MoveComputerToOU]
WebService=http://mdt-websrv/mdt/ad.asmx/MoveComputerToOU
Parameters=ComputerName,OUPath
MachineObjectOU=OUPath

I have placed the "Z-MoveComputer_StagingOU.wsf" as a run command line in the task sequence under the preinstall group and before the configure task. When this runs the computer doesnt get moved and this is an extract of part of the log:

<![LOG[CHECKING the [MoveComputerToOU] section]LOG]!><time="11:53:12.000+000" date="03-25-2010" component="Z-MoveComputer_StagingOU" context="" type="1" thread="" file="Z-MoveComputer_StagingOU">
<![LOG[No valid specified for parameter 'COMPUTERNAME', web service results could be unpredictable.]LOG]!><time="11:53:12.000+000" date="03-25-2010" component="Z-MoveComputer_StagingOU" context="" type="1" thread="" file="Z-MoveComputer_StagingOU">
<![LOG[No valid specified for parameter 'OUPATH', web service results could be unpredictable.]LOG]!><time="11:53:12.000+000" date="03-25-2010" component="Z-MoveComputer_StagingOU" context="" type="1" thread="" file="Z-MoveComputer_StagingOU">
<![LOG[About to execute web service call using method POST to http://mdt-websrv/mdt/ad.asmx/MoveComputerToOU: ComputerName=&OUPath=]LOG]!><time="11:53:12.000+000" date="03-25-2010" component="Z-MoveComputer_StagingOU" context="" type="1" thread="" file="Z-MoveComputer_StagingOU">
<![LOG[Response from web service: 200 OK]LOG]!><time="11:53:23.000+000" date="03-25-2010" component="Z-MoveComputer_StagingOU" context="" type="1" thread="" file="Z-MoveComputer_StagingOU">
<![LOG[Successfully executed the web service.]LOG]!><time="11:53:23.000+000" date="03-25-2010" component="Z-MoveComputer_StagingOU" context="" type="1" thread="" file="Z-MoveComputer_StagingOU">
<![LOG[Z-MoveComputer_StagingOU processing completed successfully.]LOG]!><time="11:53:23.000+000" date="03-25-2010" component="Z-MoveComputer_StagingOU" context="" type="1" thread="" file="Z-MoveComputer_StagingOU">

It doesn't seem to get the parameters??? im lost as to why, can you maybe shed some light on this??

Much appreciated,

Adam

 

Mar 30, 2010 at 2:02 PM

I'm having the exact same problem.  Still digging into it, but from my logs, it looks as if the parameters are not being passed.

Mar 31, 2010 at 12:14 PM

Ok, I got mine working after some good old fashioned debugging.  I had two problems:

 

1.  The Z-MoveComputer_HostOS.vbs was missing the following line just before oService.SectionName = "MoveComputerToOU":

       oService.iniFile = "customsettings.ini"

2.  I had to fix my MoveComputerToOU section in my customsettings.ini to reflect the correct parameters.  Here is what mine looks like now:

[MoveComputerToOU]
WebService=http://mywebserver/DeploymentWebservice/AD.asmx/MoveComputerToOU
Parameters=OSDComputerName, MachineObjectOU
OSDComputerName=ComputerName
MachineObjectOU=OUPath

 

Now it works like a charm!!  Hope this helps.

Coordinator
Apr 8, 2010 at 9:56 AM

Great, I just updated the sample files with these changes.

Thanks

Maik

Apr 8, 2010 at 12:37 PM

Guys, Poifict, thanks very much, sorry about the delayed posting. been manic. your help was appreciated!!

One last curiosity...... is it possible to move computers around in another domain from the same webservice?? or would a new webservice have to be created??

Thanks,

Adam

Apr 8, 2010 at 12:57 PM

Adam,

Do you mean move a machine between domains, or move machines from different domains within the same domain?

 

For example:

Case 1: MachineA in xxx.com from OU=computers,DC=xxx,DC=com to OU=computers,DC=yyy,DC=com

or

Case 2: MachineA in xxx.com from OU=computers,DC=xxx,DC=com to OU=workstations,DC=xxx,DC=com followed by MachineB in yyy.com from OU=computers,DC=yyy,DC=com to OU=workstations,DC=yyy,DC=com

If Case 1 is what you are attempting, then I would think this cannot be done.  If Case 2 is what you are looking for (and I think it is), then it should be possible.  In my environment, I have 8 domains that I build servers for.  All are pretty much identical, with the exception of domains.  I built a couple of custom panes in MDT that the user specifies which domain the server is for.  I am able to successfully join any of the domains and move computers within that domain.  I think the key is that the service account that the IIS Application Pool uses has access to all domains.  I may be off base here, but wanted to give you something to work off of.  I'm sure if I'm wrong, Maik will set me straight. ;)

Eddie

Apr 8, 2010 at 1:12 PM

Hi Eddie,

Im being a donut. as i read your reply i remembered i had already looked into it. And i think it works. I was wanting to move computers within their domains. but i have multiple domains.

What i have done is setup a second iis directory with the same webservice but with another domains credentials...... this seems to work fine......

I forgot how far i had progressed with it...... One question though. can you have different .ini files within the same deployment share?? rather than using the one custom settings.ini??

Thanks a lot. :-),

Adam

Apr 8, 2010 at 2:50 PM

Adam,

I would think that you can.  You would have to point you scripts to the correct .ini file with the oService.iniFile = "mycustomini.ini" line.  You can also build some logic into the scripts that determines which .ini file to use.

For example:

If JoinDomain.value = "xxx.com" then
     oService.iniFile = "xxx.ini"
Else
     oService.iniFile = "yyy.ini"
End if

Again, this is all in theory, as I currently do not have a need for multiple customsettings.ini files.  If you try and get it to work, though, let me know.

Eddie

Apr 27, 2010 at 7:03 PM

Hi Guys,

In the end. i moved over to using a database, which solved looads of my problems and actually required a lot less work than i thought it would. And with the front end its gonna make peoples lives SOOO much easier!! Cheers Maik,

In regard to the posts above though. i still have a slight snag. all works fine for one domain. happy as larry.... and i have the second webservice set up for second domain which is fine when manually called. But during the build itself it doesnt work. It doesnt look like it is reading the section in the CS.ini i have defined. I "ASSUMED" (famous last words) that if i create another section in the CS.ini exactly the same but with the different path to the movecomputer function for the second domain and reflect that in the staging OU script. E.g.

[MoveComputerToOU]
WebService=http://mdt-websrv/mdt/ad.asmx/MoveComputerToOU
Parameters=OSDComputerName, MachineObjectOU
OSDComputerName=ComputerName
MachineObjectOU=OUPath

[2ndMoveComputerToOU]
WebService=http://mdt-websrv/2ndmdt/ad.asmx/MoveComputerToOU
Parameters=OSDComputerName, MachineObjectOU
OSDComputerName=ComputerName
MachineObjectOU=OUPath

script 1

oService.IniFile = "CustomSettings.ini"
oService.SectionName = "MoveComputerToOU"
          

script 2

oService.IniFile = "CustomSettings.ini"
oService.SectionName = "2ndMoveComputerToOU"
     

Should the above work? its not but at least if you say it should i know to perservere and that im just being an idiot somewhere along the line. Or you might say there is a much simpler way.

Cheers

Adam

Coordinator
May 22, 2010 at 4:24 PM

Hi Adam,

the above should work.

Regards

Maik

May 22, 2010 at 4:34 PM

Hi Maik,

I looked at this again 2 days ago and worked out where i was going wrong. i wasn't changing the class name in the script to match the name of the script. Thanks for your help. Much appreciated.

slightly of subject, just a question, in the front end i was setting access roles for a group so they only had change access only to the computers section, the only way i could give them privelliges to assign a role to a computer was to also assign change rights to the packages section also, is that right??

Great front end and services. Cheers

Adam

Coordinator
May 22, 2010 at 6:26 PM

Thanks ;-)

And regarding the error. Yes, this is a known bug in the current version. I'm a bit late with the next update but this should be fixed in the next relase. See http://mdtwebfrontend.codeplex.com/WorkItem/View.aspx?WorkItemId=5827 for reference.

Regards

Maik

Aug 31, 2010 at 12:07 AM

Hi Miak,

My web service is running great but when I try to move a computer in the tas sequnce i keep getting this message.

"No valid specified for parameter 'MACHINEOBJECTOU', web service results could be unpredictable."

If added the customsettings.ini to my toolkit package and I just cant seem to get it working.

Thanks for any help you can provide.

 

Aug 31, 2010 at 7:08 PM

I got it working by doing the following:

My goal was to move desktops to the Desktops OU and Laptops to the Laptops OU.

I got ride of my error message above by doing this:

1) Created two Gather Tasks with Task Sequence variables one IsLapTop = True and one ISLaptop False, each task also had a different rules files with the MachineObjectOU set as needed(Customsettings.ini)

2) Right after the toolkit package I  added TWO Run Commandlines with the same Task Sequence variables(IsLaptop = True/False) to run Z_MoveComptuer_TargetOU but also set a package for each that also had the correctly configured customsettings.ini file.

This may not be the prettiest solution but it's working :-) 

Sep 15, 2010 at 3:46 PM

Hi guys.

I'm probably doing the same sort of thing as jima101, but I'm trying to keep things simple.

I'm wondering whether I can use the TS variable in my SCCM/MDT TS that is set depending on whether the machine is a laptop / desktop [using IsDesktop or IsLaptop etc].

I'd rather use just one customsettings.ini really for both scenario's as I've managed to do this for everything else, so I'm wondering whether I could change things to be like the following:

[MoveComputerToOU]
WebService=http://MyWebServer/Deployment/ad.asmx/MoveComputerToOU
Parameters=OSDComputerName,MachineObjectOU
OSDComputerName=ComputerName
MachineObjectOU=TSMachineObjectOU

and then in my OS Task Sequence, place a Set Task Sequence Variable right at the begining of the process that will define that variable - based on either a desktop or a laptop.

Just wondering whether that would work or whether theres a similar way to do it without doubling up on customsettings.ini files etc.?

Cheers for a very handy tool - they should really implement your webservice scripts and stuff into MDT/SCCM as I'm surprised everyone isnt crying out for being able to do things like Computer Obj moving / manipulating etc.

I'm really running out of time to get into the depths of things fully before we have to start rolling out the deployments of Win7 using this set up (aka monday it starts) so if you can help, please let me know :)

Best Regards
Nathan.

Sep 15, 2010 at 4:14 PM

Could you not have two “set task sequence variables” steps in your task sequences at the beginning with if statements under options for Islaptop and IsDesktop (one for each). E.g.:

set task sequence variables step 1

Under options:

If Islaptop = true

Under Properties:

machineobjectou = “OU=laptops, OU=Machines, DC=domain, DC=local”

Set task sequence variables step 2

Under options:

If IsDesktop = true

Under Properties:

machineobjectou = “OU=Desktops, OU=Machines, DC=domain, DC=local”

and in your “customsettings.ini” have

[MoveComputerToOU]
WebService=http://MyWebServer/Deployment/ad.asmx/MoveComputerToOU
Parameters=OSDComputerName,MachineObjectOU
OSDComputerName=ComputerName
MachineObjectOU=OUPath

In your DB or in the customsettings.ini set machineObjectOU to a standard path in case it doesn’t get set in the TS. E.g. :

machineobjectou = “OU=Unknown, OU=Machines, DC=domain, DC=local”

Just a suggestion….

Cheers

Adam

From: tarquel [mailto:notifications@codeplex.com]
Sent: Wednesday, September 15, 2010 4:47 PM
To: Driver Adam
Subject: Re: Calling MoveComputerToOU WebService from VBS [mdtcustomizations:203465]

From: tarquel

Hi guys.

I'm probably doing the same sort of thing as jima101, but I'm trying to keep things simple.

I'm wondering whether I can use the TS variable in my SCCM/MDT TS that is set depending on whether the machine is a laptop / desktop [using IsDesktop or IsLaptop etc].

I'd rather use just one customsettings.ini really for both scenario's as I've managed to do this for everything else, so I'm wondering whether I could change things to be like the following:

[MoveComputerToOU]
WebService=http://MyWebServer/Deployment/ad.asmx/MoveComputerToOU
Parameters=OSDComputerName,MachineObjectOU
OSDComputerName=ComputerName
MachineObjectOU=TSMachineObjectOU

and then in my OS Task Sequence, place a Set Task Sequence Variable right at the begining of the process that will define that variable - based on either a desktop or a laptop.

Just wondering whether that would work or whether theres a similar way to do it without doubling up on customsettings.ini files etc.?

Cheers for a very handy tool - they should really implement your webservice scripts and stuff into MDT/SCCM as I'm surprised everyone isnt crying out for being able to do things like Computer Obj moving / manipulating etc.

I'm really running out of time to get into the depths of things fully before we have to start rolling out the deployments of Win7 using this set up (aka monday it starts) so if you can help, please let me know :)

Best Regards
Nathan.

Read the full discussion online.

To add a post to this discussion, reply to this email (mdtcustomizations@discussions.codeplex.com)

To start a new discussion for this project, email mdtcustomizations@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com

***************************************************************************

This e-mail is confidential and privileged. If you are not the intended recipient please accept our apologies; please do not disclose, copy or distribute information in this e-mail or take any action in reliance on its

contents: to do so is strictly prohibited and may be unlawful. Please inform us that this message has gone astray before deleting it. Thank you for your co-operation.

This footnote also confirms that this email message has been swept for the presence of computer viruses.

***************************************************************************

Sep 16, 2010 at 8:47 AM

It all worked a treat - glad i was on the right track tho :)

For info on what worked:

From the deployment logs [in SCCM] my initial attempt failed as the webservice reported that it wanted it as OUPath i.e. MachineObjectOU=OUPath

Put that back and kept the customsettings.ini as you said, and thankfully, it used the correct condition in the TS and all worked lovely :)

Many thanks for the helping hand Adam :)