Converting a script which updates AD Account Info from VBS to PowerShell

Hey Scripting Guy! I need to convert a VBScript into Windows PowerShell 2.0. The script calls Internet Explorer in kiosk mode, retrieves some information from the Customer (Phone Number, Department)  & then updates AD account information using an account that has the relevant rights

The VBScript I have is:

'WScript.Sleep 1000 * 10
sADAdminUser = "domain\username"
sADAdminPass = "password"
 
On Error Resume Next
 
Const ADS_NAME_INITTYPE_DOMAIN = 1
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
Const ADS_SECURE_AUTHENTICATION = &H1
 
Set oWShell = CreateObject("Wscript.Shell")
sUserName = oWShell.ExpandEnvironmentStrings("%username%")
 
Set iAdRootDSE = GetObject("LDAP://RootDSE")
sDomain = Replace(Replace(Lcase(iAdRootDSE.Get("defaultNamingContext")), "dc=", ""), ",", ".")
Set iAdRootDSE = Nothing

Set oNameTranslate = CreateObject("NameTranslate")
oNameTranslate.Init ADS_NAME_INITTYPE_DOMAIN, sDomain
oNameTranslate.Set ADS_NAME_TYPE_NT4, "CORP\" & sUserName
sDN = oNameTranslate.Get(ADS_NAME_TYPE_1779)
If Err.Number = 0 Then
    Set oLDAP = GetObject("LDAP:")
    Set oUser = oLDAP.OpenDSObject("LDAP://" & sDN, sADAdminUser, sADAdminPass, ADS_SECURE_AUTHENTICATION)
    If LCase(oUser.extensionAttribute3) <> "sometext" Then
  Set objExplorer = WScript.CreateObject("InternetExplorer.Application")
  objExplorer.Navigate "about:blank"
  objExplorer.ToolBar = 0
  objExplorer.FullScreen = True
  objExplorer.StatusBar = 0
  objExplorer.Visible = 1
  objExplorer.resizable = No
  objExplorer.menubar = 0
  objExplorer.Navigate "weblink"
 oUser.SetInfo
    End If
End If
 
Set oUser = Nothing
Set oLDAP = Nothing
Set oTranslate = Nothing
Set oWShell = Nothing

Please help :)

August 21st, 2015 9:14am

Hi,

Do you have a specific question?

This might help you get started:

https://technet.microsoft.com/en-us/library/ee221101.aspx

Let us know if you get stuck. If you do, post your current code and your errors and we can go from there.

Free Windows Admin Tool Kit Click here and download it now
August 21st, 2015 9:33am

The VBScript does nothing but display a web page.
August 21st, 2015 11:29am

Hey Scripting Guy! I need to convert a VBScript into Windows PowerShell 2.0. ...

<lines of a script posted here>

Please help :)

Sorry, but this isn't a free "someone please rewrite this code for me in PowerShell" service.

Keep in mind that the respondents in this forum are volunteers who answer scripting questions for free.

Asking someone to rewrite a script in a different language for you is, at the least, rather presumptuous.

Free Windows Admin Tool Kit Click here and download it now
August 21st, 2015 12:25pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics