Archive

Posts Tagged ‘scripting’

Powershell : Generate passwords into an excel file

February 18, 2011 1 comment

Some months ago a posted a VBS script that generated passwords into an excel file (found here). This time I wrote one that can do this by using powershell. This scipt can be used with other powershell scripts I wrote in combination with excel. Very handy if you need to create passwords for hunderds of new student accounts.

####################################################################
#
PowerShell Script to generate a password into an excel file #
#
#
#
Version: 0.1 #
#
#
#
Requirements: #
#
1. Powershell #
#
3. Excel 2007 Installed #
#
4. Excel file with the following Columns and data: #
#
Column 1 (A) : Last Name #
#
Column 2 (B) : Middle Name (like van, de, or blank) #
#
Column 3 (C) : First Name #
#
Column 4 (D) : Login Name (like 22222) #
#
Column 5 (E) : Class (like 4K1) #
#
Column 6 (F) : Sector (VMBO, HVWO, PRO) #
#
Column 7 (G) : Password #
#
#
#
Changelog: #
#
0.1 First version Richard #
#
#
#
###################################################################

$strExcelFile = "C:\Scripts\students.xlsx"

####################################################################
#
FUNCTIONS #
#
###################################################################
function Release-Ref ($ref) {
([
System.Runtime.InteropServices.Marshal]::ReleaseComObject([System.__ComObject]$ref) -gt 0)
[
System.GC]::Collect()
[
System.GC]::WaitForPendingFinalizers()
}
function CreatePassword([int]$length){
$specialCharacters = "_!+"
$lowerCase = "abcdefghijklmnopqrstuvwxyz"
$upperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
$numbers = "1234567890"
$res = ""
$rnd = New-Object System.Random

do
{
$flag = $rnd.Next(4);
if ($flag -eq 0)
{
$res += $specialCharacters[$rnd.Next($specialCharacters.Length)];}
elseif ($flag -eq 1)
{
$res += $lowerCase[$rnd.Next($lowerCase.Length)];}
elseif ($flag -eq 2)
{
$res += $upperCase[$rnd.Next($upperCase.Length)];}
else
{
$res += $numbers[$rnd.Next($numbers.Length)];}
}
while (0 -lt $length--)
return $res
}
####################################################################
#
MAIN SCRIPT #
#
###################################################################
#
Get First Cell and last Cell value (using VBS for this)
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$strFirstCell = [Microsoft.VisualBasic.Interaction]::InputBox("First Cell value (like G2)", "Password Generator for Excel")
$strLastCell = [Microsoft.VisualBasic.Interaction]::InputBox("Last Cell value (Like G100)", "Password Generator for Excel")
$objCellRange = $strFirstCell + ":" + $strLastCell

#Open COM object, start Excel, open Excel File with workbook
$objExcel = New-Object -Comobject Excel.Application
$objExcel.Visible = $True
$objExcel.DisplayAlerts = $False
$objExcelWorkbook = $objExcel.Workbooks.Open($strExcelFile)

#loop through CellRange and create password with 6 chars (change 5 to something else if more required)
ForEach ($objExcelCell In $objExcel.Range($objCellRange)) {$objExcelCell.Value() = createpassword 5}

#Save and close Excel Workbook, close Excel, cleanup and kill EXCEL32 process
$objExcelWorkbook.SaveAs($strExcelFile)
$objExcel.DisplayAlerts = $True
$objExcelWorkbook.Close()
$objExcel.Quit()
Start-Sleep -Seconds 2
Release-Ref $objExcelWorkbook
Release-Ref $objExcel
spps -n excel
####################################################################
#
END MAIN SCRIPT #
#
###################################################################

Feel free to comment.

Powershell : create homedrive folder with correct permissions (Icacls) by using excel

February 16, 2011 Leave a comment

In my last article I spoke of adding student users to AD with an excel file by using Powershell. This script is a little addon to create the corresponding Homedrive folder with correct permissions. In the past I was using a VBS script that used xcacls to create the folder with permissions. In the Windows 2008 R2 with powershell era it would be cool to use icacls. Feel free to combine the two scripts into one script.

