<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Edwin M Sarmientomodify SQL Server logins &#8211; Edwin M Sarmiento</title>
	<atom:link href="https://www.edwinmsarmiento.com/category/modify-sql-server-logins/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.edwinmsarmiento.com</link>
	<description>Intentional Excellence</description>
	<lastBuildDate>Mon, 13 Apr 2026 21:00:49 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
<site xmlns="com-wordpress:feed-additions:1">84283043</site>		<item>
		<title>Your poor man&#8217;s SQL Server log shipping-PowerShell version</title>
		<link>https://www.edwinmsarmiento.com/your-poor-mans-sql-server-log-shipping-powershell-version/</link>
		<comments>https://www.edwinmsarmiento.com/your-poor-mans-sql-server-log-shipping-powershell-version/#comments</comments>
		<pubDate>Sat, 01 May 2010 14:18:00 +0000</pubDate>
		<dc:creator>Edwin M Sarmiento</dc:creator>
				<category><![CDATA[log shipping]]></category>
		<category><![CDATA[modify SQL Server logins]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SQL Server]]></category>
		<guid isPermaLink="false">http://bassplayerdoc.wordpress.com/2010/05/01/your-poor-mans-sql-server-log-shipping-powershell-version</guid>

				<description><![CDATA[In 2008, I was privileged to be a part of a project to write a chapter for a book that was for a good cause. SQL Server MVP Deep Dives became an avenue for a lot of the SQL Server MVPs to share their expertise for the benefit of not just the technical community but [&#8230;]]]></description>
					<content:encoded><![CDATA[<p><span style="font-family: arial;">In 2008, I was privileged to be a part of a project to write a chapter for a book that was for a good cause. </span><a href="http://www.manning.com/nielsen/"><span style="font-family: arial;">SQL Server MVP Deep Dives</span></a><span style="font-family: arial;"> became an avenue for a lot of the SQL Server MVPs to share their expertise for the benefit of not just the technical community but of the beneficiary.</span></p>
<p><span style="font-family: Arial;">I wrote a chapter for the book based on this <a href="https://www.edwinmsarmiento.com/your-poor-mans-sql-server-log-shipping/" target="_blank">blog post</a> some three years ago and one of the recommendations I did was to convert the VBScript scripts to Windows PowerShell. So, here it is.</span></p>
<p><span style="font-family: Arial;">I&#8217;ve converted the VBScript that does the checking of the folders containing my latest LOG backups and restoring them in NORECOVERY mode to Windows PowerShell. What is fascinating is the fact that if the process I&#8217;ve outlined in the blog post is followed thru, adding another database to be configured for log shipping was as easy as creating regular LOG backups via TSQL scripts or database maintenance plans &#8211; no need to add an entry for every database that will be configured. How cool was that?</span></p>
<p><span style="font-family: Arial;">So, here&#8217;s the Windows PowerShell version of the custom restore LOG backup command</span></p>
<p><code style="font-size: 12px;"><span style="color: black;">$logBackupFolder</span><span style="color: blue;">=</span><span style="color: darkred;">"your LOG backup location here or a parameter variable"</p>
<p></span><span style="color: black;">##Variable </span><span style="color: blue;">for </span><span style="color: black;">time duration </span><span style="color: gray;">- </span><span style="color: black;">the amount of time you need to generate and restore LOG backups<br />
$1HourOld </span><span style="color: blue;">= </span><span style="color: black;">[DateTime]</span><span style="color: gray;">::</span><span style="color: black;">Now.AddHours</span><span style="color: gray;">(-</span><span style="color: black;">1</span><span style="color: gray;">)</p>
<p></span><span style="color: black;">##Retrieve folders and files </span><span style="color: blue;">in </span><span style="color: black;">the specified directory<br />
</span><span style="color: blue;">foreach </span><span style="color: gray;">(</span><span style="color: black;">$databaseName </span><span style="color: blue;">in </span><span style="color: gray;">(</span><span style="color: black;">Get</span><span style="color: gray;">-</span><span style="color: black;">ChildItem $logBackupFolder </span><span style="color: gray;">| </span><span style="color: black;">Where { $_.PsIsContainer }</span><span style="color: gray;">) )<br />
</span><span style="color: black;">{<br />
</span><span style="color: blue;">foreach </span><span style="color: gray;">(</span><span style="color: black;">$logName </span><span style="color: blue;">in </span><span style="color: gray;">(</span><span style="color: black;">Get</span><span style="color: gray;">-</span><span style="color: black;">ChildItem $logBackupFolder$databasename </span><span style="color: gray;">| </span><span style="color: black;">where {</span><span style="color: gray;">(</span><span style="color: black;">$_.CreationTime </span><span style="color: gray;">-</span><span style="color: black;">ge $1HourOld</span><span style="color: gray;">) -</span><span style="color: black;">and </span><span style="color: gray;">(</span><span style="color: black;">$_.Extension </span><span style="color: gray;">-</span><span style="color: black;">eq </span><span style="color: darkred;">".trn"</span><span style="color: gray;">)</span><span style="color: black;">} SELECT name</span><span style="color: gray;">))<br />
</span><span style="color: black;">{</p>
<p>$logBackupPath </span><span style="color: blue;">= </span><span style="color: black;">[System.String]</span><span style="color: gray;">::</span><span style="color: black;">Concat</span><span style="color: gray;">(</span><span style="color: darkred;">"'$logBackupFolder"</span><span style="color: gray;">,</span><span style="color: black;">$databasename</span><span style="color: gray;">,</span><span style="color: darkred;">""</span><span style="color: gray;">,</span><span style="color: black;">$logName.Name</span><span style="color: gray;">,</span><span style="color: darkred;">"'"</span><span style="color: gray;">)<br />
</span><span style="color: black;">$restoreSQL </span><span style="color: blue;">= </span><span style="color: darkred;">"RESTORE LOG $databaseName FROM DISK=$logBackupPath WITH NORECOVERY" </span><span style="color: gray;">| </span><span style="color: black;">Out</span><span style="color: gray;">-</span><span style="color: black;">File D:$databaseName.sql</p>
<p>Invoke</span><span style="color: gray;">-</span><span style="color: black;">Expression </span><span style="color: darkred;">"osql.exe -SYourSQLServerInstanceHere -E -iD:$databaseName.sql"</p>
<p></span><span style="color: black;">}<br />
}<br />
</span></code></p>
<p><span style="font-family: Arial;">You might be wondering why I am using osql.exe instead of sqlcmd.exe. Well, it&#8217;s still there even if you have SQL Server 2008. Which means this script will work even for SQL Server 2000 instances as long as you install Windows PowerShell on the machine running SQL Server.</span></p>
<p><span style="font-family: Arial;">And all of that for a mere 17-liner script. I could write it even less than that but I&#8217;m a big fan of script readability. Now, that&#8217;s a good enough reason to dig deeper on what Windows PowerShell has to offer</span></p>
<div class="blogger-post-footer"><img alt="" width="1" height="1" /></div>
]]></content:encoded>
			

		<wfw:commentRss>https://www.edwinmsarmiento.com/your-poor-mans-sql-server-log-shipping-powershell-version/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
				<post-id xmlns="com-wordpress:feed-additions:1">213</post-id>	</item>
		<item>
		<title>Check the last backup date in SQL Server using Windows PowerShell</title>
		<link>https://www.edwinmsarmiento.com/check-the-last-backup-date-in-sql-server-using-windows-powershell/</link>
		<comments>https://www.edwinmsarmiento.com/check-the-last-backup-date-in-sql-server-using-windows-powershell/#respond</comments>
		<pubDate>Tue, 16 Jun 2009 23:32:00 +0000</pubDate>
		<dc:creator>Edwin M Sarmiento</dc:creator>
				<category><![CDATA[last backup date]]></category>
		<category><![CDATA[modify SQL Server logins]]></category>
		<category><![CDATA[Windows PowerShell]]></category>
		<guid isPermaLink="false">http://bassplayerdoc.wordpress.com/2009/06/16/check-the-last-backup-date-in-sql-server-using-windows-powershell</guid>

				<description><![CDATA[This article highlights how to use Windows PowerShell to retrieve database properties using SMO. Notice how easy it is to check the database properties using pretty common syntax One of the challenges I have when I was starting out as a SQL Server DBA was to check for the last backup date for a database. [&#8230;]]]></description>
					<content:encoded><![CDATA[<p><span style="font-family:arial;">This <a href="http://mssqltips.com/tip.asp?tip=1759">article </a>highlights how to use Windows PowerShell to retrieve database properties using SMO. Notice how easy it is to check the database properties using pretty common syntax</span></p>
<p>One of the challenges I have when I was starting out as a SQL Server DBA was to check for the last backup date for a database. One way to do this is to find out which tables in the MSDB database contain the records of the backup history. What&#8217;s really challenging here is the fact that you would have to look at the tables and their corresponding relationships which, apparently, MSDB doesn&#8217;t have. You simply have to rely on what SQL Server Books Online has to say. Plus, the MSDB database will only contain records for databases with backups. What about those without?</p>
<p>For SQL Server 2005, the script below displays the last backup date of all the databases on your SQL Server instance. This script is from the <a href="http://code.msdn.microsoft.com/SQLExamples/Wiki/View.aspx?title=LastBackUpDate">MSDN Code Gallery</a></p>
<p><code style="font-size:12px;"><span style="color:blue;">SELECT<br />
</span><span style="color:black;">T1.Name </span><span style="color:blue;">AS </span><span style="color:black;">DatabaseName</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">COALESCE</span><span style="color:gray;">(</span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">12</span><span style="color:gray;">), </span><span style="color:blue;">MAX</span><span style="color:gray;">(</span><span style="color:black;">T2.backup_finish_date</span><span style="color:gray;">), </span><span style="color:black;">101</span><span style="color:gray;">),</span><span style="color:red;">'Not Yet Taken'</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">LastBackUpTaken</span><span style="color:black;"><br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.sysdatabases T1 </span><span style="color:magenta;">LEFT </span><span style="color:gray;">OUTER </span><span style="color:blue;">JOIN </span><span style="color:black;">msdb.dbo.backupset T2<br />
</span><span style="color:blue;">ON </span><span style="color:black;">T2.database_name </span><span style="color:blue;">= </span><span style="color:black;">T1.name<br />
</span><span style="color:blue;">GROUP BY </span><span style="color:black;">T1.Name<br />
</span><span style="color:blue;">ORDER BY </span><span style="color:black;">T1.Name<br />
</span></code><br />
<span style="font-family:arial;">You can simply replace the <span style="font-size:85%;"><span style="font-weight:bold;">sys.sysdatabases</span></span> table with <span style="font-size:85%;"><span style="font-weight:bold;">master.dbo.sysdatabases</span></span> for SQL Server 2000</span></p>
<p>Below is the equivalent script using Windows PowerShell.</p>
<pre class="brush: powershell; title: ; notranslate">
$instance=&amp;quot;Your_SQL_Server_Instance_Name&amp;quot;
&#x5B;System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO')| out-null

# Create an SMO connection to the instance
$s = new-object ('Microsoft.SqlServer.Management.Smo.Server') $instance

$dbs = $s.Databases
$dbs | select Name,LastBackupDate, LastLogBackupDate | format-table -autosize
</pre>
<p>The only thing to note here are the last two lines &#8211; the one that creates an instance of the database object and the one that displays and formats a few of the database object properties. The first few lines will be the same for just about any PowerShell script that will access SQL Server using SMO</p>
<div class="blogger-post-footer"><img decoding="async" src="" alt="" width="1" height="1" /></div>
]]></content:encoded>
			

		<wfw:commentRss>https://www.edwinmsarmiento.com/check-the-last-backup-date-in-sql-server-using-windows-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
				<post-id xmlns="com-wordpress:feed-additions:1">192</post-id>	</item>
		<item>
		<title>Changing a SQL Server 2000 login</title>
		<link>https://www.edwinmsarmiento.com/changing-a-sql-server-2000-login/</link>
		<comments>https://www.edwinmsarmiento.com/changing-a-sql-server-2000-login/#respond</comments>
		<pubDate>Tue, 07 Apr 2009 02:02:00 +0000</pubDate>
		<dc:creator>Edwin M Sarmiento</dc:creator>
				<category><![CDATA[modify SQL Server logins]]></category>
		<category><![CDATA[SQL Server 2000]]></category>
		<guid isPermaLink="false">http://bassplayerdoc.wordpress.com/2009/04/07/changing-a-sql-server-2000-login</guid>

				<description><![CDATA[WARNING: This is not a recommended approach. Use at your own risk While SQL Server 2005 has the ALTER LOGIN statement to change the properties of a SQL Server login account, SQL Server 2000 does not have such a command. Unfortunately, there are cases where you need to simply rename the login due to a [&#8230;]]]></description>
					<content:encoded><![CDATA[<div align="center"><strong><span style="font-size:85%;">WARNING: This is not a recommended approach. Use at your own risk</span></strong></div>
<p><span style="font-family:arial;">While SQL Server 2005 has the <a href="http://msdn.microsoft.com/en-us/library/ms189828(SQL.90).aspx">ALTER LOGIN</a> statement to change the properties of a SQL Server login account, SQL Server 2000 does not have such a command. Unfortunately, there are cases where you need to simply rename the login due to a misspelled name or a change management policy. The proper way to do it in SQL Server 2000 is to create the new login, map the permissions and roles of the existing login that you wish to change to this new login and, then, drop the old login. I wouldn&#8217;t want to go thru that if I only have to rename the login. The only simpler way to do it is to modify the system tables. As I&#8217;ve said, it is not recommended to modify the system tables and/or objects directly so bear in mind that doing this would be at your own risk. This would also require that you torn on allowing ad hoc updates to system tables and turning it off afterwards</span></p>
<p><span style="font-family:Arial;"><span style="font-size:85%;"><span style="color:darkred;">sp_CONFIGURE </span><span style="color:red;">&#8216;ALLOW UPDATES&#8217;</span><span style="color:gray;">, </span><span style="color:black;">1<br />
GO<br />
</span><span style="color:blue;">RECONFIGURE WITH </span><span style="color:black;">OVERRIDE<br />
GO </span></span></span></p>
<p><span style="color:blue;">UPDATE </span><span style="color:black;">db..sysusers<br />
</span><span style="color:blue;">SET </span><span style="color:black;">name</span><span style="color:blue;">=</span><span style="color:red;">&#8216;newLogin&#8217;<br />
</span><span style="color:blue;">WHERE<br />
</span><span style="color:black;">name</span><span style="color:blue;">=</span><span style="color:red;">&#8216;oldLogin&#8217; </span></p>
<p><span style="color:blue;">UPDATE </span><span style="color:black;">master..sysxlogins<br />
</span><span style="color:blue;">SET </span><span style="color:black;">name</span><span style="color:blue;">=</span><span style="color:red;">&#8216;newLogin&#8217;<br />
</span><span style="color:blue;">WHERE<br />
</span><span style="color:black;">name</span><span style="color:blue;">=</span><span style="color:red;">&#8216;oldLogin&#8217; </span></p>
<p><span style="color:darkred;">sp_CONFIGURE </span><span style="color:red;">&#8216;ALLOW UPDATES&#8217;</span><span style="color:gray;">, </span><span style="color:black;">0<br />
GO<br />
</span><span style="color:blue;">RECONFIGURE WITH </span><span style="color:black;">OVERRIDE<br />
GO </span></p>
<p><span style="font-family:arial;">A similar stored procedure is described <a href="http://www.sqlservercentral.com/scripts/Miscellaneous/30178/">here</a></span></p>
<div class="blogger-post-footer"><img decoding="async" src="https://blogger.googleusercontent.com/tracker/92377218009570869-7853894846892751022?l=bassplayerdoc.blogspot.com" alt="" width="1" height="1" /></div>
]]></content:encoded>
			

		<wfw:commentRss>https://www.edwinmsarmiento.com/changing-a-sql-server-2000-login/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
				<post-id xmlns="com-wordpress:feed-additions:1">180</post-id>	</item>
	</channel>
</rss>