| Author | Messages | |
gilvicente.ad
Posts:8
 | | 02/01/2012 8:35 PM |
| I'm looking for a vbscript that checks if the value that will gonna be signed to an employeeID field already exists in the other users accounts.
I starting using this generic code for employeeID insertion:
dim oVar, oUsr, tmp, title, text1
set oVar = wscript.arguments
set oUsr = getobject(oVar(0))
title = "EmployeeID Insertion"
text1 = "Actual EmployeeID: " & oUsr.employeeID & vbcrlf & vbcrlf & "Insert or Update the EmployeeID:" & vbcrlf & vbcrlf & "(Ex: 75309889078)"
tmp = inputbox(text1,title)
if tmp <> "" then oUsr.put "employeeID",tmp
oUsr.setinfo
set oUsr = Nothing
wscript.quit
But now I have to tune the code with this condition, Can't exists two users accounts with the same employeeID, and this field have to be 11 numeric characters.
| | | |
| Parzival
Posts:108
 | | 02/01/2012 8:37 PM |
| You probably could end up with something like this: (although not tested etc etc,.. and possibly could be optimized)
but i would say.. you could also go for powershell..
Roelf
dim oVar, oUsr, tmp, title, text1
set oVar = wscript.arguments
set oUsr = getobject(oVar(0))
title = "EmployeeID Insertion"
text1 = "Actual EmployeeID: " & oUsr.employeeID & vbcrlf & vbcrlf & "Insert or Update the EmployeeID:" & vbcrlf & vbcrlf & "(Ex: 75309889078)"
tmp = inputbox(text1,title)
if tmp <> "" then
on error resume next
int=Cint(tmp) 'See if we can convert the input to a number, if not it contains normal characters
if error.numer >0 Then
wscript.echo "NOT A NUMBER"
wscript.quit
end if
If Len(tmp) <> 11 Then 'check the lenght of the string entered to see if it is longer or shorter than 11 characters
wscript.echo "NOT 11 Characters"
wscript.quit
End if
If FindDuplicates(tmp)=true 'calling the function
oUsr.put "employeeID",tmp Else wscript.echo "Duplicate found" End if
Function FindDuplicates (inbound) FindDuplicates=false Set CNUsers = GetObject ("LDAP://OU=YOUROU,DC=YOURDOMAIN,DC=org") 'retrieve all objects from an OU For Each User in CNUsers If Ucase(user.employeeID)=UCase(inbound) Then 'did we match one or more users to the input WScript.Echo "one" WScript.Echo " DisplayName: " & user.displayname & " - Legacy DN=: " & LegacDn FindDuplicates=True 'if yes set to true End If Next End Function From: activedir-owner@mail.activedir.org<mailto:activedir-owner@mail.activedir.org> [mailto:activedir-owner@mail.activedir.org]<mailto:[mailto:activedir-owner@mail.activedir.org]> On Behalf Of Gil Sent: Tuesday, January 31, 2012 7:58 PM To: ActiveDir@mail.activedir.org<mailto:ActiveDir@mail.activedir.org> Subject: [ActiveDir] Check Duplicate EmployeeID field
I'm looking for a vbscript that checks if the value that will gonna be signed to an employeeID field already exists in the other users accounts.
I starting using this generic code for employeeID insertion:
dim oVar, oUsr, tmp, title, text1
set oVar = wscript.arguments
set oUsr = getobject(oVar(0))
title = "EmployeeID Insertion"
text1 = "Actual EmployeeID: " & oUsr.employeeID & vbcrlf & vbcrlf & "Insert or Update the EmployeeID:" & vbcrlf & vbcrlf & "(Ex: 75309889078)"
tmp = inputbox(text1,title)
if tmp <> "" then oUsr.put "employeeID",tmp
oUsr.setinfo
set oUsr = Nothing
wscript.quit
But now I have to tune the code with this condition, Can't exists two users accounts with the same employeeID, and this field have to be 11 numeric characters.
| | | |
| pradeeprawat85
Posts:19
 | | 02/01/2012 8:39 PM |
| If you have PowerShell with MS AD cmdlets you can try this code:
$employeeID = Read-Host "Enter the employeeID" if(($employeeID -as [Int64]) -and ($employeeID.Length -ge 11)) { Write-Host "CRITERIA MATCHED : VALID EMPLOYEE ID FORMAT" -ForegroundColor Green $checkeID = Get-ADUser -Filter {EmployeeID -eq $employeeID} | Select-Object -ExpandProperty SamAccountName if($checkeID) { Write-Host "$employeeID ALREADY ASSIGNED TO: $checkeID" -ForegroundColor Yellow } else { Write-Host "$employeeID NOT ASSIGNED TO ANY USER." $assigneid = Read-Host "ENTER A VALID USERNAME TO ASSIGN EMPLOYEE ID $employeeID" $checkuser = Get-ADUser -Filter {SamAccountName -eq $assigneid} | Select-Object -ExpandProperty SamAccountName if($checkuser) { Set-ADUser -Identity $checkuser -EmployeeID $employeeID -Confirm:$false Write-Host "$employeeID ASSIGNED TO $checkuser" -ForegroundColor Green } else { Write-Host "$assigneid NOT FOUND OR INCORRECT NAME" -ForegroundColor Red } } } else { Write-Host "CRITERIA NOT MATCHED: employeeID must be an integer value or must contain 11 numeric characters" -ForegroundColor Red }
On Wed, Feb 1, 2012 at 1:11 PM, Roelf Zomerman <roelf.zomerman@avanade.com>wrote:
> You probably could end up with something like this: (although not tested > etc etc,.. and possibly could be optimized)**** > > ** ** > > but i would say.. you could also go for powershell..**** > > ** ** > > Roelf**** > > ** ** > > dim oVar, oUsr, tmp, title, text1**** > > ** ** > > set oVar = wscript.arguments**** > > ** ** > > set oUsr = getobject(oVar(0))**** > > ** ** > > title = "EmployeeID Insertion"**** > > ** ** > > text1 = "Actual EmployeeID: " & oUsr.employeeID & vbcrlf & vbcrlf & "Insert or Update the EmployeeID:" & vbcrlf & vbcrlf & "(Ex: 75309889078)"**** > > ** ** > > tmp = inputbox(text1,title)**** > > if tmp <> "" then **** > > on error resume next**** > > int=Cint(tmp) ‘See if we can convert the input to a number, if not it contains normal characters**** > > if error.numer >0 Then**** > > wscript.echo “NOT A NUMBER”**** > > wscript.quit**** > > end if**** > > If Len(tmp) <> 11 Then ‘check the lenght of the string entered to see if it is longer or shorter than 11 characters**** > > wscript.echo “NOT 11 Characters”**** > > wscript.quit**** > > End if**** > > If FindDuplicates(tmp)=true ‘calling the function**** > > oUsr.put "employeeID",tmp**** > > Else**** > > wscript.echo “Duplicate found”**** > > End if**** > > ** ** > > ** ** > > Function FindDuplicates (inbound)**** > > FindDuplicates=false**** > > Set CNUsers = GetObject > ("LDAP://OU=YOUROU,DC=YOURDOMAIN,DC=org") ‘retrieve all objects from an OU > **** > > For Each User in CNUsers**** > > If Ucase(user.employeeID)=UCase(inbound) Then ‘did we > match one or more users to the input**** > > WScript.Echo "one"**** > > WScript.Echo " DisplayName: " & > user.displayname & " - Legacy DN=: " & LegacDn**** > > FindDuplicates=True ‘if yes set to true**** > > End If**** > > Next**** > > End Function**** > > *From:* activedir-owner@mail.activedir.org > [mailto:activedir-owner@mail.activedir.org] *On Behalf Of *Gil > *Sent:* Tuesday, January 31, 2012 7:58 PM > > *To:* ActiveDir@mail.activedir.org > *Subject:* [ActiveDir] Check Duplicate EmployeeID field**** > > ** ** > > ** ** > > I'm looking for a vbscript that checks if the value that will gonna be signed to an employeeID field already exists in the other users accounts.**** > > ** ** > > I starting using this generic code for employeeID insertion:**** > > ** ** > > dim oVar, oUsr, tmp, title, text1**** > > ** ** > > set oVar = wscript.arguments**** > > ** ** > > set oUsr = getobject(oVar(0))**** > > ** ** > > title = "EmployeeID Insertion"**** > > ** ** > > text1 = "Actual EmployeeID: " & oUsr.employeeID & vbcrlf & vbcrlf & "Insert or Update the EmployeeID:" & vbcrlf & vbcrlf & "(Ex: 75309889078)"**** > > ** ** > > tmp = inputbox(text1,title)**** > > ** ** > > if tmp <> "" then oUsr.put "employeeID",tmp**** > > ** ** > > oUsr.setinfo**** > > ** ** > > set oUsr = Nothing**** > > ** ** > > wscript.quit**** > > ** ** > > ** ** > > ** ** > > But now I have to tune the code with this condition, Can't exists two users accounts with the same employeeID, and this field have to be 11 numeric characters.**** > >
-- Thanks, Pradeep Rawat
| | | |
| gilvicente.araujo
Posts:8
 | | 02/02/2012 8:25 PM |
| Thanks All,
Finishing, The Final Vbscript Code.
dim oVar, oUsr, tmp, title, text1
set oVar = wscript.arguments
set oUsr = getobject(oVar(0))
title = "Cadastro do CPF"
text1 = "CPF Atual: " & oUsr.employeeID & vbcrlf & vbcrlf & "Informe o CPF:" & vbcrlf & vbcrlf & "(Ex: 75309889078)"
tmp = inputbox(text1,title)
if tmp <> "" then
on error resume next
If Len(tmp) <> 11 Then 'Validacao do tamanho do CPF
wscript.echo "O CPF deve conter obrigatoriamente 11 caracteres numéricos."
wscript.quit
End if
If Not IsNumeric(tmp) then
wscript.echo "Insira somente caracteres numéricos."
wscript.quit
End If
If FindDuplicates(tmp)=true Then 'Validacao de Duplicidade
'oUsr.put "employeeID",tmp
'wscript.echo "Ja existe CPF cadastrado"
Else
oUsr.put "employeeID",tmp
WScript.Echo "CPF cadastrado com sucesso"
oUsr.setinfo
set oUsr = Nothing
wscript.quit
'wscript.echo "Ja existe CPF cadastrado"
End if
End If
Function FindDuplicates (inbound)
FindDuplicates=false
Set CNUsers = GetObject ("LDAP://CN=Users,DC=dom,DC=ma,DC=in,DC=ad") 'Base de comparacao
For Each User in CNUsers
If Ucase(user.employeeID)=UCase(inbound) Then 'Checar se existe alguma duplicidade
WScript.Echo "Este CPF já está cadastrado para: " & user.cn
FindDuplicates=True 'Altera para True se encontrar
End If
Next
End Function
________________________________
Gil Vicente de Oliveira Araujo
Analista de Suporte MCP/CCNA
+55 (91) 8199 7269
________________________________
De: Pradeep Rawat <pradeeprawat85@gmail.com>
Para: activedir@mail.activedir.org
Enviadas: Quarta-feira, 1 de Fevereiro de 2012 10:54
Assunto: Re: [ActiveDir] Check Duplicate EmployeeID field
This piece of code can be added after $assigneid = Read-Host "ENTER A VALID USERNAME TO ASSIGN EMPLOYEE ID $employeeID"
So the output will be like this:
Enter the employeeID: 123456789010
CRITERIA MATCHED : VALID EMPLOYEE ID FORMAT
123456789010 NOT ASSIGNED TO ANY USER.
ENTER A VALID USERNAME TO ASSIGN EMPLOYEE ID 123456789010: _pradeep
_pradeep ALREADY HAVE AN EMPLOYEE ID ASSIGNED : 123456789011
UPDATE EMPLOYEE ID? (Y/N): Y
NEW EMPLOYEE ID 123456789010 ASSIGNED TO _pradeep
if($checkuser = Get-ADUser -Filter {(SamAccountName -eq $assigneid) -and (EmployeeID -notlike "*")} | Select-Object -ExpandProperty SamAccountName)
{
Set-ADUser -Identity $checkuser -EmployeeID $employeeID -Confirm:$false
Write-Host "$employeeID ASSIGNED TO $checkuser" -ForegroundColor Green
}
elseif($checkuser = Get-ADUser -Filter {(SamAccountName -eq $assigneid) -and (EmployeeID -like "*")} -Properties EmployeeID | `
Select-Object EmployeeID,SamAccountName)
{
Write-Host "$($checkuser.SamAccountName) ALREADY HAVE AN EMPLOYEE ID ASSIGNED : $($checkuser.EmployeeID)" -ForegroundColor Yellow
$response = Read-Host "`nUPDATE EMPLOYEE ID? (Y/N)"
if($response -eq "Y")
{
Set-ADUser -Identity $checkuser.SamAccountName -EmployeeID $employeeID -Confirm:$false
Write-Host "NEW EMPLOYEE ID $($employeeID) ASSIGNED TO $($checkuser.SamAccountName)" -ForegroundColor Green
}
else
{
Write-Host "NO MODIFICATIONS DONE" -ForegroundColor Green
}
On Wed, Feb 1, 2012 at 6:10 PM, Pradeep Rawat <pradeeprawat85@gmail.com> wrote:
Aah nice catch Roelf ;-) Missed that part.
>
>
>
>On Wed, Feb 1, 2012 at 6:01 PM, Roelf Zomerman <roelf.zomerman@avanade.com> wrote:
>
>Actually, you should also verify the object retrieved to see if it already has an ID assigned to it.. else you could be overwriting the actual employeeID..
>>
>>
>>Roelf
>>
>>
>>________________________________
>>
>>From: activedir-owner@mail.activedir.org [activedir-owner@mail.activedir.org] on behalf of Pradeep Rawat [pradeeprawat85@gmail.com]
>>Sent: Wednesday, February 01, 2012 12:55 PM
>>To: activedir@mail.activedir.org
>>Subject: Re: [ActiveDir] Check Duplicate EmployeeID field
>>
>>
>>If you have PowerShell with MS AD cmdlets you can try this code:
>>
>>$employeeID = Read-Host "Enter the employeeID"
>>if(($employeeID -as [Int64]) -and ($employeeID.Length -ge 11))
>>{
>>Write-Host "CRITERIA MATCHED : VALID EMPLOYEE ID FORMAT" -ForegroundColor Green
>>$checkeID = Get-ADUser -Filter {EmployeeID -eq $employeeID} | Select-Object -ExpandProperty SamAccountName
>>if($checkeID)
>>{
>>Write-Host "$employeeID ALREADY ASSIGNED TO: $checkeID" -ForegroundColor Yellow
>>}
>>else
>>{
>>Write-Host "$employeeID NOT ASSIGNED TO ANY USER."
>>$assigneid = Read-Host "ENTER A VALID USERNAME TO ASSIGN EMPLOYEE ID $employeeID"
>>$checkuser = Get-ADUser -Filter {SamAccountName -eq $assigneid} | Select-Object -ExpandProperty SamAccountName
>>if($checkuser)
>>{
>>Set-ADUser -Identity $checkuser -EmployeeID $employeeID -Confirm:$false
>>Write-Host "$employeeID ASSIGNED TO $checkuser" -ForegroundColor Green
>>}
>>else
>>{
>>Write-Host "$assigneid NOT FOUND OR INCORRECT NAME" -ForegroundColor Red
>>}
>>}
>>}
>>else
>>{
>>Write-Host "CRITERIA NOT MATCHED: employeeID must be an integer value or must contain 11 numeric characters" -ForegroundColor Red
>>}
>>
>>
>>
>>
>>On Wed, Feb 1, 2012 at 1:11 PM, Roelf Zomerman <roelf.zomerman@avanade.com> wrote:
>>
>>You probably could end up with something like this: (although not tested etc etc,.. and possibly could be optimized)
>>>
>>>but i would say.. you could also go for powershell..
>>>
>>>Roelf
>>>
>>>dim oVar, oUsr, tmp, title, text1
>>>
>>>set oVar = wscript.arguments
>>>
>>>set oUsr = getobject(oVar(0))
>>>
>>>title = "EmployeeID Insertion"
>>>
>>>text1 = "Actual EmployeeID: " & oUsr.employeeID & vbcrlf & vbcrlf & "Insert or Update the EmployeeID:" & vbcrlf & vbcrlf & "(Ex: 75309889078)"
>>>
>>>tmp = inputbox(text1,title)
>>>if tmp <> "" then
>>> on error resume next
>>> int=Cint(tmp) ‘See if we can convert the input to a number, if not it contains normal characters
>>> if error.numer >0 Then
>>> wscript.echo “NOT A NUMBER”
>>> wscript.quit
>>> end if
>>> If Len(tmp) <> 11 Then ‘check the lenght of the string entered to see if it is longer or shorter than 11 characters
>>> wscript.echo “NOT 11 Characters”
>>> wscript.quit
>>> End if
>>> If FindDuplicates(tmp)=true ‘calling the function
>>> oUsr.put "employeeID",tmp
>>> Else
>>> wscript.echo “Duplicate found”
>>>End if
>>>
>>>
>>>Function FindDuplicates(inbound)
>>> FindDuplicates=false
>>> Set CNUsers = GetObject ("LDAP://OU=YOUROU,DC=YOURDOMAIN,DC=org") ‘retrieve all objects from an OU
>>> For Each User in CNUsers
>>> If Ucase(user.employeeID)=UCase(inbound) Then ‘did we match one or more users to the input
>>> WScript.Echo "one"
>>> WScript.Echo " DisplayName: " & user.displayname & " - Legacy DN=: " & LegacDn
>>> FindDuplicates=True ‘if yes set to true
>>> End If
>>> Next
>>>End Function
>>>From:activedir-owner@mail.activedir.org [mailto:activedir-owner@mail.activedir.org] On Behalf Of Gil
>>>Sent: Tuesday, January 31, 2012 7:58 PM
>>>
>>>To: ActiveDir@mail.activedir.org
>>>Subject: [ActiveDir] Check Duplicate EmployeeID field
>>>
>>>
>>>I'm looking for a vbscript that checks if the value that will gonna be signed to an employeeID field already exists in the other users accounts.
>>>
>>>I starting using this generic code for employeeID insertion:
>>>
>>>dim oVar, oUsr, tmp, title, text1
>>>
>>>set oVar = wscript.arguments
>>>
>>>set oUsr = getobject(oVar(0))
>>>
>>>title = "EmployeeID Insertion"
>>>
>>>text1 = "Actual EmployeeID: " & oUsr.employeeID & vbcrlf & vbcrlf & "Insert or Update the EmployeeID:" & vbcrlf & vbcrlf & "(Ex: 75309889078)"
>>>
>>>tmp = inputbox(text1,title)
>>>
>>>if tmp <> "" then oUsr.put "employeeID",tmp
>>>
>>>oUsr.setinfo
>>>
>>>set oUsr = Nothing
>>>
>>>wscript.quit
>>>
>>>
>>>
>>>But now I have to tune the code with this condition, Can't exists two users accounts with the same employeeID, and this field have to be 11 numeric characters.
>>
>>
>>
| | | |
|
|