####################################################################
#
PowerShell Script add STUDENT homedrive Folder with permissions #
#
#
#
Version: 0.2 #
#
#
#
Requirements: #
#
1. Powershell Installed #
#
2. Permissions on the fileserver #
#
3. Excel 2007 Installed #
#
4. Excel file with the following Columns and data: #
#
Column 1 (A) : Last Name #
#
Column 2 (B) : Middle Name (like van, de, or blank) #
#
Column 3 (C) : First Name #
#
Column 4 (D) : Login Name/Student number (like 11122)#
#
Column 5 (E) : Expertise (Like Network Admin) #
#
Column 6 (F) : Sector (VMBO, HVWO, PRO) #
#
Column 7 (G) : Password #
#
#
#
Changelog: #
#
0.1 First version Richard #
#
0.2 Add dir existance check Richard #
#
#
#
###################################################################

$strExcelFile = "C:\Scripts\leerlingen.xlsx"
$strADUserHomeDrivePath = "\\servername\servershare\studentshomedrive\"
$strIcaclsPrms1 = "/inheritance:r"
$strIcaclsPrms2 = "<netbios domainname>\"
$strIcaclsPrms3 = ":(OI)(CI)F"
$strIcaclsPrms9 = ":(OI)(CI)M"
$strIcaclsPrms4 = "/grant:r"
$strIcaclsPrms5 = "SYSTEM:(OI)(CI)F"
$strIcaclsPrms6 = "<netbios domainname>\domain admins"
$strIcaclsPrms7 = "/T"
$strIcaclsPrms8 = "SYSTEM:F"

####################################################################
#
FUNCTIONS #
#
###################################################################
function addHomeDriveFolder {
#check if dir exists. If not then create dir and set permissions
if (!(Test-Path -path ($strADUserHomeDrivePath + $strADUserAlias)))
{
New-Item ($strADUserHomeDrivePath + $strADUserAlias) -type directory
Start-Sleep -Seconds 1
Icacls
"${strADUserHomeDrivePath}${strADUserAlias}" $strIcaclsPrms1 $strIcaclsPrms4 "${strIcaclsPrms2}${strADUserAlias}${strIcaclsPrms9}" $strIcaclsPrms4 "${strIcaclsPrms6}${strIcaclsPrms3}" $strIcaclsPrms4 $strIcaclsPrms5 $strIcaclsPrms7
}
}
####################################################################
#
MAIN SCRIPT #
#
###################################################################
#
Open COM object, start Excel, open Excel File with workbook
$objExcel = New-Object -Comobject Excel.Application
$objExcel.Visible = $True
$objExcelWorkbook = $objExcel.Workbooks.Open($strExcelFile)

#First Row contains header, so start with row 2
$objExcelCurrentRow = 2

#Loop through excel file and add folder with specific permissions
do
{
$strADUserSector = $objExcel.Cells.Item($objExcelCurrentRow,6).Value()
$strADUserAlias = $objExcel.Cells.Item($objExcelCurrentRow,4).Value()
if ($strADUserSector -ne $Null) {addHomeDriveFolder}
else {}
$objExcelCurrentRow++
}
until ($strADUserSector -eq $Null)

#Close Excel Workbook and Excel and cleanup with .Net Framework
$objExcelWorkbook.Close()
$objExcel.Quit()
$Null = & {
[
Runtime.Interopservices.Marshal]::ReleaseComObject($objExcel)
[
Runtime.Interopservices.Marshal]::ReleaseComObject($objExcelWorkbook)
}
GC]::Collect()
####################################################################
#
END MAIN SCRIPT #
#
###################################################################

Hope you found this script usefull somehow and feel free to comment.

Categories: Scripting Tags: , , ,

Powershell : Add student users to AD with an excel file

February 14, 2011 8 comments

Powershell. or powerHell…well sometimes. I think it has got to do with lack of knowledge about this scripting technique. The more I am working with it the more i am starting to love it. Very powerfull commands to do more with less. Since the migration to exchange 2010 and windows 2008 R2 we are discovering the power of powershell. Now I’ve converted some of my scripts from VBS to powershell. In this article I have created a script to add student users to Active Directory while using a Excel xlsx file and NOT using Quest AD commandlets.

####################################################################
#
PowerShell Script for to add STUDENTS users to Active Directory #
#
#
#
Version: 0.2 #
#
#
#
Requirements: #
#
1. Powershell with Exchange 2010 CMDlets #
#
2. Permissions on Exchange 2010 and Active Directory #
#
3. Excel 2007 Installed #
#
4. Excel file with the following Columns and data: #
#
#
#
Column 1 (A) : Last Name #
#
Column 2 (B) : Middle Name (like van, de, or blank) #
#
Column 3 (C) : First Name #
#
Column 4 (D) : Login Name (like 22222) #
#
Column 5 (E) : Class (like 4K1) #
#
Column 6 (F) : Sector (VMBO, HVWO, PRO) #
#
Column 7 (G) : Password #
#
#
#
Changelog: #
#
0.1 First version Richard #
#
0.2 Add user check Richard #
#
#
#
###################################################################

