New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contribution: PowerShell script for WebSite creation #243

Open
PHuhn opened this Issue Sep 11, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@PHuhn

PHuhn commented Sep 11, 2017

Hi Patrick:

I have been working working on a WordPress talk. I didn't what to install Apache and MySQL, so I have been using Project Nami. I have created a Powershell script to create my IIS demonstration website. I would like to share this with the community. This is the read-me file:

Project Nami WebSite Create

Version: 2.0.0

NAME
WebSite.ps1

SYNOPSIS
This is a simple Powershell script to generate a generic website. This intended to be used
in a development environment on a developer's workstation.

SYNTAX
C:\Dat\nsg\Talks\Web\WordPress\AddOns\scripts\WebSite.ps1 [[-baseDir] ] [[-siteName] ]
[[-siteUser] ] [[-portNum] ] [[-owner] ] [[-wordPress] ]
[]

DESCRIPTION
Create a website and set permissions. This is a simple PowerShell script that creates
a generic website, as follows:
* create a website folder,
* creates an IIS Website (and app-pool with same name),
* grants the website user read/execute permissions to the website folder,
* if WordPress site then creates wp-content and wp-includes folders
and grants the website user modify permissions to the these folders,
* optionally grants owner permissions to the website folder to a developer.

PARAMETERS
-baseDir
root folder (should already exist)

    Required?                    false
    Position?                    1
    Default value                C:\inetpub\
    Accept pipeline input?       false
    Accept wildcard characters?  false
    
-siteName <String>
    name of the website in IIS manager
    
    Required?                    false
    Position?                    2
    Default value                WPress
    Accept pipeline input?       false
    Accept wildcard characters?  false
    
-siteUser <String>
    the user account the site shoul run as (normally IUSR),
    
    Required?                    false
    Position?                    3
    Default value                IUSR
    Accept pipeline input?       false
    Accept wildcard characters?  false
    
-portNum <String>
    port # (should not conflict with other sites),
    
    Required?                    false
    Position?                    4
    Default value                8000
    Accept pipeline input?       false
    Accept wildcard characters?  false
    
-owner <String>
    developer's user account (ff empty then ignored),
    
    Required?                    false
    Position?                    5
    Default value                
    Accept pipeline input?       false
    Accept wildcard characters?  false
    
-wordPress <String>
    boolean value (0 = false/ 1 = true)
    
    Required?                    false
    Position?                    6
    Default value                true
    Accept pipeline input?       false
    Accept wildcard characters?  false
    
<CommonParameters>
    This cmdlet supports the common parameters: Verbose, Debug,
    ErrorAction, ErrorVariable, WarningAction, WarningVariable,
    OutBuffer, PipelineVariable, and OutVariable. For more information, see 
    about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 

NOTES
This will need to be run as an administrator account.
The user account referenced in the $owner variables is not an administrator account.
If you set it to empty string it will be ignored.
If wordpress is true it will create wp-includes and wp-content directories
and set permissions to modify.

-------------------------- EXAMPLE 1 --------------------------

PS>.\website.ps1 "C:\inetpub\" "WSite007" "IUSR" "9127" "Phil" 0


-------------------------- EXAMPLE 2 --------------------------

PS>.\website.ps1 "C:\inetpub\" "WPress006" "IUSR" "9126" "Phil"


-------------------------- EXAMPLE 3 --------------------------

PS>.\website.ps1 -siteName WordPress009 -portNum "9129" -owner Phil

The following is an example of executing the script:

PS C:\Talks\Web\WordPress\AddOns\scripts> .\website.ps1 -siteName WordPress009 -portNum "9129" -owner Phil
C:\inetpub\ WordPress009 IUSR Phil True
C:\inetpub\WordPress009 \Sites\WordPress009 \AppPools\WordPress009 WordPress009 *:9129:

Directory: C:\inetpub

Mode LastWriteTime Length Name


d----- 9/11/2017 10:30 AM WordPress009

Name : WordPress009
State : Started

Name : WordPress009
ID : 6
State : Started
PhysicalPath : C:\inetpub\WordPress009
Bindings : Microsoft.IIs.PowerShell.Framework.ConfigurationElement

set-DirPermissions, directory: C:\inetpub\WordPress009 , user: IUSR , perm: ReadAndExecute

Directory: C:\inetpub\WordPress009

Mode LastWriteTime Length Name


d----- 9/11/2017 10:30 AM wp-includes
set-DirPermissions, directory: C:\inetpub\WordPress009\wp-includes , user: IUSR , perm: Modify
d----- 9/11/2017 10:30 AM wp-content
set-DirPermissions, directory: C:\inetpub\WordPress009\wp-content , user: IUSR , perm: Modify
set-DirPermissions, directory: C:\inetpub\WordPress009 , user: Phil , perm: FullControl

The WordPress009 site may require additional configuration from the
'Internet Information Services (IIS) Manager' console.

PS C:\Talks\Web\WordPress\AddOns\scripts>

Phil

@PHuhn

This comment has been minimized.

Show comment
Hide comment
@PHuhn

PHuhn Sep 13, 2017

Hi Patrick:

I have increased my scripting. I have created a script to create the database and SQL login user account. This is the read-me file:

Project Nami Windows Install Utils

Version: 2.0.0

NAME
Create-DB-User-Parms.ps1

SYNOPSIS
This is a simple T-SQL script to create a database and SQL user account. This intended to be used
in a development environment on a developer's workstation.

SYNTAX
C:\Dat\nsg\Talks\Web\WordPress\scripts\Create-DB-User-Parms.ps1 [[-server] ] [[-dbName] ]
[[-userName] ] [[-userPwd] ] [[-siteUser] ] []

DESCRIPTION
Create a website and set permissions. This is a simple PowerShell script that creates a generic website,
as follows:
* creates a database,
* create a login database account,
* grant the above account user owner/read/write permissions to the database,
* grant the 'site user' account owner/read/write permissions to the database.

PARAMETERS
-server
SQL Server instance name, . can be used for local instance or .\SQLExpress for default instance name
for Express version.

    Required?                    false
    Position?                    1
    Default value                .\SQLExpress
    Accept pipeline input?       false
    Accept wildcard characters?  false
    
-dbName <String>
    database name,
    
    Required?                    false
    Position?                    2
    Default value                WordPress
    Accept pipeline input?       false
    Accept wildcard characters?  false
    
-userName <String>
    For WordPress sites and others sites that run as SQL Server login account.  User name for login 
    database account,
    
    Required?                    false
    Position?                    3
    Default value                WPUser
    Accept pipeline input?       false
    Accept wildcard characters?  false
    
-userPwd <String>
    Password for login database account,
    
    Required?                    false
    Position?                    4
    Default value                
    Accept pipeline input?       false
    Accept wildcard characters?  false
    
-siteUser <String>
    The user account the site should run as (normally NT AUTHORITY\IUSR),
    
    Required?                    false
    Position?                    5
    Default value                
    Accept pipeline input?       false
    Accept wildcard characters?  false
    
<CommonParameters>
    This cmdlet supports the common parameters: Verbose, Debug,
    ErrorAction, ErrorVariable, WarningAction, WarningVariable,
    OutBuffer, PipelineVariable, and OutVariable. For more information, see 
    about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 

INPUTS

OUTPUTS

NOTES
siteUser user is optional.
The default values for -userPwd and -siteUser are empty string. Other default values are as follows:
-server .\SQLExpress
-dbName WordPress
-userName WPUser

-------------------------- EXAMPLE 1 --------------------------

PS>.\Create-DB-User-Parms.ps1 -server ".\Express" -userPwd "WP!000001"

-------------------------- EXAMPLE 2 --------------------------

PS>.\Create-DB-User-Parms.ps1 -server ".\Express" -dbName "WordPress008" -userName "WordPress008" -userPwd 
"WP!000001"

-------------------------- EXAMPLE 3 --------------------------

PS>.\Create-DB-User-Parms.ps1 -server ".\Express" -dbName "WordPress008" -userName "WordPress008" -userPwd 
"WP!000001" -siteUser "NT AUTHORITY\NETWORK SERVICE"

RELATED LINKS
https://github.com/ProjectNami/

