Skip to content

Commit

Permalink
Changed most Read-Host lines with script parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Russell committed Nov 26, 2018
1 parent 30aa303 commit e3a36ec
Show file tree
Hide file tree
Showing 22 changed files with 101 additions and 219 deletions.
10 changes: 1 addition & 9 deletions IIS-delete-website.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
# This script will go and delete the IIS website that you specify, along with the corresponding app pool and DNS entry.
# It is meant to be run from your local computer, so you don't have to log in to your web server and domain controller to delete the website, all you have to do is run the script.

Do {
$webserver = Read-Host "Enter the DNS name of the web server"
}
While ($webserver -eq "")
Do {
$dnsserver = Read-Host "Enter the DNS name of the domain controller"
}
While ($dnsserver -eq "")
param($webserver,$dnsserver)

$sites = Invoke-Command -ComputerName $webserver -ScriptBlock {
$websites = Get-Website
Expand Down
5 changes: 1 addition & 4 deletions IIS-restart-all-apppools.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# This script remotely restarts all the web app pools on the specified web server
Do {
$webserver = Read-Host "Enter the DNS name of the web server"
}
While ($webserver -eq "")
param($webserver)
# Invoke command on remote web server
Invoke-Command -ComputerName $webserver -ScriptBlock {
Import-Module WebAdministration
Expand Down
27 changes: 7 additions & 20 deletions create-csv-from-mysql-table.ps1
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
# Install-Module InvokeQuery
# Run the above command if you do not have this module
param(
$server,
$database,
$dbuser,
$dbpass,
$query
)
$csvfilepath = "$PSScriptRoot\mysql_table.csv"
Do {
$server = Read-Host "Please enter the server host name or IP of the database"
}
While ($server -eq "")
Do {
$database = Read-Host "Please enter the database name"
}
While ($database -eq "")
Do {
$dbuser = Read-Host "Please enter the database user"
}
While ($dbuser -eq "")
Do {
$dbpass = Read-Host "Please enter the database user's password"
}
While ($dbpass -eq "")
Do {
$query = Read-Host "Please enter the sql query"
}
While ($query -eq "")
$result = Invoke-MySqlQuery -ConnectionString "server=$server; database=$database; user=$dbuser; password=$dbpass; pooling = false; convert zero datetime=True" -Sql $query -CommandTimeout 10000
$result | Export-Csv $csvfilepath -NoTypeInformation
17 changes: 4 additions & 13 deletions create-csv-from-sqlserver-table.ps1
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
# Install-Module InvokeQuery
# Run the above command if you do not have this module
param($server,$database,$query,$username,$password)
$secpasswd = ConvertTo-SecureString $password -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential ($username, $secpasswd)
$csvfilepath = "$PSScriptRoot\sqlserver_table.csv"
Do {
$server = Read-Host "Please enter the server host name or IP of the database"
}
While ($server -eq "")
Do {
$database = Read-Host "Please enter the database name"
}
While ($database -eq "")
Do {
$query = Read-Host "Please enter the sql query"
}
While ($query -eq "")
$result = Invoke-SqlServerQuery -Credential (Get-Credential) -ConnectionTimeout 10000 -Database $database -Server $server -Sql $query -CommandTimeout 10000
$result = Invoke-SqlServerQuery -Credential $creds -ConnectionTimeout 10000 -Database $database -Server $server -Sql $query -CommandTimeout 10000
$result | Export-Csv $csvfilepath -NoTypeInformation
23 changes: 6 additions & 17 deletions create-startup-executable.ps1
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
# This script can be used to quickly schedule an executable to be run on start up. In it I assume some basic settings for the sake of simplicity.
# Grab data from user
Do {
$name = Read-Host "Please enter the name of the new task"
}
While ($name -eq "")
Do {
$exec = Read-Host "Please enter the path to the executable for the new task"
}
While ($exec -eq "")
Do {
$user = Read-Host "Please enter the user id for the new task"
}
While ($user -eq "")
Do {
$desc = Read-Host "Please enter the description for the new task"
}
While ($desc -eq "")
param(
$name,
$exec,
$user,
$desc
)
# Create action object
$action = New-ScheduledTaskAction -Execute $exec
# Create trigger object
Expand Down
23 changes: 6 additions & 17 deletions create-startup-powershell-script.ps1
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
# This script can be used to quickly schedule a powershell script to be run on start up. In it I assume some basic settings for the sake of simplicity.
# Grab data from user
Do {
$name = Read-Host "Please enter the name of the new task"
}
While ($name -eq "")
Do {
$script = Read-Host "Please enter the path to the Powershell script for the new task"
}
While ($script -eq "")
Do {
$user = Read-Host "Please enter the user id for the new task"
}
While ($user -eq "")
Do {
$desc = Read-Host "Please enter the description for the new task"
}
While ($desc -eq "")
param(
$name,
$script,
$user,
$desc
)
# Create action object
$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-file $script"
# Create trigger object
Expand Down
13 changes: 4 additions & 9 deletions create-symbolic-link.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
# This script is super simple, it just creates a symbolic link.
# It repuires the code module, so if you don't have it you can install it with:
# Install-Module core
# Grab input
Do {
$linkpath = Read-Host "Please enter the path of the symbolic link"
}
While ($linkpath -eq "")
Do {
$target = Read-Host "Please enter the path of the target"
}
While ($target -eq "")
param(
$linkpath,
$target
)
# Create the link
New-SymLink -Link $linkpath -Target $target
6 changes: 1 addition & 5 deletions download-web-files.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# This script allows you to download all the files listed on a website's directory listing.
# First, you must copy the list of files from your web browser into a CSV named files.csv , and it must have a header row that says "name". Then put that csv in the same directory as the script.
# Grab the url of the website
Do {
$url = Read-Host "Please enter the url of the website"
}
While ($url -eq "")
param($url)
# Import the CSV of file names
$files = Import-Csv "$PSScriptRoot\files.csv"
# Create a directory to store downloaded files in
Expand Down
13 changes: 2 additions & 11 deletions file-search.ps1
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
# This script serves as a quick Powershell replacement to the search functionality in Windows.
# After you enter a root folder and a search term, the script will list all files and folders matching that phrase.
# Grab root folder path
Do {
$path = Read-Host "Please enter the full path of the folder you want to search"
}
While ($path -eq "")
# Grab search term
Do {
$term = Read-Host "Please enter the search term"
}
While ($term -eq "")
# After you pass in a root folder and a search term, the script will list all files and folders matching that phrase.
param($path,$term)
# Recursive search function
Write-Host "Results:"
function Search-Folder($FilePath, $SearchTerm) {
Expand Down
13 changes: 2 additions & 11 deletions git-init.ps1
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
# This script initializes a git repository in the folder specified, adds the files, makes the first commit, adds the remote repository, and pushes the repository.
# All you have to do is specify the full path to the folder and the url of the repository
# Grab the folder path
Do {
$path = Read-Host "Enter the path of the project"
}
While ($path -eq "")
# Grab the url of the repository
Do {
$url = Read-Host "Enter the url of the repository"
}
While ($url -eq "")
# All you have to do is pass in the full path to the folder and the url of the repository
param($path,$url)
# Set the current working directory to the folder path
Set-Location $path
# Initialize an empty git repo
Expand Down
2 changes: 1 addition & 1 deletion git-pull.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This script pulls updates from git for every folder in a directory.
# This can be useful if you made changes to several apps and want to retrieve the updates for all apps by just running one script.
# You can also schedule in in Task Scheduler to periodically grab updates
$rootFolder = "" # Enter the full path of the folder containing your git projects
param($rootFolder)
$folders = Get-ChildItem $rootFolder
foreach ($folder in $folders) {
$foldername = $folder.Name
Expand Down
17 changes: 1 addition & 16 deletions list-tables-mysql.ps1
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
# This script lists all of the tables in a MySQL database and exports the list as a CSV
# Install-Module InvokeQuery
# Run the above command if you do not have this module
param($server,$database,$dbuser,$dbpass)
$csvfilepath = "$PSScriptRoot\mysql_tables.csv"
Do {
$server = Read-Host "Please enter the server host name or IP of the database"
}
While ($server -eq "")
Do {
$database = Read-Host "Please enter the database name"
}
While ($database -eq "")
Do {
$dbuser = Read-Host "Please enter the database user"
}
While ($dbuser -eq "")
Do {
$dbpass = Read-Host "Please enter the database user's password"
}
While ($dbpass -eq "")
$result = Invoke-MySqlQuery -ConnectionString "server=$server; database=$database; user=$dbuser; password=$dbpass; pooling = false; convert zero datetime=True" -Sql "SHOW TABLES" -CommandTimeout 10000
$result | Export-Csv $csvfilepath -NoTypeInformation
13 changes: 4 additions & 9 deletions list-tables-sqlserver.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
# This script lists all of the tables in a SQL Server database and exports the list as a CSV
# Install-Module InvokeQuery
# Run the above command if you do not have this module
param($server,$database,$username,$password)
$secpasswd = ConvertTo-SecureString $password -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential ($username, $secpasswd)
$csvfilepath = "$PSScriptRoot\sqlserver_tables.csv"
Do {
$server = Read-Host "Please enter the server host name or IP of the database"
}
While ($server -eq "")
Do {
$database = Read-Host "Please enter the database name"
}
While ($database -eq "")
$result = Invoke-SqlServerQuery -Credential (Get-Credential) -ConnectionTimeout 10000 -Database $database -Server $server -Sql "SELECT TABLE_NAME FROM $database.INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'" -CommandTimeout 10000
$result = Invoke-SqlServerQuery -Credential $creds -ConnectionTimeout 10000 -Database $database -Server $server -Sql "SELECT TABLE_NAME FROM $database.INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'" -CommandTimeout 10000
$result | Export-Csv $csvfilepath -NoTypeInformation
4 changes: 2 additions & 2 deletions monitor-webpage.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
. $PSScriptRoot\send-email.ps1
param($url)
. $PSScriptRoot\send-email.ps1
# This script checks every hour to see if a website returns a 200 status code. If it doesn't, the script sends an email.
$url = "" # Specify the url of the website
$interval = 3600 # You can change the interval, by default set as 1 hour
while (1) {
$request = Invoke-WebRequest -Uri $url
Expand Down
2 changes: 1 addition & 1 deletion nodejs-forever-start-apps.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# This script loops through every folder in a directory and starts all the Node.js apps inside them.
# This script is dependent on every one of your Node.js entry point files having the same name, like in this case, server.js
# You also need to have forever or PM2 installed to use lines 12 or 14.
param($webroot)
# Get list of folders
$webroot = "" # Fill this in with the full path to your web root.
$folders = Get-ChildItem $webroot
# Loop through folders
foreach ($folder in $folders) {
Expand Down
8 changes: 5 additions & 3 deletions ping-server.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# This script pings a server or IP every interval. This is useful for servers that "go to sleep" (for lack of a better term) when they aren't receiving any activity.
$server = "" # Specify the server name or IP
$interval = 30 # You can change the interval, by default set as 30 seconds
param(
$server,
$intervalSeconds
)
while (1) {
ping $server
Start-Sleep -Seconds $interval
Start-Sleep -Seconds $intervalSeconds
}
17 changes: 9 additions & 8 deletions ssh-apt-upgrade-ubuntu.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# This script performs a software update on a Ubuntu or Debian server
# Grab server IP
Do {
$server = Read-Host "Please enter the IP of the Linux server"
}
While ($server -eq "")
# Grab credentials
$creds = Get-Credential
param(
$server,
$username,
$password
)
# Create credential object based on parameters
$secpasswd = ConvertTo-SecureString $password -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential ($username, $secpasswd)
$user = $creds.UserName
# Create SSH session
$session = New-SSHSession -ComputerName $server -Credential $creds
Expand All @@ -17,7 +18,7 @@ $result = Invoke-SSHStreamExpectSecureAction -ShellStream $stream -Command "apt-
Start-Sleep -Seconds 30
$return = $stream.Read()
Write-Host $return
# Run apt=get upgrade
# Run apt-get upgrade
$result = Invoke-SSHStreamExpectSecureAction -ShellStream $stream -Command "apt-get upgrade" -ExpectString "[sudo] password for $($user):" -SecureAction $creds.Password
# Wait 2 minutes for apt-get upgrade to run
Start-Sleep -Seconds 120
Expand Down
30 changes: 11 additions & 19 deletions ssh-new-db-mongodb.ps1
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
# This script creates a new MongoDB database on the Linux host
# Grab server IP
Do {
$server = Read-Host "Please enter the IP of the Linux server"
}
While ($server -eq "")
Do {
$NEWDB = Read-Host "Database Name"
}
While ($NEWDB -eq "")
Do {
$NEWUSER = Read-Host "Database User"
}
While ($NEWUSER -eq "")
Do {
$NEWPWD = Read-Host "Database Password"
}
While ($NEWPWD -eq "")
# Grab credentials
$creds = Get-Credential
param(
$server,
$username,
$password,
$NEWDB,
$NEWUSER,
$NEWPWD
)
# Create credential object based on parameters
$secpasswd = ConvertTo-SecureString $password -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential ($username, $secpasswd)
$user = $creds.UserName
# Create SSH session
$session = New-SSHSession -ComputerName $server -Credential $creds
Expand Down
35 changes: 12 additions & 23 deletions ssh-new-db-mysql.ps1
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
# This script creates a new MySQL database on the Linux host
# Grab server IP
Do {
$server = Read-Host "Please enter the IP of the Linux server"
}
While ($server -eq "")
Do {
$NEWDB = Read-Host "Database Name"
}
While ($NEWDB -eq "")
Do {
$NEWUSER = Read-Host "Database User"
}
While ($NEWUSER -eq "")
Do {
$NEWPWD = Read-Host "Database Password"
}
While ($NEWPWD -eq "")
Do {
$ROOTPWD = Read-Host "MySQL Root Password"
}
While ($ROOTPWD -eq "")
# Grab credentials
$creds = Get-Credential
param(
$server,
$username,
$password,
$NEWDB,
$NEWUSER,
$NEWPWD,
$ROOTPWD
)
# Create credential object based on parameters
$secpasswd = ConvertTo-SecureString $password -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential ($username, $secpasswd)
$user = $creds.UserName
# Create SSH session
$session = New-SSHSession -ComputerName $server -Credential $creds
Expand Down
Loading

0 comments on commit e3a36ec

Please sign in to comment.