Add scripts
This commit is contained in:
parent
422934aef7
commit
350807c951
30 changed files with 574 additions and 0 deletions
19
Scripts/Add-ADUserToMySQL.ps1
Normal file
19
Scripts/Add-ADUserToMySQL.ps1
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
$ip = "192.168.1.253"
|
||||
$user = "posh"
|
||||
$pass = "1qaz!QAZ"
|
||||
$db = "db_aduser"
|
||||
Add-Type –Path "$home\Documents\MySQL-Connector-NET\8.0.31-4.8\MySql.Data.dll"
|
||||
$Connection = [MySql.Data.MySqlClient.MySqlConnection]@{
|
||||
ConnectionString="server=$ip;uid=$user;pwd=$pass;database=$db"
|
||||
}
|
||||
$Connection.Open()
|
||||
$Command = New-Object MySql.Data.MySqlClient.MySqlCommand
|
||||
$Command.Connection = $Connection
|
||||
$UserList = Get-ADUser -filter * -properties name,EmailAddress
|
||||
foreach ($user in $UserList) {
|
||||
$uname=$user.Name
|
||||
$uemail=$user.EmailAddress
|
||||
$Command.CommandText = "INSERT INTO table_aduser (Name,Email) VALUES ('$uname','$uemail')"
|
||||
$Command.ExecuteNonQuery()
|
||||
}
|
||||
$Connection.Close()
|
||||
Loading…
Add table
Add a link
Reference in a new issue