EXAMPLE EXCUTION
PS C:\Talks\Web\WordPress\scripts> .\Create-DB-User-Parms.ps1 -server '.\Express' -dbName "WordPress008" -userName "WordPress008" -userPwd "WP!000001" -siteUser "NT AUTHORITY\NETWORK SERVICE"
Server: .\Express, dbName=WordPress008 uName=WordPress008 uPwd=WP!000001 siteUser=NT AUTHORITY\NETWORK SERVICE
VERBOSE: Changed database context to 'master'.
VERBOSE: CREATE DATABASE [WordPress008]
VERBOSE: CREATE LOGIN [WordPress008] WITH PASSWORD ='WP!000001'
VERBOSE:
USE [WordPress008];

 CREATE USER [WordPress008] FOR LOGIN [WordPress008] WITH DEFAULT_SCHEMA = dbo;
 EXEC sp_addrolemember @rolename='db_owner',      @membername = [WordPress008];
 EXEC sp_addrolemember @rolename='db_datareader', @membername = [WordPress008];
 EXEC sp_addrolemember @rolename='db_datawriter', @membername = [WordPress008];
 --

 CREATE USER [NT AUTHORITY\NETWORK SERVICE] FOR LOGIN [NT AUTHORITY\NETWORK SERVICE] WITH DEFAULT_SCHEMA=dbo;
 EXEC sp_addrolemember @rolename='db_owner',      @membername = [NT AUTHORITY\NETWORK SERVICE];
 EXEC sp_addrolemember @rolename='db_datareader', @membername = [NT AUTHORITY\NETWORK SERVICE];
 EXEC sp_addrolemember @rolename='db_datawriter', @membername = [NT AUTHORITY\NETWORK SERVICE];

VERBOSE:  
VERBOSE: !*!*  If the is for WordPress, paste the following into the wp-config.php  *!*!
VERBOSE: 

// ** SQL Server settings - You can get this info from your web host ** //
define('DB_NAME', 'WordPress008');  /** The name of the database */
define('DB_USER', 'WordPress008');  /** SQL database username */
define('DB_PASSWORD', 'WP!000001'); /** SQL database password */
define('DB_HOST', 'COLONY7\EXPRESS'); /** SQL hostname */


PS C:\Talks\Web\WordPress\scripts> 

I would like to contribute this set of utilities to Project Nami.

Phil

PHuhn commented Sep 13, 2017

Hi Patrick:

I have increased my scripting. I have created a script to create the database and SQL login user account. This is the read-me file:

Project Nami Windows Install Utils

Version: 2.0.0

NAME
Create-DB-User-Parms.ps1

SYNOPSIS
This is a simple T-SQL script to create a database and SQL user account. This intended to be used
in a development environment on a developer's workstation.

SYNTAX
C:\Dat\nsg\Talks\Web\WordPress\scripts\Create-DB-User-Parms.ps1 [[-server] ] [[-dbName] ]
[[-userName] ] [[-userPwd] ] [[-siteUser] ] []

DESCRIPTION
Create a website and set permissions. This is a simple PowerShell script that creates a generic website,
as follows:
* creates a database,
* create a login database account,
* grant the above account user owner/read/write permissions to the database,
* grant the 'site user' account owner/read/write permissions to the database.

PARAMETERS
-server
SQL Server instance name, . can be used for local instance or .\SQLExpress for default instance name
for Express version.

    Required?                    false
    Position?                    1
    Default value                .\SQLExpress
    Accept pipeline input?       false
    Accept wildcard characters?  false
    
-dbName <String>
    database name,
    
    Required?                    false
    Position?                    2
    Default value                WordPress
    Accept pipeline input?       false
    Accept wildcard characters?  false
    
-userName <String>
    For WordPress sites and others sites that run as SQL Server login account.  User name for login 
    database account,
    
    Required?                    false
    Position?                    3
    Default value                WPUser
    Accept pipeline input?       false
    Accept wildcard characters?  false
    
-userPwd <String>
    Password for login database account,
    
    Required?                    false
    Position?                    4
    Default value                
    Accept pipeline input?       false
    Accept wildcard characters?  false
    
-siteUser <String>
    The user account the site should run as (normally NT AUTHORITY\IUSR),
    
    Required?                    false
    Position?                    5
    Default value                
    Accept pipeline input?       false
    Accept wildcard characters?  false
    
<CommonParameters>
    This cmdlet supports the common parameters: Verbose, Debug,
    ErrorAction, ErrorVariable, WarningAction, WarningVariable,
    OutBuffer, PipelineVariable, and OutVariable. For more information, see 
    about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 

INPUTS

OUTPUTS

