Werbung: SecurityConsole.de verwaltet Ihre Computer mit Security Essentails aus der Cloud!
30 Tage kostenfrei testen und 20% Rabatt für Ihre Bestellung mit Promocode: WBF2685582
(Promocode gültig bis 31.12.2011)

Group:  English: Windows Server » microsoft.public.windows.server.scripting
Thread: Multiple computers

HTVi
TV Discussion Newsgroups

Multiple computers
morjo619 6/26/2007 5:45:01 PM
Hello,

Trying to figure out a way to run the script below for group of computers,
could someone give a hand? Script adds a local user to the machine I specify,
I need to to be able to do it in bulk. Thanks!

Script:
strComputer = "machin1"
Set colAccounts = GetObject("WinNT://" & strComputer & "")
Set objUser = colAccounts.Create("user", "user1")
objUser.SetPassword "mypassword"
objUser.SetInfo

Re: Multiple computers
"Richard Mueller [MVP]" <rlmueller-nospam[ at ]ameritech.nospam.net> 6/26/2007 7:15:04 PM
morjo619 wrote:

[Quoted Text]
> Trying to figure out a way to run the script below for group of computers,
> could someone give a hand? Script adds a local user to the machine I
> specify,
> I need to to be able to do it in bulk. Thanks!
>
> Script:
> strComputer = "machin1"
> Set colAccounts = GetObject("WinNT://" & strComputer & "")
> Set objUser = colAccounts.Create("user", "user1")
> objUser.SetPassword "mypassword"
> objUser.SetInfo
>

One idea would be to read computer names from a text file, using the
FileSystemObject. For example:
============
Const ForReading = 1

' Specify text file with NetBIOS names of computers.
strFile = "c:\scripts\computers.txt"

' Open the text file for read access.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFile, ForReading)

' Read names from file.
Do Until objFile.AtEndOfStream
strComputer = Trim(objFile.ReadLine)
' Skip blank lines.
If (strComputer <> "") Then
' Perform task on each computer.
Set colAccounts = GetObject("WinNT://" & strComputer)
Set objUser = colAccounts.Create("user", "user1")
objUser.SetPassword "mypassword"
objUser.SetInfo
End If
Loop

' Clean up.
objFile.Close

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--


Re: Multiple computers
morjo619 6/26/2007 8:12:02 PM
Richard,

Thank you for your help....looks like it's going to work. Do you know if
it'll continue if comes accross a machine that it can't connect to?

"Richard Mueller [MVP]" wrote:

[Quoted Text]
> morjo619 wrote:
>
> > Trying to figure out a way to run the script below for group of computers,
> > could someone give a hand? Script adds a local user to the machine I
> > specify,
> > I need to to be able to do it in bulk. Thanks!
> >
> > Script:
> > strComputer = "machin1"
> > Set colAccounts = GetObject("WinNT://" & strComputer & "")
> > Set objUser = colAccounts.Create("user", "user1")
> > objUser.SetPassword "mypassword"
> > objUser.SetInfo
> >
>
> One idea would be to read computer names from a text file, using the
> FileSystemObject. For example:
> ============
> Const ForReading = 1
>
> ' Specify text file with NetBIOS names of computers.
> strFile = "c:\scripts\computers.txt"
>
> ' Open the text file for read access.
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objFile = objFSO.OpenTextFile(strFile, ForReading)
>
> ' Read names from file.
> Do Until objFile.AtEndOfStream
> strComputer = Trim(objFile.ReadLine)
> ' Skip blank lines.
> If (strComputer <> "") Then
> ' Perform task on each computer.
> Set colAccounts = GetObject("WinNT://" & strComputer)
> Set objUser = colAccounts.Create("user", "user1")
> objUser.SetPassword "mypassword"
> objUser.SetInfo
> End If
> Loop
>
> ' Clean up.
> objFile.Close
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
> --
>
>
>
Re: Multiple computers
"Richard Mueller [MVP]" <rlmueller-nospam[ at ]ameritech.nospam.net> 6/26/2007 8:38:59 PM
No, the script will halt. To trap this possible error:
============
'....
Do Until objFile.AtEndOfStream
strComputer = Trim(objFile.ReadLine)
' Skip blank lines.
If (strComputer <> "") Then
' Perform task on each computer.
' Trap error if computer not available.
On Error Resume Next
Set colAccounts = GetObject("WinNT://" & strComputer)
If (Err.Number = 0) Then
' Also trap error if you lack permission to create user.
Set objUser = colAccounts.Create("user", "user1")
If (Err.Number = 0) Then
On Error GoTo 0
objUser.SetPassword "mypassword"
objUser.SetInfo
Else
On Error GoTo 0
Wscript.Echo "Unable to create user on " & strComputer
End If
Else
On Error GoTo 0
Wscript.Echo "Unable to connect to " & strComputer
End If
End If
Loop
'....
--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--
"morjo619" <morjo619[ at ]discussions.microsoft.com> wrote in message
news:79E0EC8E-8588-47D1-803B-AF27F05D7410[ at ]microsoft.com...
[Quoted Text]
> Richard,
>
> Thank you for your help....looks like it's going to work. Do you know if
> it'll continue if comes accross a machine that it can't connect to?
>
> "Richard Mueller [MVP]" wrote:
>
>> morjo619 wrote:
>>
>> > Trying to figure out a way to run the script below for group of
>> > computers,
>> > could someone give a hand? Script adds a local user to the machine I
>> > specify,
>> > I need to to be able to do it in bulk. Thanks!
>> >
>> > Script:
>> > strComputer = "machin1"
>> > Set colAccounts = GetObject("WinNT://" & strComputer & "")
>> > Set objUser = colAccounts.Create("user", "user1")
>> > objUser.SetPassword "mypassword"
>> > objUser.SetInfo
>> >
>>
>> One idea would be to read computer names from a text file, using the
>> FileSystemObject. For example:
>> ============
>> Const ForReading = 1
>>
>> ' Specify text file with NetBIOS names of computers.
>> strFile = "c:\scripts\computers.txt"
>>
>> ' Open the text file for read access.
>> Set objFSO = CreateObject("Scripting.FileSystemObject")
>> Set objFile = objFSO.OpenTextFile(strFile, ForReading)
>>
>> ' Read names from file.
>> Do Until objFile.AtEndOfStream
>> strComputer = Trim(objFile.ReadLine)
>> ' Skip blank lines.
>> If (strComputer <> "") Then
>> ' Perform task on each computer.
>> Set colAccounts = GetObject("WinNT://" & strComputer)
>> Set objUser = colAccounts.Create("user", "user1")
>> objUser.SetPassword "mypassword"
>> objUser.SetInfo
>> End If
>> Loop
>>
>> ' Clean up.
>> objFile.Close
>>
>> --
>> Richard Mueller
>> Microsoft MVP Scripting and ADSI
>> Hilltop Lab - http://www.rlmueller.net
>> --
>>
>>
>>


Re: Multiple computers
morjo619 6/26/2007 9:24:01 PM
You're da the man! I noticed that once it creates the account it doesn't add
it to local users group, is there an easy way to do that also?

"Richard Mueller [MVP]" wrote:

[Quoted Text]
> No, the script will halt. To trap this possible error:
> ============
> '....
> Do Until objFile.AtEndOfStream
> strComputer = Trim(objFile.ReadLine)
> ' Skip blank lines.
> If (strComputer <> "") Then
> ' Perform task on each computer.
> ' Trap error if computer not available.
> On Error Resume Next
> Set colAccounts = GetObject("WinNT://" & strComputer)
> If (Err.Number = 0) Then
> ' Also trap error if you lack permission to create user.
> Set objUser = colAccounts.Create("user", "user1")
> If (Err.Number = 0) Then
> On Error GoTo 0
> objUser.SetPassword "mypassword"
> objUser.SetInfo
> Else
> On Error GoTo 0
> Wscript.Echo "Unable to create user on " & strComputer
> End If
> Else
> On Error GoTo 0
> Wscript.Echo "Unable to connect to " & strComputer
> End If
> End If
> Loop
> '....
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
> --
> "morjo619" <morjo619[ at ]discussions.microsoft.com> wrote in message
> news:79E0EC8E-8588-47D1-803B-AF27F05D7410[ at ]microsoft.com...
> > Richard,
> >
> > Thank you for your help....looks like it's going to work. Do you know if
> > it'll continue if comes accross a machine that it can't connect to?
> >
> > "Richard Mueller [MVP]" wrote:
> >
> >> morjo619 wrote:
> >>
> >> > Trying to figure out a way to run the script below for group of
> >> > computers,
> >> > could someone give a hand? Script adds a local user to the machine I
> >> > specify,
> >> > I need to to be able to do it in bulk. Thanks!
> >> >
> >> > Script:
> >> > strComputer = "machin1"
> >> > Set colAccounts = GetObject("WinNT://" & strComputer & "")
> >> > Set objUser = colAccounts.Create("user", "user1")
> >> > objUser.SetPassword "mypassword"
> >> > objUser.SetInfo
> >> >
> >>
> >> One idea would be to read computer names from a text file, using the
> >> FileSystemObject. For example:
> >> ============
> >> Const ForReading = 1
> >>
> >> ' Specify text file with NetBIOS names of computers.
> >> strFile = "c:\scripts\computers.txt"
> >>
> >> ' Open the text file for read access.
> >> Set objFSO = CreateObject("Scripting.FileSystemObject")
> >> Set objFile = objFSO.OpenTextFile(strFile, ForReading)
> >>
> >> ' Read names from file.
> >> Do Until objFile.AtEndOfStream
> >> strComputer = Trim(objFile.ReadLine)
> >> ' Skip blank lines.
> >> If (strComputer <> "") Then
> >> ' Perform task on each computer.
> >> Set colAccounts = GetObject("WinNT://" & strComputer)
> >> Set objUser = colAccounts.Create("user", "user1")
> >> objUser.SetPassword "mypassword"
> >> objUser.SetInfo
> >> End If
> >> Loop
> >>
> >> ' Clean up.
> >> objFile.Close
> >>
> >> --
> >> Richard Mueller
> >> Microsoft MVP Scripting and ADSI
> >> Hilltop Lab - http://www.rlmueller.net
> >> --
> >>
> >>
> >>
>
>
>
Re: Multiple computers
"Richard Mueller [MVP]" <rlmueller-nospam[ at ]ameritech.nospam.net> 6/27/2007 12:35:12 AM
To add a local user to a local group, bind to the group object and use the
Add method of the group object. Pass the AdsPath of the prospective member
to the method. Since some clients may not have a Users group, it would be
wise to trap the possible error. For example:
=========
'....
Do Until objFile.AtEndOfStream
strComputer = Trim(objFile.ReadLine)
' Skip blank lines.
If (strComputer <> "") Then
' Perform task on each computer.
' Trap error if computer not available.
On Error Resume Next
Set colAccounts = GetObject("WinNT://" & strComputer)
If (Err.Number = 0) Then
' Also trap error if you lack permission to create user.
Set objUser = colAccounts.Create("user", "user1")
If (Err.Number = 0) Then
On Error GoTo 0
objUser.SetPassword "mypassword"
objUser.SetInfo
' Bind to local Users group. Trap error if group not found.
On Error Resume Next
Set objGroup = GetObject("WinNT://" & strComputer &
"/Users,group")
If (Err.Number = 0) Then
On Error GoTo 0
objGroup.Add objUser.AdsPath
Else
On Error GoTo 0
Wscript.Echo "Unable to add to Users group on " &
strComputer
End If
Else
On Error GoTo 0
Wscript.Echo "Unable to create user on " & strComputer
End If
Else
On Error GoTo 0
Wscript.Echo "Unable to connect to " & strComputer
End If
End If
Loop
'....

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--

