Categories
Sponsors
Archive
Blogroll
Badges
Community
|
Posted in Hosting & IIS7, Windows Powershell, Windows Server | No Comment | 3,121 views | 23/06/2009 10:45
You can join Windows user to Windows group from Powershell:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| # Add IIS User to IIS Group
function add_user_to_iis_group($username)
{
$computergroup = [ADSI]("WinNT://localhost,computer")
$admins = $computergroup.psbase.children.find("IIS_IUSRS")
foreach ($member in $admins.psbase.Invoke("Members"))
{
$member_name = $member.GetType().InvokeMember("Name", ‘GetProperty’, $null, $member, $null)
if ($member_name -eq $username)
{
Write-Host $username "already in this group."
return
}
}
$admins.Add("WinNT://$username")
Write-Host $username "added to group."
}
add_user_to_iis_group "$username" |
# Add IIS User to IIS Group
function add_user_to_iis_group($username)
{
$computergroup = [ADSI]("WinNT://localhost,computer")
$admins = $computergroup.psbase.children.find("IIS_IUSRS")
foreach ($member in $admins.psbase.Invoke("Members"))
{
$member_name = $member.GetType().InvokeMember("Name", ‘GetProperty’, $null, $member, $null)
if ($member_name -eq $username)
{
Write-Host $username "already in this group."
return
}
}
$admins.Add("WinNT://$username")
Write-Host $username "added to group."
}
add_user_to_iis_group "$username"
It checks user and if it is not exist in that group, add that username.
Posted in Windows Powershell, Windows Server | 4 Comments | 7,356 views | 23/06/2009 10:39
You can create Windows user from Powershell:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| function create_user($username, $password)
{
$computer = [ADSI]"WinNT://localhost"
foreach ($user in $computer.psbase.children)
{
if ($user.Name -eq $username)
{
Write-Host $user.Name "already exist."
Return
}
}
$user_obj = $computer.Create("user", "$username")
$user_obj.Put("description", "$username")
$user_obj.SetInfo()
$user_obj.SetPassword($password)
$user_obj.SetInfo()
$user_obj.psbase.invokeset("AccountDisabled", "False")
$user_obj.SetInfo()
Write-Host "$username created."
}
create_user "$username" "$password" |
function create_user($username, $password)
{
$computer = [ADSI]"WinNT://localhost"
foreach ($user in $computer.psbase.children)
{
if ($user.Name -eq $username)
{
Write-Host $user.Name "already exist."
Return
}
}
$user_obj = $computer.Create("user", "$username")
$user_obj.Put("description", "$username")
$user_obj.SetInfo()
$user_obj.SetPassword($password)
$user_obj.SetInfo()
$user_obj.psbase.invokeset("AccountDisabled", "False")
$user_obj.SetInfo()
Write-Host "$username created."
}
create_user "$username" "$password"
It checks user and if it is not exist, creates that username.
Posted in Hosting & IIS7, Windows Powershell, Windows Server | No Comment | 4,195 views | 23/06/2009 10:13
You can remove MySQL user from Powershell with MySQL connector:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| # Powershell Args
$dbusername = $args[0] # user01073
$dbpassword = $args[1] # RadoreTelekom
$dbname = $args[2] # db01073
# Add MySQL Data Connector
[void][system.reflection.Assembly]::LoadWithPartialName("MySql.Data")
# Open Connection to SQL Server
$connStr = "server=127.0.0.1;port=3306;uid=root;pwd=SQLPassword"
$conn = New-Object MySql.Data.MySqlClient.MySqlConnection($connStr)
$conn.Open()
# Drop MySQL User
$dropmysqluser = "DROP USER '" + $dbusername + "'@'localhost'"
$cmd = New-Object MySql.Data.MySqlClient.MySqlCommand($dropmysqluser, $conn)
$da = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($cmd)
$ds = New-Object System.Data.DataSet
$da.Fill($ds) |
# Powershell Args
$dbusername = $args[0] # user01073
$dbpassword = $args[1] # RadoreTelekom
$dbname = $args[2] # db01073
# Add MySQL Data Connector
[void][system.reflection.Assembly]::LoadWithPartialName("MySql.Data")
# Open Connection to SQL Server
$connStr = "server=127.0.0.1;port=3306;uid=root;pwd=SQLPassword"
$conn = New-Object MySql.Data.MySqlClient.MySqlConnection($connStr)
$conn.Open()
# Drop MySQL User
$dropmysqluser = "DROP USER '" + $dbusername + "'@'localhost'"
$cmd = New-Object MySql.Data.MySqlClient.MySqlCommand($dropmysqluser, $conn)
$da = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($cmd)
$ds = New-Object System.Data.DataSet
$da.Fill($ds)
Also I used arguments so you can call this powershell script from your panel.
Posted in Hosting & IIS7, Windows Powershell, Windows Server | 1 Comment | 5,648 views | 23/06/2009 10:07
You can remove MySQL database from Powershell with MySQL connector:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| # Powershell Args
$dbusername = $args[0] # user01073
$dbpassword = $args[1] # RadoreTelekom
$dbname = $args[2] # db01073
# Add MySQL Data Connector
[void][system.reflection.Assembly]::LoadWithPartialName("MySql.Data")
# Open Connection to SQL Server
$connStr = "server=127.0.0.1;port=3306;uid=root;pwd=SQLPassword"
$conn = New-Object MySql.Data.MySqlClient.MySqlConnection($connStr)
$conn.Open()
# Drop MySQL Database
$dropmysqldatabase = 'DROP DATABASE `' + $dbname + '`'
$cmd = New-Object MySql.Data.MySqlClient.MySqlCommand($dropmysqldatabase, $conn)
$da = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($cmd)
$ds = New-Object System.Data.DataSet
$da.Fill($ds) |
# Powershell Args
$dbusername = $args[0] # user01073
$dbpassword = $args[1] # RadoreTelekom
$dbname = $args[2] # db01073
# Add MySQL Data Connector
[void][system.reflection.Assembly]::LoadWithPartialName("MySql.Data")
# Open Connection to SQL Server
$connStr = "server=127.0.0.1;port=3306;uid=root;pwd=SQLPassword"
$conn = New-Object MySql.Data.MySqlClient.MySqlConnection($connStr)
$conn.Open()
# Drop MySQL Database
$dropmysqldatabase = 'DROP DATABASE `' + $dbname + '`'
$cmd = New-Object MySql.Data.MySqlClient.MySqlCommand($dropmysqldatabase, $conn)
$da = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($cmd)
$ds = New-Object System.Data.DataSet
$da.Fill($ds)
Also I used arguments so you can call this powershell script from your panel.
Posted in Hosting & IIS7, Windows Powershell, Windows Server | No Comment | 2,816 views | 23/06/2009 10:01
You can flush MySQL privileges from Powershell with MySQL connector:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| # Powershell Args
$dbusername = $args[0] # user01073
$dbpassword = $args[1] # RadoreTelekom
$dbname = $args[2] # db01073
# Add MySQL Data Connector
[void][system.reflection.Assembly]::LoadWithPartialName("MySql.Data")
# Open Connection to SQL Server
$connStr = "server=127.0.0.1;port=3306;uid=root;pwd=SQLPassword"
$conn = New-Object MySql.Data.MySqlClient.MySqlConnection($connStr)
$conn.Open()
# Flush Privileges
$flushprivileges = 'FLUSH PRIVILEGES'
$cmd = New-Object MySql.Data.MySqlClient.MySqlCommand($flushprivileges, $conn)
$da = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($cmd)
$ds = New-Object System.Data.DataSet
$da.Fill($ds) |
# Powershell Args
$dbusername = $args[0] # user01073
$dbpassword = $args[1] # RadoreTelekom
$dbname = $args[2] # db01073
# Add MySQL Data Connector
[void][system.reflection.Assembly]::LoadWithPartialName("MySql.Data")
# Open Connection to SQL Server
$connStr = "server=127.0.0.1;port=3306;uid=root;pwd=SQLPassword"
$conn = New-Object MySql.Data.MySqlClient.MySqlConnection($connStr)
$conn.Open()
# Flush Privileges
$flushprivileges = 'FLUSH PRIVILEGES'
$cmd = New-Object MySql.Data.MySqlClient.MySqlCommand($flushprivileges, $conn)
$da = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($cmd)
$ds = New-Object System.Data.DataSet
$da.Fill($ds)
Also I used arguments so you can call this powershell script from your panel.
Posted in Hosting & IIS7, Windows Powershell, Windows Server | No Comment | 2,351 views | 23/06/2009 02:55
You can grant MySQL User on database from Powershell with MySQL connector:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| # Powershell Args
$dbusername = $args[0] # user01073
$dbpassword = $args[1] # RadoreTelekom
$dbname = $args[2] # db01073
# Add MySQL Data Connector
[void][system.reflection.Assembly]::LoadWithPartialName("MySql.Data")
# Open Connection to SQL Server
$connStr = "server=127.0.0.1;port=3306;uid=root;pwd=SQLPassword"
$conn = New-Object MySql.Data.MySqlClient.MySqlConnection($connStr)
$conn.Open()
# Grant MySQL User on DB
$grantmysqluser = 'GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,ALTER,CREATE TEMPORARY TABLES,LOCK TABLES,REFERENCES ON ' + $dbname + '.* TO `' + $dbusername + '`@`localhost` WITH GRANT OPTION'
$cmd = New-Object MySql.Data.MySqlClient.MySqlCommand($grantmysqluser, $conn)
$da = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($cmd)
$ds = New-Object System.Data.DataSet
$da.Fill($ds) |
# Powershell Args
$dbusername = $args[0] # user01073
$dbpassword = $args[1] # RadoreTelekom
$dbname = $args[2] # db01073
# Add MySQL Data Connector
[void][system.reflection.Assembly]::LoadWithPartialName("MySql.Data")
# Open Connection to SQL Server
$connStr = "server=127.0.0.1;port=3306;uid=root;pwd=SQLPassword"
$conn = New-Object MySql.Data.MySqlClient.MySqlConnection($connStr)
$conn.Open()
# Grant MySQL User on DB
$grantmysqluser = 'GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,ALTER,CREATE TEMPORARY TABLES,LOCK TABLES,REFERENCES ON ' + $dbname + '.* TO `' + $dbusername + '`@`localhost` WITH GRANT OPTION'
$cmd = New-Object MySql.Data.MySqlClient.MySqlCommand($grantmysqluser, $conn)
$da = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($cmd)
$ds = New-Object System.Data.DataSet
$da.Fill($ds)
Also I used arguments so you can call this powershell script from your panel.
Posted in Hosting & IIS7, Windows Powershell, Windows Server | No Comment | 4,024 views | 23/06/2009 02:50
You can change or set MySQL user password from Powershell with MySQL connector:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| # Powershell Args
$dbusername = $args[0] # user01073
$dbpassword = $args[1] # RadoreTelekom
$dbname = $args[2] # db01073
# Add MySQL Data Connector
[void][system.reflection.Assembly]::LoadWithPartialName("MySql.Data")
# Open Connection to SQL Server
$connStr = "server=127.0.0.1;port=3306;uid=root;pwd=SQLPassword"
$conn = New-Object MySql.Data.MySqlClient.MySqlConnection($connStr)
$conn.Open()
# Set MySQL User Password
$setmysqlpassword = "SET PASSWORD FOR '" + $dbusername + "'@'localhost' = PASSWORD('" + $dbpassword + "')"
$cmd = New-Object MySql.Data.MySqlClient.MySqlCommand($setmysqlpassword, $conn)
$da = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($cmd)
$ds = New-Object System.Data.DataSet
$da.Fill($ds) |
# Powershell Args
$dbusername = $args[0] # user01073
$dbpassword = $args[1] # RadoreTelekom
$dbname = $args[2] # db01073
# Add MySQL Data Connector
[void][system.reflection.Assembly]::LoadWithPartialName("MySql.Data")
# Open Connection to SQL Server
$connStr = "server=127.0.0.1;port=3306;uid=root;pwd=SQLPassword"
$conn = New-Object MySql.Data.MySqlClient.MySqlConnection($connStr)
$conn.Open()
# Set MySQL User Password
$setmysqlpassword = "SET PASSWORD FOR '" + $dbusername + "'@'localhost' = PASSWORD('" + $dbpassword + "')"
$cmd = New-Object MySql.Data.MySqlClient.MySqlCommand($setmysqlpassword, $conn)
$da = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($cmd)
$ds = New-Object System.Data.DataSet
$da.Fill($ds)
Also I used arguments so you can call this powershell script from your panel.
|