$strExcelFile = "C:\Scripts\students.xlsx"
$strADDomainName = "domainname.local"
$strDC = "servername"
$strExchangeDB = "EX-DB"
$strExchangeSMTP = "@companyname.nl"

$strADUserLogonScriptHVWO = "Hvwo-student.vbs"
$strADUserProfPathHVWO = "\\servername\Profiles$\studentprofileHvwo"
$strADUserOUHVWO = [ADSI] "LDAP://servername.domainname.local:389/OU=Students,OU=Users,OU=HavoVwo,DC=domainname,DC=local"
$strADUserOUHVWOShort = ",OU=Students,OU=Users,OU=HavoVwo,DC=domainname,DC=local"
$strADUserGroupHVWO = [ADSI] "LDAP://servername.domainname.local:389/CN=Students HavoVwo,OU=Students,OU=groups,OU=HavoVwo,DC=domainname,DC=local"

$strADUserLogonScriptPRO = "Pro-student.vbs"
$strADUserProfPathPRO = "\\servername\Profiles$\studentprofilePro"
$strADUserOUPRO = [ADSI] "LDAP://servername.domainname.local:389/OU=Students,OU=Users,OU=Pro,DC=domainname,DC=local"
$strADUserOUPROShort = ",OU=Students,OU=Users,OU=Pro,DC=domainname,DC=local"
$strADUserGroupPRO = [ADSI] "LDAP://servername.domainname.local:389/CN=Students PRO,OU=Students,OU=groups,OU=Pro,DC=domainname,DC=local"

$strADUserLogonScriptVMBO = "Vmbo-student.vbs"
$strADUserProfPathVMBO = "\\servername\Profiles$\studentprofileVmbo"
$strADUserOUVMBO = [ADSI] "LDAP://servername.domainname.local:389/OU=Students,OU=Users,OU=Vmbo,DC=domainname,DC=local"
$strADUserOUVMBOShort = ",OU=Students,OU=Users,OU=Vmbo,DC=domainname,DC=local"
$strADUserGroupVMBO = [ADSI] "LDAP://servername.domainname.local:389/CN=Students VMBO,OU=Students,OU=groups,OU=Vmbo,DC=domainname,DC=local"