"morjo619" <morjo619[ at ]discussions.microsoft.com> wrote in message
news:587DD788-789A-4BF7-9A86-D9C5E25309FC[ at ]microsoft.com...
[Quoted Text]
> You're da the man! I noticed that once it creates the account it doesn't
> add
> it to local users group, is there an easy way to do that also?
>
> "Richard Mueller [MVP]" wrote:
>
>> No, the script will halt. To trap this possible error:
>> ============
>> '....
>> Do Until objFile.AtEndOfStream
>> strComputer = Trim(objFile.ReadLine)
>> ' Skip blank lines.
>> If (strComputer <> "") Then
>> ' Perform task on each computer.
>> ' Trap error if computer not available.
>> On Error Resume Next
>> Set colAccounts = GetObject("WinNT://" & strComputer)
>> If (Err.Number = 0) Then
>> ' Also trap error if you lack permission to create user.
>> Set objUser = colAccounts.Create("user", "user1")
>> If (Err.Number = 0) Then
>> On Error GoTo 0
>> objUser.SetPassword "mypassword"
>> objUser.SetInfo
>> Else
>> On Error GoTo 0
>> Wscript.Echo "Unable to create user on " & strComputer
>> End If
>> Else
>> On Error GoTo 0
>> Wscript.Echo "Unable to connect to " & strComputer
>> End If
>> End If
>> Loop
>> '....
>> --
>> Richard Mueller
>> Microsoft MVP Scripting and ADSI
>> Hilltop Lab - http://www.rlmueller.net
>> --
>> "morjo619" <morjo619[ at ]discussions.microsoft.com> wrote in message
>> news:79E0EC8E-8588-47D1-803B-AF27F05D7410[ at ]microsoft.com...
>> > Richard,
>> >
>> > Thank you for your help....looks like it's going to work. Do you know
>> > if
>> > it'll continue if comes accross a machine that it can't connect to?
>> >
>> > "Richard Mueller [MVP]" wrote:
>> >
>> >> morjo619 wrote:
>> >>
>> >> > Trying to figure out a way to run the script below for group of
>> >> > computers,
>> >> > could someone give a hand? Script adds a local user to the machine I
>> >> > specify,
>> >> > I need to to be able to do it in bulk. Thanks!
>> >> >
>> >> > Script:
>> >> > strComputer = "machin1"
>> >> > Set colAccounts = GetObject("WinNT://" & strComputer & "")
>> >> > Set objUser = colAccounts.Create("user", "user1")
>> >> > objUser.SetPassword "mypassword"
>> >> > objUser.SetInfo
>> >> >
>> >>
>> >> One idea would be to read computer names from a text file, using the
>> >> FileSystemObject. For example:
>> >> ============
>> >> Const ForReading = 1
>> >>
>> >> ' Specify text file with NetBIOS names of computers.
>> >> strFile = "c:\scripts\computers.txt"
>> >>
>> >> ' Open the text file for read access.
>> >> Set objFSO = CreateObject("Scripting.FileSystemObject")
>> >> Set objFile = objFSO.OpenTextFile(strFile, ForReading)
>> >>
>> >> ' Read names from file.
>> >> Do Until objFile.AtEndOfStream
>> >> strComputer = Trim(objFile.ReadLine)
>> >> ' Skip blank lines.
>> >> If (strComputer <> "") Then
>> >> ' Perform task on each computer.
>> >> Set colAccounts = GetObject("WinNT://" & strComputer)
>> >> Set objUser = colAccounts.Create("user", "user1")
>> >> objUser.SetPassword "mypassword"
>> >> objUser.SetInfo
>> >> End If
>> >> Loop
>> >>
>> >> ' Clean up.
>> >> objFile.Close
>> >>
>> >> --
>> >> Richard Mueller
>> >> Microsoft MVP Scripting and ADSI
>> >> Hilltop Lab - http://www.rlmueller.net
>> >> --
>> >>
>> >>
>> >>
>>
>>
>>


Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net
Suche nach Orten, Städten, Postleitzahlen, Vorwahlen, Kfz-Kennzeichen