<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>olivier pieri's WebLog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/olivier_pieri/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/olivier_pieri/feed.xml</link>
    <description>SQL, SQL Server, ADO.NET and other data topics</description>
    <lastBuildDate>Wed, 17 Apr 2019 04:07:00 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>SQL Server 2012 : introduction to tabular model</title>
      <link>https://docs.microsoft.com/archive/blogs/olivier_pieri/sql-server-2012-introduction-to-tabular-model</link>
      <pubDate>Fri, 25 Nov 2011 00:12:31 GMT</pubDate>
      <dc:creator><![CDATA[olivier pieri]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/olivier_pieri/2011/11/25/sql-server-2012-introduction-to-tabular-model/</guid>
      <description><![CDATA[Here, you can find a good article for you in order to introduce a sql server analysis services 2012...]]></description>
      <content:encoded><![CDATA[<p>Here, you can find a good article for you in order to introduce a sql server analysis services 2012 new functionality : tabular model :</p>
<p><a href="https://msdn.microsoft.com/en-us/library/hh231691(SQL.110).aspx">https://msdn.microsoft.com/en-us/library/hh231691(SQL.110).aspx</a></p>
<p>&nbsp;</p>
<p>enjoy</p>]]></content:encoded>
    </item>
    <item>
      <title>Retreive Analysis Services warning with powershell</title>
      <link>https://docs.microsoft.com/archive/blogs/olivier_pieri/retreive-analysis-services-warning-with-powershell</link>
      <pubDate>Thu, 22 Sep 2011 01:46:00 GMT</pubDate>
      <dc:creator><![CDATA[olivier pieri]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/olivier_pieri/2011/09/22/retreive-analysis-services-warning-with-powershell/</guid>
      <description><![CDATA[One great feature of Analysis Services is to give warning about your cube design during the design...]]></description>
      <content:encoded><![CDATA[<p>One great feature of Analysis Services is to give warning about your cube design during the design of your cube.</p>
<p>These warning can be retreive after you have deployed your cube on the Analysis Services Server.</p>
<p>&nbsp;</p>
<p>here is a sample script to retreive these warning :</p>
<p><span style="font-family: courier new,courier;">[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices")</span><br /><span style="font-family: courier new,courier;">$serverAS = New-Object Microsoft.AnalysisServices.Server</span><br /><span style="font-family: courier new,courier;">$serverAS.connect("ServerName")</span><br /><span style="font-family: courier new,courier;">$db = $serverAS.databases["DatabaseName"]</span></p>
<p><span style="font-family: courier new,courier;">$val = new-object Microsoft.AnalysisServices.ValidationResultCollection</span></p>
<p><span style="font-family: courier new,courier;">foreach ($dim in $db.dimensions)</span><br /><span style="font-family: courier new,courier;">{</span><br /><span style="font-family: courier new,courier;">&nbsp;write-host "Validation dimension : ", $dim.name</span><br /><span style="font-family: courier new,courier;">&nbsp;$dim.validate($val, 4)</span><br /><span style="font-family: courier new,courier;">}</span></p>
<p><span style="font-family: courier new,courier;">foreach ($cube in $db.cubes)</span><br /><span style="font-family: courier new,courier;">&nbsp;{</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;write-host "validation cube : ", $cube.name</span><br /><span style="font-family: courier new,courier;">&nbsp;$cube.validate($val, 4)</span><br /><span style="font-family: courier new,courier;">&nbsp;foreach ($mg in $cube.measuregroups)</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;{</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;write-host "validation measuregroup : ", $mg.name</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;$mg.validate($val, 4)</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;foreach ($partition in $mg.partitions)</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;{</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;write-host "validation partition : ", $partition.name</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$partition.validate($val, 4)</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;}</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;}</span><br /><span style="font-family: courier new,courier;">&nbsp;}</span></p>
<p><span style="font-family: courier new,courier;">$val | select source, sourcePath, sourceTYpe, description</span></p>
<p>&nbsp;Enjoy !</p>]]></content:encoded>
    </item>
    <item>
      <title>Update SQL Server Statistics with Powershell</title>
      <link>https://docs.microsoft.com/archive/blogs/olivier_pieri/update-sql-server-statistics-with-powershell</link>
      <pubDate>Tue, 29 Mar 2011 01:18:00 GMT</pubDate>
      <dc:creator><![CDATA[olivier pieri]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/olivier_pieri/2011/03/29/update-sql-server-statistics-with-powershell/</guid>
      <description><![CDATA[It can be usefull to have a script to update statistics with powershell.
this script is very...]]></description>
      <content:encoded><![CDATA[<p>It can be usefull to have a script to update statistics with powershell.</p>
<p>this script is very simple, you just have to connect to you database and call the <span style="font-family: courier new,courier;">updatestatistics</span>() method for all your tables :</p>
<p><span style="font-family: courier new,courier;">[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null</span></p>
<p><span style="font-family: courier new,courier;">&nbsp;$s = new-object ('Microsoft.sqlserver.Management.smo.server') myServer\myInstance</span></p>
<p><span style="font-family: courier new,courier;">&nbsp;$db = $s.databases["myDB"]</span></p>
<p><span style="font-family: courier new,courier;">&nbsp;foreach ($t in $db.tables)<br />&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; write-host "Update stat"&nbsp; $t.name<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $t.updatestatistics("all", "fullscan")<br />&nbsp;}</span></p>
<p>the first parameter is a statistics Target, possible value are described here : <a href="https://msdn.microsoft.com/fr-fr/library/microsoft.sqlserver.management.smo.statisticstarget.aspx">https://msdn.microsoft.com/fr-fr/library/microsoft.sqlserver.management.smo.statisticstarget.aspx</a></p>
<p>the second parameter is a Statistics scan type, possible value are describe here : <a href="https://msdn.microsoft.com/fr-fr/library/microsoft.sqlserver.management.smo.statisticsscantype.aspx">https://msdn.microsoft.com/fr-fr/library/microsoft.sqlserver.management.smo.statisticsscantype.aspx</a></p>
<p>If you want to update your statistics with giving a sample and not a full scan, the script become :</p>
<p><span style="font-family: courier new,courier;">[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null</span></p>
<p><span style="font-family: courier new,courier;">$s = new-object ('Microsoft.sqlserver.Management.smo.server') myServer\myInstance</span></p>
<p><span style="font-family: courier new,courier;">$db = $s.databases["myDB"]</span></p>
<p><span style="font-family: courier new,courier;">$sample = 50</span></p>
<p><span style="font-family: courier new,courier;">foreach ($t in $db.tables)<br />{<br />&nbsp;&nbsp;&nbsp; write-host "Update stat" $t.name<br />&nbsp;&nbsp;&nbsp; $t.updatestatistics("all", "percent", $sample)<br />}</span></p>
<p>Enjoy...</p>]]></content:encoded>
    </item>
    <item>
      <title>Rebuild SQL Server index with Powershell</title>
      <link>https://docs.microsoft.com/archive/blogs/olivier_pieri/rebuild-sql-server-index-with-powershell</link>
      <pubDate>Mon, 28 Mar 2011 02:40:00 GMT</pubDate>
      <dc:creator><![CDATA[olivier pieri]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/olivier_pieri/2011/03/28/rebuild-sql-server-index-with-powershell/</guid>
      <description><![CDATA[let continue to explore what we can achieve with powershell for SQL Server management.
The goal of...]]></description>
      <content:encoded><![CDATA[<p>let continue to explore what we can achieve with powershell for SQL Server management.</p>
<p>The goal of this post is to rebuild fragmented index with power shell.</p>
<p>To achieve that we need to use the <span style="font-family: courier new,courier;">invoke-sqlcmd </span>cmdlet.</p>
<p>try to use this command, if it doesn't work, be sure to have all the system module loaded, if not, run the <span style="font-family: courier new,courier;">importSystemModules </span>cmdlet.</p>
<p>the query that we are going to use to know if indexes are fragmented or not is :</p>
<p style="FONT-FAMILY: "><span style="font-family: courier new,courier;">Select&nbsp;&nbsp; i.name as index_name,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;object_name(s.object_id) as table_name,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.avg_fragmentation_in_percent,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.page_count <br />from&nbsp;&nbsp;&nbsp;&nbsp; sys.dm_db_index_physical_stats(db_id(), null, null, null, null) s,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sys.indexes i<br />where&nbsp;&nbsp;&nbsp; i.object_id = s.object_id <br />and&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i.index_id = s.index_id <br />and&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i.name is not null</span></p>
<p>to run this query from powershell, just put the query in a variable ($indexList) and use the <span style="font-family: courier new,courier;">invoke-sqlcmd </span>cmdlet like :</p>
<p>&nbsp;<span style="font-family: courier new,courier;">invoke-sqlcmd -ServerInstance "myServer\myInstance" -database "myDB" -query $indexlist</span></p>
<p>you can put the result of this query in a powershell variable :</p>
<p style="FONT-FAMILY: "><span style="font-family: courier new,courier;">$listObject = invoke-sqlcmd -ServerInstance "opieri02\R2" -database "AdventureworksDW2008R2" -query $indexlist</span></p>
<p>after you just have to test if an index is fragmented or not (here, we consider an index as fragmented if it have more than 1000 pages and if the fragmentation is more than 10%)</p>
<p>to achieve this test we are going to use smo object.</p>
<p>1) load the smo assemby :<br /><span style="font-family: courier new,courier;">[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")</span></p>
<p>2) connect to your instance :<br /><span style="font-family: courier new,courier;">$server = New-Object('Microsoft.SqlServer.Management.Smo.Server') myServer\myInstance</span></p>
<p>3) for each index that you have retreive, instanciate an smo index :<br /><span style="font-family: courier new,courier;">$index = $Server.databases["myDB"].Tables[$i.table_name].Indexes[$i.index_name]</span></p>
<p>&nbsp;The complete script is :</p>
<p>$<span style="font-family: courier new,courier;">indexlist = "<br />Select i.name as index_name, object_name(s.object_id) as table_name,<br />s.avg_fragmentation_in_percent, s.page_count from sys.dm_db_index_physical_stats(db_id(), null, null, null, null) s,<br />sys.indexes i<br />where i.object_id = s.object_id and i.index_id = s.index_id and i.name is not null"</span></p>
<p><br /><span style="font-family: courier new,courier;">$listObject = invoke-sqlcmd -ServerInstance "myServer\myInstance" -database "myDB" -query $indexlist</span></p>
<p><span style="font-family: courier new,courier;">[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")</span></p>
<p><span style="font-family: courier new,courier;">$server = New-Object('Microsoft.SqlServer.Management.Smo.Server') myServer\myInstance</span></p>
<p><span style="font-family: courier new,courier;"></span><span style="font-family: courier new,courier;">foreach ($i in $listObject)<br />{<br />&nbsp;$index = $Server.databases["myDB"].Tables[$i.table_name].Indexes[$i.index_name]<br />&nbsp;if ($i.avg_fragmentation_in_percent -gt 10 -and $i.page_count -gt 1000)<br />&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;Write-Host -BackgroundColor Red "Table : " $i.table_name " Index :" $i.index_name " is Fragmented = &gt; Rebuild"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;$index.Rebuild()<br />&nbsp;&nbsp;}<br />&nbsp;else<br />&nbsp;&nbsp;{<br />&nbsp;&nbsp;Write-Host "Table : " $i.table_name " Index :" $i.index_name " is not Fragmented"<br />&nbsp;&nbsp;}</span></p>
<p><span style="font-family: courier new,courier;">}<br /></span></p>
<p>&nbsp;</p>
<p>Enjoy !!!</p>
<p>&nbsp;</p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>SQL Server backup and powershell</title>
      <link>https://docs.microsoft.com/archive/blogs/olivier_pieri/sql-server-backup-and-powershell</link>
      <pubDate>Thu, 24 Mar 2011 03:56:00 GMT</pubDate>
      <dc:creator><![CDATA[olivier pieri]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/olivier_pieri/2011/03/24/sql-server-backup-and-powershell/</guid>
      <description><![CDATA[In my previous post, I give some basic sample on how to use powershell for SQL Server. Here we are...]]></description>
      <content:encoded><![CDATA[<p>In my previous post, I give some basic sample on how to use powershell for SQL Server. Here we are going to build a sample script to backup database.</p>
<p><strong><span style="font-size: small;">1)&nbsp; Perfom a full backup for a specified database :</span></strong></p>
<p><span style="font-family: Courier New; font-size: x-small;"><span class="style9"><span style="font-weight: 400;">[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null<br />$s = New-Object ('Microsoft.SqlServer.Management.Smo.Server') "myServer\myInstance" </span></span></span></p>
<p><span style="font-family: Courier New; font-size: x-small;"><span class="style9"><span style="font-weight: 400;">#Create a Backup object instance with the Microsoft.SqlServer.Management.Smo.Backup namespace <br />$dbBackup = new-object ("Microsoft.SqlServer.Management.Smo.Backup") </span></span></span></p>
<p><span style="font-family: Courier New; font-size: x-small;"><span class="style9"><span style="font-weight: 400;">#Set the Database property to myDB<br />$dbBackup.Database = "myDB" </span></span></span></p>
<p><span style="font-family: Courier New; font-size: x-small;"><span class="style9"><span style="font-weight: 400;">#Add the backup file to the Devices collection and specify File as the backup type <br />$dbBackup.Devices.AddDevice("C:\backups\myDB_FULL.bak", "File")</span></span></span></p>
<p><span style="font-family: Courier New; font-size: x-small;"><span class="style9"><span style="font-weight: 400;">#Specify the Action property to generate a FULL backup <br />$dbBackup.Action="Database"</span></span></span></p>
<p><span style="font-family: Courier New; font-size: x-small;"><span class="style9"><span style="font-weight: 400;">#Call the SqlBackup method to generate the backup <br />$dbBackup.SqlBackup($s)</span></span></span></p>
<p><span style="font-size: x-small;"><span class="style9"><span style="font-weight: 400;"><strong><span style="font-size: small;">2) Perfom a full backup for all databases :</span></strong></span></span></span></p>
<p><span style="font-size: x-small;"><span class="style9"><span style="font-weight: 400;">
<p><span style="font-family: Courier New; font-size: x-small;"><span class="style9"><span style="font-weight: 400;">[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | out-null<br />$s = new-object ("Microsoft.SqlServer.Management.Smo.Server") "myServer\myInstance"</span></span></span></p>
<p>
<p><span style="font-family: Courier New; font-size: x-small;"><span class="style9"><span style="font-weight: 400;">$bkdir = "D:\backups" <br />$dbs = $s.Databases<br />foreach ($db in $dbs) <br />{<br />if($db.Name -ne "tempdb") #We don't want to backup the tempdb database <br />{<br />$dbname = $db.Name<br />$dt = get-date -format yyyyMMddHHmm <br />$dbBackup = new-object ("Microsoft.SqlServer.Management.Smo.Backup")<br />$dbBackup.Action = "Database"<br />$dbBackup.Database = $dbname<br />$dbBackup.Devices.AddDevice($bkdir + "\" + $dbname + "_db_" + $dt + ".bak", "File")<br />$dbBackup.SqlBackup($s)<br />}<br />}</span></span></span></p>
</p>
</span></span></span></p>
<p><strong><span style="font-size: small;">3) Perform a transaction log backup for all databases :</span></strong></p>
<p><span style="font-family: Courier New; font-size: x-small;"><span class="style9"><span style="font-weight: 400;">[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | out-null<br />$s = new-object ("Microsoft.SqlServer.Management.Smo.Server") "myServer\myInstance"</span></span></span></p>
<p><span style="font-family: Courier New; font-size: x-small;"><span class="style9"><span style="font-weight: 400;"></span></span></span><span style="font-family: Courier New; font-size: x-small;">
<p><span class="style9"><span style="font-weight: 400;">$bkdir = "D:\backups" <br />$dbs = $s.Databases<br />foreach ($db in $dbs) <br />{</span></span></p>
<p><span class="style9"><span style="font-weight: 400;">if($db.RecoveryModel -ne 3) #Don't do Log backups for DBs with RecoveryModel=3 or SIMPLE <br />{<br />$dbname = $db.Name<br />$dt = get-date -format yyyyMMddHHmm <br />$dbBackup = new-object ("Microsoft.SqlServer.Management.Smo.Backup")<br />$dbBackup.Action = "Log"<br />$dbBackup.Database = $dbname<br />$dbBackup.Devices.AddDevice($bkdir + "\" + $dbname + "_log_" + $dt + ".trn", "File")<br />$dbBackup.SqlBackup($s)<br />} </span></span></p>
<p><span class="style9"><span style="font-weight: 400;">}</span></span></p>
<p><span class="style9"><span style="font-weight: 400;"></span></span></p>
</span></p>
<p><strong><span style="font-size: small;">&nbsp;</span></strong><span class="style9"><span style="font-weight: 400;">&nbsp;</span></span></p>
<p><span style="font-size: small;"><strong><span lang="EN-US" style="font-family: 'Arial','sans-serif'; color: black; mso-ansi-language: EN-US;">4) monitoring backup</span><span></span></strong><span lang="EN-US" style="font-family: 'Arial','sans-serif'; color: black; font-size: 9pt; mso-ansi-language: EN-US;"><o:p></o:p></span></span></p>
<p><span lang="EN-US" style="font-family: 'Arial','sans-serif'; color: black; font-size: 9pt; mso-ansi-language: EN-US;">the following script give info about the last databases backup<o:p></o:p></span></p>
<p><span><span lang="EN-US" style="font-family: 'Courier New'; color: black; font-size: 10pt; mso-ansi-language: EN-US;">[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null<br />$s = New-Object ('Microsoft.SqlServer.Management.Smo.Server') "MyServer\MyInstance" </span></span><span lang="EN-US" style="font-family: 'Arial','sans-serif'; color: black; font-size: 9pt; mso-ansi-language: EN-US;"><o:p></o:p></span></p>
<p><span><span lang="EN-US" style="font-family: 'Courier New'; color: black; font-size: 10pt; mso-ansi-language: EN-US;">$dbs=$s.Databases<br /><br />$dbs | SELECT Name,LastBackupDate, LastLogBackupDate | Format-Table -autosize </span></span><span lang="EN-US" style="font-family: 'Arial','sans-serif'; color: black; font-size: 9pt; mso-ansi-language: EN-US;"><o:p></o:p></span></p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>SQL Server and powershell</title>
      <link>https://docs.microsoft.com/archive/blogs/olivier_pieri/sql-server-and-powershell</link>
      <pubDate>Thu, 24 Mar 2011 01:58:00 GMT</pubDate>
      <dc:creator><![CDATA[olivier pieri]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/olivier_pieri/2011/03/24/sql-server-and-powershell/</guid>
      <description><![CDATA[Here is some sample of what you can achieve to manager SQL Server with powershell, let start with...]]></description>
      <content:encoded><![CDATA[<p>Here is some sample of what you can achieve to manager SQL Server with powershell, let start with system script :</p>
<p><span style="font-size: small;"><strong>1) is the SQL Service running ?</strong></span></p>
<p><span style="font-family: courier new,courier;">Get-WmiObject win32_service | Where-Object {$_.name -match "^*SQL*"} | select SystemName, Name, StartName, State</span></p>
<p><strong><span style="font-size: small;">2) how the process run ?</span></strong></p>
<p><span style="font-family: courier new,courier;">get-wmiobject win32_process | where {$_.name -like "*sql*"} | select name, workingsetsize, threadcount</span></p>
<p><span style="font-size: small;"><strong>3) Is there info about SQL Server in the event log ?</strong></span></p>
<p><span style="font-family: courier new,courier;">get-eventlog -logname application -newest 1000 | where-object {($_.source -eq "MSSQL`$R2") -and ($_.EntryType -eq "Error")}</span></p>
<p>&nbsp;</p>
<p>Now, if we want info about SQL Server, we have to connect to SQL server, to do that, we must first load the SMO assembly</p>
<p><span style="font-family: courier new,courier;">[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")</span></p>
<p>and make a connection to a specific SQL Server instance :</p>
<p><span style="font-family: courier new,courier;">$server = New-Object('Microsoft.SqlServer.Management.Smo.Server') myserver\myinstance</span></p>
<p><span style="font-size: small;"><strong>&nbsp;4) SQL Server instance information :</strong></span></p>
<p><br /><span style="font-family: courier new,courier;">$server | select Edition, Version, ProductLevel, Collation, PhysicalMemory, Processors<br />$server.Configuration.get_AweEnabled()</span></p>
<p><strong><span style="font-size: small;">5) Processes Info (sp_who):</span></strong></p>
<p><span style="font-size: x-small;"><span style="font-family: courier new,courier;"><span style="font-size: xx-small;">$server.EnumProcesses() | where-object {$_.IsSystem -eq $false} | select Spid, Login, Host, Status, Command, database, Cpu, memusage, BlockingSpid | Format-Table</span></span></span></p>
<p><strong><span style="font-size: small;">6) databases information :</span></strong></p>
<p><span style="font-family: courier new,courier;">$server.Databases | select name, collation, size</span></p>
<p>To go in a specific database :</p>
<p><span style="font-family: courier new,courier;">$db = $server.databases["DatabaseName"]</span></p>
<p>and to show all the info about this database :</p>
<p><span style="font-family: courier new,courier;">$db</span></p>
<p><span style="font-size: small;"><strong>7) Tables information :</strong></span></p>
<p><span style="font-family: courier new,courier;">foreach ($t in $db.Tables)<br />{<br />write-host $t.name, $t.RowCount, $t.DataSpaceUsed, $IndexSpaceUsed<br />}</span></p>
<p><span style="font-size: small;"><strong>8) Tables with clustered index :</strong></span></p>
<p>foreach ($t in $db.Tables)<br />{ <br />&nbsp;if ($t.HasClusteredIndex -eq $false)<br />&nbsp;&nbsp;{ <br />&nbsp;&nbsp;write-host $t.name<br />&nbsp;}<br />}</p>
<p><strong><span style="font-size: small;">9) script an object</span></strong></p>
<p>you can generate the object's SQL Script (in this example, a table, but it work for all SQL Server object, stored proc etc...)</p>
<p><span style="font-family: courier new,courier;">$db.Tables["tableName"].script()</span></p>
<p><span style="font-size: small;"><strong>10) Detach/attach a database :</strong></span></p>
<p><span style="font-family: courier new,courier;">#Detach :</span></p>
<p><span style="font-family: courier new,courier;">$server.DetachDatabase("Mydatabase", $false)</span></p>
<p><span style="font-family: courier new,courier;">#Attach<br />$sc = new-object System.Collections.Specialized.StringCollection<br />$sc.Add("C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\Mydatabase.mdf")<br />$server.AttachDatabase("myDataBase", $sc)</span></p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>Analysis Services and powershell</title>
      <link>https://docs.microsoft.com/archive/blogs/olivier_pieri/analysis-services-and-powershell</link>
      <pubDate>Wed, 26 Jan 2011 02:33:00 GMT</pubDate>
      <dc:creator><![CDATA[olivier pieri]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/olivier_pieri/2011/01/26/analysis-services-and-powershell/</guid>
      <description><![CDATA[It is usefull to be able to see analysis services configuration and browsing cube structure with...]]></description>
      <content:encoded><![CDATA[<p>It is usefull to be able to see analysis services configuration and browsing cube structure with powershell.</p>
<p>to achieve that, you first need to load the AMO assembly in Powershell :</p>
<p><span style="font-family: courier new,courier;"><span style="color: #0000ff;">[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices")</span></span></p>
<p>And then create a server object :</p>
<p><span style="font-family: courier new,courier;"><span style="color: #0000ff;">$serverAS = New-Object Microsoft.AnalysisServices.Server</span></span></p>
<p>And connect to your Analysis Services server :</p>
<p><span style="font-family: courier new,courier;"><span style="color: #0000ff;">$serverAS.connect("OPIERI02\R2")</span></span></p>
<p>&nbsp;Now, you can easily query your Analysis Services to know how it is configured :</p>
<p><span style="font-family: courier new,courier;"><span style="color: #0000ff;">$serverAS.serverproperties | select Name, Value</span></span></p>
<p>Or to know the list of databases that are stored on this Analysis Services Instance :</p>
<p><span style="font-family: courier new,courier;"><span style="color: #0000ff;">$serverAS.databases | select Name, EstimatedSize, StorageMode, LastProcessed</span></span></p>
<p>If, for a database, you want to have some information about the cube :</p>
<p><span style="font-family: courier new,courier;"><span style="color: #0000ff;">$db = $server.databases["MyDB"]</span></span></p>
<p><span style="font-family: courier new,courier;"><span style="color: #0000ff;">$db.cubes | select name, storagemode, lastprocessed</span></span></p>
<p>if, for the same database, you want info about dimensions</p>
<p><span style="font-family: courier new,courier;"><span style="color: #0000ff;">$db.dimensions | select name, isparentchild, lastprocessed, storagemode</span></span></p>
<p>&nbsp;If you want to see information about measure group in your database, you have to browse the cube collection as follow :</p>
<p><span style="font-family: courier new,courier;"><span style="color: #0000ff;">foreach ($c in $db.cubes) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; write-host $c.Name<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach ($mg in $c.measuregroups) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; write-host $mg.name, $mg.estimatedsize, $mg.lastprocessed<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />}</span></span></p>
<p>You want to know if proactive cache is enable for partition ?</p>
<p><span style="font-family: courier new,courier;"><span style="color: #0000ff;">$cube = $db.cubes[&ldquo;myCube&rdquo;]<br />$mg = $cube.MeasureGroups[&ldquo;myMG&rdquo;]<br />Foreach ($p in $mg.partitions) { Write-host $p.Name, $p.estimatedSize, $p.proactivecaching.enabled}</span></span></p>
<p>To process all the cube for a database :</p>
<p><span style="font-family: courier new,courier;"><span style="color: #0000ff;">Foreach ($c in $db.cubes)&nbsp; {$c.process("ProcessFull")}</span></span></p>
<p>and to process all dimensions :</p>
<p><span style="font-family: courier new,courier;"><span style="color: #0000ff;">Foreach ($d in $db.dimensions) {$d.process("ProcessFull")}</span></span></p>
<p>And you can also backup an analysis services &nbsp;database&nbsp;with powershell:</p>
<p><span style="font-family: courier new,courier;"><span style="color: #0000ff;">$db.backup("myBackup.abf")</span></span></p>
<p>Enjoy !</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>Usefull DMV Query</title>
      <link>https://docs.microsoft.com/archive/blogs/olivier_pieri/usefull-dmv-query</link>
      <pubDate>Fri, 14 Jan 2011 00:57:00 GMT</pubDate>
      <dc:creator><![CDATA[olivier pieri]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/olivier_pieri/2011/01/14/usefull-dmv-query/</guid>
      <description><![CDATA[What are DMV : (Dynamic Management View)

View of internals informations.
DMV are basically SQL...]]></description>
      <content:encoded><![CDATA[<p>What are DMV : (Dynamic Management View)</p>
<ul>
<li>View of internals informations.</li>
<li>DMV are basically SQL Views on some pretty important internal memory structures.</li>
<li>DMV informations include metrics about : 
<ul>
<li>indexes</li>
<li>query execution</li>
<li>operating system</li>
<li>Transaction</li>
<li>Databases</li>
<li>and much more</li>
</ul>
</li>
</ul>
<p>What are DMF : (Dynamic Management Function)</p>
<p>As an example <strong><em>sys.dm_exec_query_stats</em></strong> records details of the SQL being processed via variable called <strong><em>sql_handle</em></strong>.</p>
<p>If this <strong><em>sql_handle</em></strong> is passed as a parameter to the DMF <strong><em>sys.dm_exec_sql_text</em></strong>, the DMF will return the actual SQL Text&nbsp; associated with this <strong><em>sql_handle</em></strong>.</p>
<p>&nbsp;</p>
<p><span style="font-size: medium;"><strong><em><span style="color: #0000ff;">Find a cache plan :</span></em></strong></span></p>
<p><span style="font-family: courier new,courier;">Select&nbsp;&nbsp; st.Text as [SQL],<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cp.cacheobjtype,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cp, objtype,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;COASLESCE (Cast(pa.value, INT)), 'Resource' as [DatabaseName],<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cp.usecounts as [Plan Usage],<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;qp.query_plan<br />From&nbsp;&nbsp;&nbsp;&nbsp; sys.dm_exec_cached_plan cp<br />CROSS APPLY sys.dm_exec_sql_text (cp.plan_handle) st<br />CROSS APPLY sys.dm_exec_query_plan (cp.plan_handle) qp<br />OUTER APPLY sys.dm_exec_plan_attributes (cp.plan_handle) pa<br />Where&nbsp;&nbsp; pa.attribute = 'dbid'</span></p>
<p>&nbsp;</p>
<p><span style="color: #0000ff;"><span style="font-size: medium;"><strong><em>Most Expensive Query :</em></strong></span></span></p>
<p><span style="font-family: courier new,courier;">Select&nbsp;&nbsp;&nbsp;&nbsp; Cast(Total_elapsed_time / 1000000.0 as decimal(28,2)) as [Total Duration (s)],<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Cast(Total_Worker_Time * 100.0 / Total_Elapsed_Time as decimal(28, 2)) as [% CPU],<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Cast ((total_elapsed_time - total_worker_time) * 100.0 / total_elapsed_time&nbsp; as decimal(28,2)) as [%&nbsp; Waiting],<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; execution_count,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Cast (Total_elapsed_time / 1000000.0 / execution_count as decimal(28,2)) as [average duration (s)],<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Substring (qt.text, (qs.statement_start_offset / 2) + 1, ((<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case When qs.statement_end_offset = -1<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Then len(convert(Nvarchar(Max), qt.text)) * 2<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else qs.statement_end_offset<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End - qs.statement_start_offset) / 2 ) + 1) as [Individual Query]<br />From&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sys.dm_exec_query_stats qs<br />CROSS APPLY&nbsp; sys.dm_exec_sql_text (qs.sql_handle) as qt<br />CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) qp<br />INNER JOIN sys.dm_exec_cached_plans as cp<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ON qs.plan_handle = cp.plan_handle<br />Where&nbsp;&nbsp;&nbsp;&nbsp; Total_elapsed_Time &lt;&gt; 0<br />and&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Execution_count &lt;&gt; 0<br />Order By&nbsp; total_elapsed_time DESC</span></p>
<p>&nbsp;</p>
<p>&nbsp;<span style="color: #0000ff;"><span style="font-size: medium;"><strong><em>Missing Index :</em></strong></span></span></p>
<p><span style="font-family: courier new,courier;">&nbsp;</span><span style="color: #000000;"><span style="font-family: courier new,courier;">Select&nbsp;&nbsp;&nbsp; Round (avg_total_user_cost * avg_user_impact * (user_seeks + user_scans), 0) as [Total Cost],<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;statement as [Table Name],<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; equality_columns<br />From&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sys.dm_db_missing_index_groups g<br />INNER JOIN sys.dm_db_missing_index_group_stats s on s.group_handle = g.index_group_handle<br />INNER JOIN sys.dm_db_missing_index_details d on d.index_handle = g.index_handle</span></span></p>
<p>&nbsp;</p>
<p><span style="color: #0000ff;"><span style="font-size: medium;"><strong><em>Why are you waiting ?</em></strong></span></span></p>
<p><span style="font-family: courier new,courier;">Select&nbsp; Wait_type, wait_time_ms, signal_wait_time_ms, wait_time_ms -signal_wait_time_ms as RealWait,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; convert(Decimal(12, 2), (wait_time_ms - signal_wait_time_ms) * 100.0 / sum(wait_time_ms) over()) as [% RealWait]<br />From&nbsp;&nbsp; sys.dm_os_wait_stats<br />Where Wait_type like '%SLEEP%'<br />And&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wait_type != 'WAITFOR'<br />Order by wait_time_ms DESC</span></p>
<p>&nbsp;</p>
<p><span style="color: #0000ff;"><strong><em><span style="font-size: medium;">What is blocked ?</span></em></strong></span></p>
<p><span style="font-family: courier new,courier;">Select&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Blocking.Session_id as BlockingSessionId,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sess.login_name as BlockingUser,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BlockingSQL.Text as BlockingSQL,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Waits.wait_type as WhyBlocked,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Blocked.Session_id as BlockedSessionId,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;USER_NAME(Blocked.user_id) as BlockedUser,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BlockedSQL.text as BlockedSQL,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DB_NAME(Blocked.database_id) as DatabaseName<br />From&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sys.dm_exec_connections as Blocking<br />INNER JOIN sys.dm_exec_requests as Blocked<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ON Blocking.session_id = blocked.blocking_sessionid<br />INNER JOIN sys.dm_os_waiting_task as waits<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ON Blocked.session_id = Waits.session_id<br />RIGHT OUTER JOIN sys.dm_exec_sessions Sess<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ON Blocking.session_id = sess.session_id<br />CROSS APPLY sys.dm_exec_sql_text (Blocking.most_recent_sql_handle) as Blocking SQL<br />CROSS APPLY sys.dm_exec_sql_text (Blocked.sql_handle) as BlockedSQL</span></p>
<p>&nbsp;</p>
<p><span style="font-size: medium;"><span style="color: #0000ff;"><strong><em>What Fill the log ?</em></strong></span></span></p>
<p><span style="font-family: courier new,courier;">&nbsp;Select db.name as [Database Name],<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;db.recovery_model_desc as [Recovery Model],<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;db.log_reuse_wait_desc as [Log reuse Wait Description],<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ls.cntr_value as [Log Size (KB)],<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lu.cntr_value as [log Used (KB)],<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CAST ( CAST(lu.cntr_value as float) / CAST(ls.cntr_value as float) as DECIMAL (18,2)) * 100 as [Log Used %],<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;db.Compatibility_level as [DB Compatibility Level],<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;db.page_verify_option_desc as [Page Verify_Option]<br />From&nbsp;&nbsp;&nbsp; sys.databases as db<br />INNER JOIN sys.dm_os_performance_counters as lu on db.name = lu.instance_name<br />INNER JOIN sys.dm_os_performance_counters as ls on db.name = ls.instance_name<br />Where lu.counter_name like 'Log File(s) Used Size (KB)%'<br />And ls.counter_name like 'Log File(s) Size (KB)%'</span></p>
<p>&nbsp;</p>
<p><span style="font-size: medium;"><span style="color: #0000ff;"><strong><em>System Information :</em></strong></span></span></p>
<p><span style="font-family: courier new,courier;">Select&nbsp; cpu_count as [Logical CPU Count],<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hyperthread_ratio as [ Hyperthread Ratio],<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cpu_count /hyperthread_ratio as [Physical CPU Count],<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; physical_memory_in_bytes / 1048576 as [Physical Memory (MB)]<br />From&nbsp;&nbsp;&nbsp; sys.dm_os_sys_info</span></p>
<p>&nbsp;</p>
<p><span style="color: #0000ff;"><span style="font-size: medium;"><strong><em>Monitor Scheduler info :</em></strong></span></span></p>
<p><br /><span style="font-family: courier new,courier;">SELECT&nbsp; AVG(current_tasks_count) AS [Avg Task Count] ,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AVG(runnable_tasks_count) AS [Avg Runnable Task Count]<br />FROM&nbsp;&nbsp;&nbsp; sys.dm_os_schedulers<br />WHERE&nbsp;&nbsp; scheduler_id &lt; 255<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AND [status] = 'VISIBLE ONLINE' <br /></span></p>
<p><span style="color: #0000ff;"><span style="font-size: medium;"><strong><em>Monitor Memory :</em></strong></span></span></p>
<p><span style="font-family: courier new,courier;">SELECT&nbsp; total_physical_memory_kb ,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; available_physical_memory_kb ,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; total_page_file_kb ,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; available_page_file_kb ,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; system_memory_state_desc<br />FROM&nbsp;&nbsp;&nbsp; sys.dm_os_sys_memory<br /></span></p>
<p><span style="font-family: courier new,courier;">SELECT&nbsp; physical_memory_in_use_kb ,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; locked_page_allocations_kb ,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; page_fault_count ,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; memory_utilization_percentage ,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; available_commit_limit_kb ,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; process_physical_memory_low ,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; process_virtual_memory_low<br />FROM&nbsp;&nbsp;&nbsp; sys.dm_os_process_memory<br /></span></p>
<p><span style="font-family: courier new,courier;">SELECT&nbsp; OBJECT_NAME(p.[object_id]) AS [ObjectName] ,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p.index_id ,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; COUNT(*) / 128 AS [Buffer size(MB)] ,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; COUNT(*) AS [Buffer_count]<br />FROM&nbsp;&nbsp;&nbsp; sys.allocation_units AS a<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; INNER JOIN sys.dm_os_buffer_descriptors<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AS b ON a.allocation_unit_id = b.allocation_unit_id<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; INNER JOIN sys.partitions AS p ON a.container_id = p.hobt_id<br />WHERE&nbsp;&nbsp; b.database_id = DB_ID()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AND p.[object_id] &gt; 100 <br />GROUP BY p.[object_id] ,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p.index_id<br />ORDER BY buffer_count DESC</span></p>]]></content:encoded>
    </item>
    <item>
      <title>Run SSIS Package programatically</title>
      <link>https://docs.microsoft.com/archive/blogs/olivier_pieri/run-ssis-package-programatically</link>
      <pubDate>Thu, 10 May 2007 03:08:00 GMT</pubDate>
      <dc:creator><![CDATA[olivier pieri]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/olivier_pieri/2007/05/10/run-ssis-package-programatically/</guid>
      <description><![CDATA[here is a small sample that show how to run an existing package from a .Net program.
This sample...]]></description>
      <content:encoded><![CDATA[<P>here is a small sample that show how to run an existing package from a .Net program.</P>
<P>This sample show how to replace target and source connection string and give a value to a package variable.</P>
<P>It show too how to register package event.</P><FONT color=#0000ff size=2>
<P>using</FONT><FONT size=2> Runtime = Microsoft.SqlServer.Dts.Runtime;</FONT></P><FONT size=2><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>private</FONT><FONT size=2> </FONT><FONT color=#2b91af size=2>PackageEvents</FONT><FONT size=2> packageEvents;</P>
<P></FONT><FONT color=#0000ff size=2>public</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>event</FONT><FONT size=2> </FONT><FONT color=#2b91af size=2>PackageEventEventHandler</FONT><FONT size=2> packageEvent = </FONT><FONT color=#0000ff size=2>null</FONT><FONT size=2>;</P>
<P></FONT><FONT color=#0000ff size=2>public</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>event</FONT><FONT size=2> </FONT><FONT color=#2b91af size=2>PackageProgressEventHandler</FONT><FONT size=2> packageProgress = </FONT><FONT color=#0000ff size=2>null</FONT><FONT size=2>;</P>
<P></FONT><FONT size=2>&nbsp;</P>
<P>packageEvents = </FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> </FONT><FONT color=#2b91af size=2>PackageEvents</FONT><FONT size=2>();</P>
<P>packageEvents.packageEvent += </FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> </FONT><FONT color=#2b91af size=2>PackageEventEventHandler</FONT><FONT size=2>(packageEvents_packageEvent);</P>
<P>packageEvents.packageProgress += </FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> </FONT><FONT color=#2b91af size=2>PackageProgressEventHandler</FONT><FONT size=2>(packageEvents_packageProgress);</FONT></P>
<P><FONT size=2></FONT>&nbsp;</P><FONT size=2><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>public</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>bool</FONT><FONT size=2> Execute(</FONT><FONT color=#0000ff size=2>string</FONT><FONT size=2> packagePath, </FONT><FONT color=#0000ff size=2>string</FONT><FONT size=2> sourceConnectionString, </FONT><FONT color=#0000ff size=2>string</FONT><FONT size=2> targetConnectionString, </FONT><FONT color=#0000ff size=2>string</FONT><FONT size=2> packageVariable)</P>
<P>{</P>
<P>Runtime.</FONT><FONT color=#2b91af size=2>Application</FONT><FONT size=2> app = </FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> Runtime.</FONT><FONT color=#2b91af size=2>Application</FONT><FONT size=2>();</P>
<P>Runtime.</FONT><FONT color=#2b91af size=2>Package</FONT><FONT size=2> package = app.LoadPackage(packagePath, </FONT><FONT color=#0000ff size=2>null</FONT><FONT size=2>);</P>
<P>package.InteractiveMode = </FONT><FONT color=#0000ff size=2>false</FONT><FONT size=2>;</FONT></P>
<P><FONT size=2>// Target is the name of the target connection in the SSIS package</P></FONT><FONT size=2>
<P>package.Connections[</FONT><FONT color=#a31515 size=2>"Target</FONT><FONT color=#a31515 size=2>"</FONT><FONT size=2>].ConnectionString = targetConnectionString;</P></FONT><FONT size=2>
<P>package.Connections[</FONT><FONT color=#a31515 size=2>"Source"</FONT><FONT size=2>].ConnectionString = sourceConnectionString;</P>
<P></FONT><FONT color=#008000 size=2>// The package have a variable, we give it the value</P></FONT><FONT size=2>
<P>package.Variables[</FONT><FONT color=#a31515 size=2>"myVar"</FONT><FONT size=2>].Value = packageVariable;</P>
<P>Runtime.</FONT><FONT color=#2b91af size=2>DTSExecResult</FONT><FONT size=2> executionResult = package.Execute(</FONT><FONT color=#0000ff size=2>null</FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2>null</FONT><FONT size=2>, packageEvents, </FONT><FONT color=#0000ff size=2>null</FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2>null</FONT><FONT size=2>);</P>
<P></FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2> (executionResult == Microsoft.SqlServer.Dts.Runtime.</FONT><FONT color=#2b91af size=2>DTSExecResult</FONT><FONT size=2>.Failure)</P>
<P>{</P>
<P></FONT><FONT color=#0000ff size=2>return</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>false</FONT><FONT size=2>;</P>
<P>}</P>
<P></FONT><FONT color=#0000ff size=2>return</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>true</FONT><FONT size=2>;</P>
<P>}</P></FONT></FONT></FONT><FONT size=2><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>void</FONT><FONT size=2> packageEvents_packageProgress(</FONT><FONT color=#0000ff size=2>int</FONT><FONT size=2> percentComplete)</P>
<P>{</P>
<P></FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2> (packageProgress != </FONT><FONT color=#0000ff size=2>null</FONT><FONT size=2>)</P>
<P>packageProgress(percentComplete);</P>
<P>}</P>
<P></FONT><FONT color=#0000ff size=2>void</FONT><FONT size=2> packageEvents_packageEvent(</FONT><FONT color=#2b91af size=2>EventType</FONT><FONT size=2> type, </FONT><FONT color=#0000ff size=2>string</FONT><FONT size=2> message)</P>
<P>{</P>
<P></FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2> (packageEvent != </FONT><FONT color=#0000ff size=2>null</FONT><FONT size=2>)</P>
<P>packageEvent(type, message);</P>
<P>}</P></FONT></FONT>]]></content:encoded>
    </item>
    <item>
      <title>XMLA from the Command line</title>
      <link>https://docs.microsoft.com/archive/blogs/olivier_pieri/xmla-from-the-command-line</link>
      <pubDate>Wed, 23 Nov 2005 05:42:00 GMT</pubDate>
      <dc:creator><![CDATA[olivier pieri]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/olivier_pieri/2005/11/23/xmla-from-the-command-line/</guid>
      <description><![CDATA[I was very suprise to don't find a tool to execute XMLA Script from the command line. Then I have...]]></description>
      <content:encoded><![CDATA[<P>I was very suprise to don't find a tool to execute XMLA Script from the command line. Then I have decided to write it and it have been simple.</P>
<P>Let do it !</P>
<P>1) Use the useful namespace</P><FONT color=#0000ff size=2>
<P>using</FONT><FONT size=2> Microsoft.AnalysisServices.AdomdClient;</P></FONT><FONT color=#0000ff size=2>
<P>using</FONT><FONT size=2> System.Data;</P></FONT><FONT color=#0000ff size=2>
<P>using</FONT><FONT size=2> System.IO;</P></FONT><FONT color=#0000ff size=2>
<P>using</FONT><FONT size=2> System.Xml;</FONT></P>
<P><FONT size=2>&nbsp;</P></FONT>
<P>2) Start by connecting to Analysis Services 2005 using Adomd.</P><FONT size=2>
<P>strConnectionString = </FONT><FONT color=#800000 size=2>"Data Source="</FONT><FONT size=2> + ServerID + </FONT><FONT color=#800000 size=2>";"</FONT><FONT size=2>;</P>
<P></P>
<P>objConnection = </FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> </FONT><FONT color=#008080 size=2>AdomdConnection</FONT><FONT size=2>();</P>
<P>objConnection.ConnectionString = strConnectionString;</P>
<P>objConnection.Open();</P>
<P>&nbsp;</P>
<P><FONT size=3>3) And just execute the Command</FONT></P><FONT color=#008080 size=2>
<P>AdomdCommand</FONT><FONT size=2> objCommand;</P>
<P></FONT><FONT color=#008080 size=2>XmlReader</FONT><FONT size=2> objReader;</P>
<P></FONT><FONT color=#008080 size=2>FileStream</FONT><FONT size=2> objStream;</P>
<P></FONT><FONT color=#0000ff></FONT><FONT size=2>&nbsp;</P>
<P>objCommand = </FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> </FONT><FONT color=#008080 size=2>AdomdCommand</FONT><FONT size=2>();</P>
<P>objCommand.Connection = objConnection;</P>
<P>objStream = </FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> </FONT><FONT color=#008080 size=2>FileStream</FONT><FONT size=2>(objScript, System.IO.</FONT><FONT color=#008080 size=2>FileMode</FONT><FONT size=2>.Open, System.IO.</FONT><FONT color=#008080 size=2>FileAccess</FONT><FONT size=2>.Read, System.IO.</FONT><FONT color=#008080 size=2>FileShare</FONT><FONT size=2>.Read);</P>
<P>objCommand.CommandStream = objStream;</P>
<P>objReader = objCommand.ExecuteXmlReader();</P>
<P>objReader.MoveToContent();</P>
<P>objReader.Read ();</P>
<P></FONT><FONT color=#008080 size=2>Console</FONT><FONT size=2>.WriteLine (objReader.ReadInnerXml());</P></FONT>
<P><FONT size=3></FONT>&nbsp;</P>
<P><FONT size=3>That's All !</FONT></P></FONT>]]></content:encoded>
    </item>
  </channel>
</rss>