19 lines
684 B
PowerShell
19 lines
684 B
PowerShell
|
|
$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()
|