NOTES
siteUser user is optional.
The default values for -userPwd and -siteUser are empty string. Other default values are as follows:
-server .\SQLExpress
-dbName WordPress
-userName WPUser

-------------------------- EXAMPLE 1 --------------------------

PS>.\Create-DB-User-Parms.ps1 -server ".\Express" -userPwd "WP!000001"

-------------------------- EXAMPLE 2 --------------------------

PS>.\Create-DB-User-Parms.ps1 -server ".\Express" -dbName "WordPress008" -userName "WordPress008" -userPwd 
"WP!000001"

-------------------------- EXAMPLE 3 --------------------------

PS>.\Create-DB-User-Parms.ps1 -server ".\Express" -dbName "WordPress008" -userName "WordPress008" -userPwd 
"WP!000001" -siteUser "NT AUTHORITY\NETWORK SERVICE"

RELATED LINKS
https://github.com/ProjectNami/

EXAMPLE EXCUTION
PS C:\Talks\Web\WordPress\scripts> .\Create-DB-User-Parms.ps1 -server '.\Express' -dbName "WordPress008" -userName "WordPress008" -userPwd "WP!000001" -siteUser "NT AUTHORITY\NETWORK SERVICE"
Server: .\Express, dbName=WordPress008 uName=WordPress008 uPwd=WP!000001 siteUser=NT AUTHORITY\NETWORK SERVICE
VERBOSE: Changed database context to 'master'.
VERBOSE: CREATE DATABASE [WordPress008]
VERBOSE: CREATE LOGIN [WordPress008] WITH PASSWORD ='WP!000001'
VERBOSE:
USE [WordPress008];

 CREATE USER [WordPress008] FOR LOGIN [WordPress008] WITH DEFAULT_SCHEMA = dbo;
 EXEC sp_addrolemember @rolename='db_owner',      @membername = [WordPress008];
 EXEC sp_addrolemember @rolename='db_datareader', @membername = [WordPress008];
 EXEC sp_addrolemember @rolename='db_datawriter', @membername = [WordPress008];
 --

 CREATE USER [NT AUTHORITY\NETWORK SERVICE] FOR LOGIN [NT AUTHORITY\NETWORK SERVICE] WITH DEFAULT_SCHEMA=dbo;
 EXEC sp_addrolemember @rolename='db_owner',      @membername = [NT AUTHORITY\NETWORK SERVICE];
 EXEC sp_addrolemember @rolename='db_datareader', @membername = [NT AUTHORITY\NETWORK SERVICE];
 EXEC sp_addrolemember @rolename='db_datawriter', @membername = [NT AUTHORITY\NETWORK SERVICE];

VERBOSE:  
VERBOSE: !*!*  If the is for WordPress, paste the following into the wp-config.php  *!*!
VERBOSE: 

// ** SQL Server settings - You can get this info from your web host ** //
define('DB_NAME', 'WordPress008');  /** The name of the database */
define('DB_USER', 'WordPress008');  /** SQL database username */
define('DB_PASSWORD', 'WP!000001'); /** SQL database password */
define('DB_HOST', 'COLONY7\EXPRESS'); /** SQL hostname */


PS C:\Talks\Web\WordPress\scripts> 

I would like to contribute this set of utilities to Project Nami.

Phil

@PHuhn

This comment has been minimized.

Show comment
Hide comment
@PHuhn

PHuhn Sep 20, 2017

Crickets...
Whoever wants my utilities, I created my own repo.
https://github.com/PHuhn/ProjectNami-Windows-Install-Utils
I also have a talk WordPress-Nami-Configuring-V2-2Up located http://www.computersociety.org/clients/resources
The talk is not fully completed.

PHuhn commented Sep 20, 2017

Crickets...
Whoever wants my utilities, I created my own repo.
https://github.com/PHuhn/ProjectNami-Windows-Install-Utils
I also have a talk WordPress-Nami-Configuring-V2-2Up located http://www.computersociety.org/clients/resources
The talk is not fully completed.

@patrickebates

This comment has been minimized.

Show comment
Hide comment
@patrickebates

patrickebates Sep 21, 2017

Member

Not ignoring your work, just letting it speak for itself. We focus our efforts on Azure, so glad to see someone creating tools to help with local installation.

Member

patrickebates commented Sep 21, 2017

Not ignoring your work, just letting it speak for itself. We focus our efforts on Azure, so glad to see someone creating tools to help with local installation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment