Færdiggjort

Powershell script to read in database names and create 3 text files

Need a powershell script as described below that can ingest a list of database names, then output 3 text files. Just needs to be able to read the file in from the local working directory and output the 3 new text files to the same local working dirctory

1)take input from a text list containing a list of database names:

Databasenumber1

Databasenumber2

Databasenumber3

read the database names from the text file and output to a new text file, each database name needs 2 lines as shown below:

Backup-SqlDatabase -Database "Databasenumber1" -BackupFile "\\sqlserver1\sharetest\[url removed, login to view]" -ServerInstance "sqlserver1"

Backup-SqlDatabase -Database "Databasenumber1" -BackupAction "Log" -BackupFile "\\sqlserver\sharetest\[url removed, login to view]" -ServerInstance "sqlserver1"

Backup-SqlDatabase -Database "Databasenumber2" -BackupFile "\\sqlserver1\sharetest\[url removed, login to view]" -ServerInstance "sqlserver1"

Backup-SqlDatabase -Database "Databasenumber2" -BackupAction "Log" -BackupFile "\\sqlserver\sharetest\[url removed, login to view]" -ServerInstance "sqlserver1"

Backup-SqlDatabase -Database "Databasenumber3" -BackupFile "\\sqlserver1\sharetest\[url removed, login to view]" -ServerInstance "sqlserver1"

Backup-SqlDatabase -Database "Databasenumber3" -BackupAction "Log" -BackupFile "\\sqlserver\sharetest\[url removed, login to view]" -ServerInstance "sqlserver1"

Then also need to read in the same source text list containing the database names and output another file with this content:

EXECUTE AS login='USERNAME;

RESTORE DATABASE Databasenumber1 FROM DISK = '\\sqlserver1\sharetest\[url removed, login to view]' WITH NORECOVERY;

REVERT;

GO

RESTORE LOG Databasenumber1 FROM DISK = '\\sqlserver1\sharetest\[url removed, login to view]' WITH NORECOVERY, FILE = 1

GO

EXECUTE AS login='USERNAME;

RESTORE DATABASE Databasenumber2 FROM DISK = '\\sqlserver1\sharetest\[url removed, login to view]' WITH NORECOVERY;

REVERT;

GO

RESTORE LOG Databasenumber2 FROM DISK = '\\sqlserver1\sharetest\[url removed, login to view]' WITH NORECOVERY, FILE = 1

GO

EXECUTE AS login='USERNAME;

RESTORE DATABASE Databasenumber3 FROM DISK = '\\sqlserver1\sharetest\[url removed, login to view]' WITH NORECOVERY;

REVERT;

GO

RESTORE LOG Databasenumber2 FROM DISK = '\\sqlserver3\sharetest\[url removed, login to view]' WITH NORECOVERY, FILE = 1

GO

3rd text file output, section below for each of the database names from the original list:

USE [master]

GO

ALTER AVAILABILITY GROUP [AGGROUP1]

ADD DATABASE [Databasenumber1];

GO

:ConnectDB2

begin try

declare @conn bit

declare @count int

declare @replica_id uniqueidentifier

declare @group_id uniqueidentifier

set @conn = 0

set @count = 30 -- wait for 5 minutes

if (serverproperty('IsHadrEnabled') = 1)

and (isnull((select member_state from master.sys.dm_hadr_cluster_members where upper(member_name COLLATE Latin1_General_CI_AS) = upper(cast(serverproperty('ComputerNamePhysicalNetBIOS') as nvarchar(256)) COLLATE Latin1_General_CI_AS)), 0) <> 0)

and (isnull((select state from master.sys.database_mirroring_endpoints), 1) = 0)

begin

select @group_id = ags.group_id from master.sys.availability_groups as ags where name = N'AGGROUP1'

select @replica_id = replicas.replica_id from master.sys.availability_replicas as replicas where upper(replicas.replica_server_name COLLATE Latin1_General_CI_AS) = upper(@@SERVERNAME COLLATE Latin1_General_CI_AS) and group_id = @group_id

while @conn <> 1 and @count > 0

begin

set @conn = isnull((select connected_state from master.sys.dm_hadr_availability_replica_states as states where states.replica_id = @replica_id), 1)

if @conn = 1

begin

-- exit loop when the replica is connected, or if the query cannot find the replica status

break

end

waitfor delay '00:00:10'

set @count = @count - 1

end

end

end try

begin catch

-- If the wait loop fails, do not stop execution of the alter database statement

end catch

ALTER DATABASE [Databasenumber1] SET HADR AVAILABILITY GROUP = [AGGROUP1];

GO

Evner: Powershell, Scripting

Se mere: powershell read text file into variable, powershell read text file into array, powershell read text file line by line foreach, powershell computer name in text file, powershell get sql database information, run powershell script against list of computers, powershell read file line by line into array, powershell list sql databases, powershell script read excel, create gui text files, cron script read database, read xml file create mysql database php script, powershell script read excel file, powershell script create multiple users, sql script create daily text file, create database text files, create cms text files, script read database send email, php script read emails text file, create number text message database

Om arbejdsgiveren:
( 0 bedømmelser ) Pensacola, United States

Projekt ID: #16637004

Tildelt til:

dfabretti

Hi there! My name is Douglas and I have been working as an Automation Developer for the last 5 years. I mainly develop using Powershell scripts and I what you need is basically what I do on a daily basis Anyway, Flere

$90 USD in 2 dage
(5 bedømmelser)
3.0

5 freelancere byder i gennemsnit $100 på dette job

afoad

I’m an IT professional with around 6 years of experience in Unified Communication and Virtualization technology, during this period I have worked on lots of projects in Egypt and KSA with multiple vendors such as Micro Flere

$166 USD in 5 dage
(8 bedømmelser)
3.6
$155 USD in 3 dage
(0 bedømmelser)
0.0
kushsolanki1991

hi, I am having sound knowledge of powershell scripting and I use in my daily task for automation of things like alerts, backup jobs, scheduled tasks etc.. I can give you scrip for your need in a day. I know that I d Flere

$55 USD på 1 dag
(0 bedømmelser)
0.0
kanwaljeetk56

A proposal has not yet been provided

$35 USD på 1 dag
(0 bedømmelser)
0.0