####################################################################
#
FUNCTIONS #
#
###################################################################
function addHVWOuser {
#check if user exists
$Status = (Check-ADUser -username $strADUserAlias).Status
If ($Status -eq 1) {Write-Host "User:" $strADUserAlias "allready exists!"}
Else {
#create user with settings
$newUser = $strADUserOUHVWO.Create("user",$CN)
$newUser.put("sAMAccountName", $strADUserAlias)
$newUser.put("GivenName", $strADUserFirstName)
$newUser.put("SN", $strADUserLastName)
$newUser.put("displayName", $strADUserFullName)
$newUser.put("initials", $strADUserInitials)
$newUser.put("description", $strADUserDiscription)
$newUser.put("profilePath", $strADUserProfPathHVWO)
$newUser.put("scriptPath", $strADUserLogonScriptHVWO)
$newUser.put("userPrincipalName", $strADUserPrincipalName)
$newUser.SetInfo()
$newUser.PsBase.Invoke("SetPassword", $strADUserPassword)
$newUser.PsBase.InvokeSet("AccountDisabled", $false)
$newUser.SetInfo()
#Set password never expires
New-Variable ADS_UF_DONT_EXPIRE_PASSWD 0x10000 -Option Constant
[
int]$flag=$newUser.useraccountcontrol[0]
$newUser.useraccountcontrol=$flag -bor $ADS_UF_DONT_EXPIRE_PASSWD
$newUser.SetInfo()
#Set password cannot be changed
set-passwordchange $newUser.distinguishedname -deny
#wait for user to be created
Start-Sleep -Seconds 10
#Add user to AD Group
$strADUserGroupHVWO.add("LDAP://" + $strDC + "." + $strADDomainName + ":389/" + $CN + $strADUserOUHVWOShort)
#create mailbox and configure mailbox settings
Enable-Mailbox -Identity $strADUserFullName -Alias $strADUserAlias -Database $strExchangeDB -PrimarySmtpAddress $strADUserEmailAddress -ActiveSyncMailboxPolicy 'Default' -DomainController $strDC
Set-CASMailbox -Identity
$strADUserFullName -MAPIEnabled $false -POPEnabled $false -ImapEnabled $false –ActiveSyncEnabled $false -DomainController $strDC
Set-Mailbox -Identity
$strADUserFullName -HiddenFromAddressListsEnabled $true -DomainController $strDC
}
}
function addPROuser {
#check if user exists
$Status = (Check-ADUser -username $strADUserAlias).Status
If ($Status -eq 1) {Write-Host "User:" $strADUserAlias "allready exists!"}
Else {
#create user with settings
$newUser = $strADUserOUPRO.Create("user",$CN)
$newUser.put("sAMAccountName", $strADUserAlias)
$newUser.put("GivenName", $strADUserFirstName)
$newUser.put("SN", $strADUserLastName)
$newUser.put("displayName", $strADUserFullName)
$newUser.put("initials", $strADUserInitials)
$newUser.put("description", $strADUserDiscription)
$newUser.put("profilePath", $strADUserProfPathPRO)
$newUser.put("scriptPath", $strADUserLogonScriptPRO)
$newUser.put("userPrincipalName", $strADUserPrincipalName)
$newUser.SetInfo()
$newUser.PsBase.Invoke("SetPassword", $strADUserPassword)
$newUser.PsBase.InvokeSet("AccountDisabled", $false)
$newUser.SetInfo()
#Set password never expires
New-Variable ADS_UF_DONT_EXPIRE_PASSWD 0x10000 -Option Constant
[
int]$flag=$newUser.useraccountcontrol[0]
$newUser.useraccountcontrol=$flag -bor $ADS_UF_DONT_EXPIRE_PASSWD
$newUser.SetInfo()
#Set password cannot be changed
set-passwordchange $newUser.distinguishedname -deny
#wait for user to be created
Start-Sleep -Seconds 10
#Add user to AD Groups
$strADUserGroupPRO.add("LDAP://" + $strDC + "." + $strADDomainName + ":389/" + $CN + $strADUserOUPROShort)
$strADUserGroupVMBO.add("LDAP://" + $strDC + "." + $strADDomainName + ":389/" + $CN + $strADUserOUPROShort)
#create mailbox and configure mailbox settings
Enable-Mailbox -Identity $strADUserFullName -Alias $strADUserAlias -Database $strExchangeDB -PrimarySmtpAddress $strADUserEmailAddress -ActiveSyncMailboxPolicy 'Default' -DomainController $strDC
Set-CASMailbox -Identity
$strADUserFullName -MAPIEnabled $false -POPEnabled $false -ImapEnabled $false –ActiveSyncEnabled $false -DomainController $strDC
Set-Mailbox -Identity
$strADUserFullName -HiddenFromAddressListsEnabled $true -DomainController $strDC
}
}
function addVMBOuser {
#check if user exists
$Status = (Check-ADUser -username $strADUserAlias).Status
If ($Status -eq 1) {Write-Host "User:" $strADUserAlias "allready exists!"}
Else {
#create user with settings
$newUser = $strADUserOUVMBO.Create("user",$CN)
$newUser.put("sAMAccountName", $strADUserAlias)
$newUser.put("GivenName", $strADUserFirstName)
$newUser.put("SN", $strADUserLastName)
$newUser.put("displayName", $strADUserFullName)
$newUser.put("initials", $strADUserAlias)
$newUser.put("description", $strADUserDiscription)
$newUser.put("profilePath", $strADUserProfPathVMBO)
$newUser.put("scriptPath", $strADUserLogonScriptVMBO)
$newUser.put("userPrincipalName", $strADUserPrincipalName)
$newUser.SetInfo()
$newUser.PsBase.Invoke("SetPassword", $strADUserPassword)
$newUser.PsBase.InvokeSet("AccountDisabled", $false)
$newUser.Put("pwdLastSet", 0)
$newUser.SetInfo()
#Set password never expires
New-Variable ADS_UF_DONT_EXPIRE_PASSWD 0x10000 -Option Constant
[
int]$flag=$newUser.useraccountcontrol[0]
$newUser.useraccountcontrol=$flag -bor $ADS_UF_DONT_EXPIRE_PASSWD
$newUser.SetInfo()
#Set password cannot be changed
set-passwordchange $newUser.distinguishedname -deny
#wait for user to be created
Start-Sleep -Seconds 10
#Add user to AD Group
$strADUserGroupVMBO.add("LDAP://" + $strDC + "." + $strADDomainName + ":389/" + $CN + $strADUserOUVMBOShort)
#create mailbox and configure mailbox settings
Enable-Mailbox -Identity $strADUserFullName -Alias $strADUserAlias -Database $strExchangeDB -PrimarySmtpAddress $strADUserEmailAddress -ActiveSyncMailboxPolicy 'Default' -DomainController $strDC
Set-CASMailbox -Identity
$strADUserFullName -MAPIEnabled $false -POPEnabled $false -ImapEnabled $false –ActiveSyncEnabled $false -DomainController $strDC
Set-Mailbox -Identity
$strADUserFullName -HiddenFromAddressListsEnabled $true -DomainController $strDC
}
}
Function Set-PasswordChange {
Param([string]$dn=$(Throw "You must specify a user's DN"),
[
switch]$Deny)
#only run if user distinguishedname was found
[ADSI]$user="LDAP://" + $strDC + "." + $strADDomainName + ":389/" + $dn
[
Guid]$guid="ab721a53-1e2f-11d0-9819-00aa0040529b"
$everyone = [System.Security.Principal.SecurityIdentifier]"S-1-1-0"
$self = [System.Security.Principal.SecurityIdentifier]"S-1-5-10"
$EveryoneDeny = New-Object System.DirectoryServices.ActiveDirectoryAccessRule ($Everyone,"ExtendedRight","Deny",$guid)
$EveryoneAllow = New-Object System.DirectoryServices.ActiveDirectoryAccessRule ($Everyone,"ExtendedRight","Allow",$guid)
$SelfDeny = New-Object System.DirectoryServices.ActiveDirectoryAccessRule ($self,'ExtendedRight','Deny',$guid)
$SelfAllow = New-Object System.DirectoryServices.ActiveDirectoryAccessRule ($self,'ExtendedRight','Allow',$guid)#Pick the right rules depending on whether $perm is set to Allow or Deny
if ($Deny) {
$SelfRule = $SelfDeny
$EveryoneRule = $EveryoneDeny
}
else
{
$SelfRule = $SelfAllow
$EveryoneRule = $EveryoneAllow
}
#The ModifyAccessRuleMethod requires an object to use for its output
New-Variable r
if (!($User.psbase.ObjectSecurity.ModifyAccessRule('Reset',$SelfRule,[ref]$r))) {
Write-Host "Failed to modify access rule for SELF"
Return
}
If (!($User.psbase.ObjectSecurity.ModifyAccessRule('Reset',$EveryoneRule,[ref]$r))) {
Write-Host "Failed to modify access rule for EVERYONE"
Return
}
# changes were made so commit them
$user.psbase.commitchanges()
}
Function Check-ADUser {
#search for user in AD
Param ($Username)
$ADRoot = [ADSI]''
$ADSearch = New-Object System.DirectoryServices.DirectorySearcher($ADRoot)
$SAMAccountName = "$Username"
$ADSearch.Filter = "(&(objectClass=user)(sAMAccountName=$SAMAccountName))"
$Result = $ADSearch.FindAll()
If($Result.Count -eq 0)
{
#Write-Host "No such user on the Server" | Out-Null
$Status = "0"
}
Else
{
#Write-Host "User exist on the Server" | Out-Null
$Status = "1"
}
$Results = New-Object Psobject
$Results | Add-Member Noteproperty Status $Status
Write-Output $Results
}
####################################################################
#
MAIN SCRIPT #
#
###################################################################
#
Open COM object, start Excel, open Excel File with workbook
$objExcel = New-Object -Comobject Excel.Application
$objExcel.Visible = $True
$objExcelWorkbook = $objExcel.Workbooks.Open($strExcelFile)#First Row contains header, so start with row 2
$objExcelCurrentRow = 2#Loop through excel file and add users with specific settings
do
{
$strADUserLastName = $objExcel.Cells.Item($objExcelCurrentRow,1).Value()
$strADUserMiddleName = $objExcel.Cells.Item($objExcelCurrentRow,2).Value()
$strADUserFirstName = $objExcel.Cells.Item($objExcelCurrentRow,3).Value()
#convert System.double to string value (needed because studentname ia a number)
[string] $strADUserAlias = $objExcel.Cells.Item($objExcelCurrentRow,4).Value()
$strADUserClass = $objExcel.Cells.Item($objExcelCurrentRow,5).Value()
$strADUserSector = $objExcel.Cells.Item($objExcelCurrentRow,6).Value()
$strADUserPassword = $objExcel.Cells.Item($objExcelCurrentRow,7).Value()
If ($strADUserMiddleName -eq $Null) {$strADUserFullName = $strADUserLastName + ", " + $strADUserFirstName} Else {$strADUserFullName = $strADUserLastName + ", " + $strADUserMiddleName + ", " + $strADUserFirstName}
$strADUserDiscription = $strADUserSector + " Class " + $strADUserClass + " (" + $strADUserFullName + ")"
$strADUserPrincipalName = $strADUserAlias + "@" + $strADDomainName
$strADUserEmailAddress = $strADUserAlias + $strExchangeSMTP
$strADUserInitials = $strADUserAlias
$CN = "CN=" + $strADUserAlias
If ($strADUserSector -eq "HVWO") {addHVWOuser}
If ($strADUserSector -eq "PRO") {addPROuser}
If ($strADUserSector -eq "VMBO") {addVMBOuser}
$objExcelCurrentRow++
}
until ($strADUserLastName -eq $Null)#Close Excel Workbook and Excel and cleanup with .Net Framework
$objExcelWorkbook.Close()
$objExcel.Quit()
$Null = & {
[
Runtime.Interopservices.Marshal]::ReleaseComObject($objExcel)
[
Runtime.Interopservices.Marshal]::ReleaseComObject($objExcelWorkbook)
}
GC]::Collect()
####################################################################
#
END MAIN SCRIPT #
#
###################################################################

