Use different credenatils to pull the report from other domain servers

attached script works well in the same domain servers but I want to use different credential to be used by this script in order to run against another domain servers.. we have multiple domains in a same forest and i need some help in updating the script...
DiskSpace-Report-HTML.txt
LVL 1
Affaan AbyazAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jason CrawfordTransport NinjaCommented:
Have you tried using Invoke-Command with the -Credential property?  You'll have to cache the credentials to a variable using Get-Credential so something like:

$creds = Get-Credential
Invoke-Command -ComputerName <server name> -ScriptBlock {Insert code} -Credential $creds

Open in new window

0
Affaan AbyazAuthor Commented:
I think I missed to mention that its a VBScript.. Please save it with .vbs extension to check on the code.
0
RobSampsonCommented:
Hi, try changing this line:
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Open in new window


to this
	Set objLocator=CreateObject("WbemScripting.SWbemLocator")
	Set objWMIService=objLocator.ConnectServer(strComputer, "root\default", "domain\remoteuser", "remotepassword")

Open in new window


then change remoteuser and remotepassword as required.

Rob.
0
Introducing the "443 Security Simplified" Podcast

This new podcast puts you inside the minds of leading white-hat hackers and security researchers. Hosts Marc Laliberte and Corey Nachreiner turn complex security concepts into easily understood and actionable insights on the latest cyber security headlines and trends.

Affaan AbyazAuthor Commented:
by anyway can we encrypt the credentials ?
Please note that I will have to schedule it on the server as a job aswell..
0
Affaan AbyazAuthor Commented:
Hi Rob,

I have updated the script and executed the same from different domain.. its did not pop-up any error message and executing but in the report its not giving any values either.. attached is the report
2015-11-02_18-52-21.png
0
RobSampsonCommented:
Sorry, it wasn't meant to have root\default in it.  It should be root\CimV2
	Set objLocator=CreateObject("WbemScripting.SWbemLocator")
	Set objWMIService=objLocator.ConnectServer(strComputer, "root\CimV2", "domain\remoteuser", "remotepassword")

Open in new window


As for encrypting the password, you can't really do that in VBScript.  What you could do to make it a bit more secure, is have the script accept the username and password as script parameters, and then add those parameters to the scheduled task.  To make it a bit more secure, if the script did some known string manipulation on the passed parameters, you can specify a reverse engineered parameter to the script, and have the script manipulate that into the correct password.

For example, if your password was mypass you could pass
90!33
to the script, and in the script have this
strPassword = ""
For intChr = 1 To Len(strPassed)
	If intChr = 1 Then
		strPassword = Chr(Asc(Mid(strPassed, intChr, 1)) + 64)
	Else
		strPassword = strPassword & Chr(Asc(Mid(strPassed, intChr, 1)) + 64)
	End If
Next

Open in new window


and strPassword would contain the correct password.  This way, the password can only be sniffed out at run time, which is unlikely, but not impossible.

Regards,

Rob.
0
Affaan AbyazAuthor Commented:
Thanks Rob.. that works well.. I am able to use it with different credentails and works well.. one last query and its about the same thing hidding the credentails in vbscript.. I am thinking about coverting vb to exe and the problem I found is that it has a variable set for the location. Line 53 says OutputDir = "C:\HP\Wintel\Admin_Tasks\DiskSpace" and if I replace it with ".\" in order to check for servers.txt and my outfiles to be created in the same folder where as I am running this script, it is not working...

could you please help me in fixing this ? and then we can have this questions closed gracefully :D
0
RobSampsonCommented:
Hi, some EXE conversions still create a temporary VBS (which is plain text) to execute it, then delete it immediately after.  You may want to try to find an EXE packager that does not do this.  I think the latest one from VBSEdit doesn't do this anymore.

You can try changing the OutputDir to this
OutputDir = Replace(WScript.ScriptFullName, WScript.ScriptName, "")

and then echoing that path with
MsgBox OutputDir

to see what directory it picks, but that should work.

Rob.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Affaan AbyazAuthor Commented:
Thanks Rob. As always your solution works.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.