[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 292
  • Last Modified:

How I create a script to restrict computer acces filling the "Log On To" ("userWorkstations") field, from a text file

Hello my dear experts,
I use this script to fill the "Log on To" field on AD:
Set objUser = GetObject _
  ("LDAP://cn=user (USR),ou=3rd OU,ou=2nd,ou=1st ou,dc=bpco,dc=com")
 objUser.Put "userWorkstations", "A,B,C,D,E"
objUser.SetInfo
Because of frequent changes inside the net, a very cool improvement will be to be able to use this same script, but allowing to pull the userWorkstations from a file text with a pre-defined computer ser list
Can you help me?
0
bpco
Asked:
bpco
  • 2
1 Solution
 
Chris DentPowerShell DeveloperCommented:

Hey,

Should be pretty straight-forward.

Const WORKSTATION_FILE = "TheList.txt"

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFile : Set objFile = objFSO.OpenTextFile(WORKSTATION_FILE, 1, False, 0)

strWorkstations = objFile.ReadAll()

Now it's just down to how you want the file to be formatted. If it's just a list it can be popped straight in:

Set objUser = GetObject _
  ("LDAP://cn=user (USR),ou=3rd OU,ou=2nd,ou=1st ou,dc=bpco,dc=com")
objUser.Put "userWorkstations", strWorkstations
objUser.SetInfo

Where the list in the file would be:

workstation1,workstation2,workstation3

Chris
0
 
bpcoAuthor Commented:
Worked very well, thanks Chris!
0
 
bpcoAuthor Commented:
I've should added more points if there were more solutions, like using csv tables for example instead of plain txt files... however, I've got the script well running
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now