[

I think this code can easily be followed. If any questions arise or if you have usefull additions or comments don’t hesitate to comment.

Generate passwords into an Excel file

October 18, 2010 Leave a comment

There are alot of user accounts mutations when a new school year starts. Creating hunderds of new user accounts can be a hassle and all those new accounts also need an password. This little script will generate passwords and place them into an excel file. This excel file can be used to create all those accounts with the generated password.

‘enable debugging
Option Explicit

‘create memory for objects
Dim objExcelRange, objExcelRange1, objExcelRange2, objExcel, objExcelWorkbook, objExcelCell
Dim objPasswordLoops, objRandomCharacter, objPasswordMFactor, objPasswordNumber, objPasswordChar, objPasswordNext

‘define globale constants
Const strExcelFileName = “D:\student.xls”
Const strExcelBoxTitle = “Password Generator for an Excelfile”
Const strPasswordLength = 6
Const  strPasswordCharacters = “abc1de2fg3hi4jk5lm6no7pqrs9tuvw0xyz”

‘asking for values
objExcelRange1=InputBox(“Enter value for the first cell” & VBCRLF & “(Example: G2) :”,strExcelBoxTitle,”G2″)
objExcelRange2=InputBox(“Enter value for the last cell” & VBCRLF & “(Example: G100) :”,strExcelBoxTitle,”G100″)
objExcelRange = objExcelRange1 & “:” & objExcelRange2

‘create an excel instance and open workbook
Set objExcel = CreateObject(“Excel.Application”)
Set objExcelWorkbook = objExcel.Workbooks.Open(strExcelFileName)

‘generate password for every cell entered into inputbox
For Each objExcelCell In objExcel.Range(objExcelRange)
 objExcelCell.Value = StrPassword(strPasswordLength,strPasswordCharacters)
Next

‘close and save excelfile
objExcelWorkbook.SaveAs strExcelFileName
objExcel.Quit

‘*************************************************************************
‘***********************      Functions       ****************************
‘*************************************************************************
Function GenIt(objPasswordMFactor)
 Randomize
 GenIt=INT(RND()*objPasswordMFactor)+1
end Function
‘*************************************************************************
Function StrPassword(strPasswordLength,strPasswordCharacters)

StrPassword = “”

objPasswordMFactor = Len(strPasswordCharacters)

For objPasswordNumber=1 to strPasswordLength
 objPasswordChar = GenIt(objPasswordMFactor)
 objPasswordNext = Mid(strPasswordCharacters,objPasswordChar,1)
 StrPassword = StrPassword & objPasswordNext
Next
End Function
‘*************************************************************************
‘*************************************************************************
‘*************************************************************************

%d bloggers like this: