Skip to content

Commit e3c7959

Browse files
committed
Working on new Assignment
1 parent b83e5b3 commit e3c7959

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed
0 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
$instance = 'TUL1CIPCNPDB1';
2+
$excelPath = "C:\Temp\DataFileInfo__$instance.xlsx";
3+
$sqlQuery = @"
4+
EXEC tempdb..[usp_AnalyzeSpaceCapacity] @getLogInfo = 1;
5+
/*
6+
EXEC sp_msForEachDB '
7+
USE [?];
8+
SELECT DBName, O.*
9+
FROM ( VALUES (DB_NAME()) ) DBs (DBName)
10+
LEFT JOIN
11+
(
12+
SELECT OBJECT_NAME(ps.object_id) as TableName,
13+
i.name as IndexName,
14+
ps.index_type_desc,
15+
ps.page_count,
16+
ps.avg_fragmentation_in_percent,
17+
ps.forwarded_record_count
18+
FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL, NULL, ''DETAILED'') AS ps
19+
INNER JOIN sys.indexes AS i
20+
ON ps.OBJECT_ID = i.OBJECT_ID
21+
AND ps.index_id = i.index_id
22+
WHERE forwarded_record_count > 0
23+
) AS O
24+
ON 1 = 1
25+
'
26+
*/
27+
--exec sp_whoIsActive --@get_full_inner_text=1,@get_transaction_info=1, @get_task_info=2,@get_locks=1, @get_avg_time=1, @get_additional_info=1,@find_block_leaders=1,@get_plans=1
28+
"@;
29+
30+
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
31+
$SqlConnection.ConnectionString = "Server=$instance;Database=master;Integrated Security=True"
32+
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
33+
$SqlCmd.CommandText = $sqlQuery
34+
$SqlCmd.Connection = $SqlConnection
35+
$SqlCmd.CommandTimeout = 0
36+
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
37+
$SqlAdapter.SelectCommand = $SqlCmd
38+
$DataSet = New-Object System.Data.DataSet;
39+
$SqlAdapter.Fill($DataSet);
40+
$SqlConnection.Close();
41+
42+
$DataSet.Tables[0] | Export-Excel $excelPath -Show;

PowerShell Commands/PowerShell Commands.ssmssqlproj

+18
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,28 @@
1515
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
1616
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
1717
</ConnectionNode>
18+
<ConnectionNode Name="TUL1CIPCNPDB1:CORPORATE\adwivedi">
19+
<Created>2018-03-18T20:48:30.4705061+05:30</Created>
20+
<Type>SQL</Type>
21+
<Server>TUL1CIPCNPDB1</Server>
22+
<UserName />
23+
<Authentication>Windows Authentication</Authentication>
24+
<InitialDB>tempdb</InitialDB>
25+
<LoginTimeout>30</LoginTimeout>
26+
<ExecutionTimeout>0</ExecutionTimeout>
27+
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
28+
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
29+
</ConnectionNode>
1830
</Items>
1931
</LogicalFolder>
2032
<LogicalFolder Name="Queries" Type="0" Sorted="true">
2133
<Items>
34+
<FileNode Name="Get-SqlResult2Excel.sql">
35+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:TUL1CIPCNPDB1:True</AssociatedConnectionMoniker>
36+
<AssociatedConnSrvName>TUL1CIPCNPDB1</AssociatedConnSrvName>
37+
<AssociatedConnUserName />
38+
<FullPath>Get-SqlResult2Excel.sql</FullPath>
39+
</FileNode>
2240
<FileNode Name="QueryResults-2-Excel.sql">
2341
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:BAN-2ADWIVEDI-L:True</AssociatedConnectionMoniker>
2442
<AssociatedConnSrvName>BAN-2ADWIVEDI-L</AssociatedConnSrvName>

SpaceCapacity-Automation/v3.5 - Automation - Restrict File growth.sql

+15-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,22 @@ BEGIN
2828
/*
2929
Created By: Ajay Dwivedi
3030
Updated on: 18-Mar-2018
31-
Current Ver: 3.4 - a) Remove issues when multiple files are there with same logical names
31+
Current Ver: 3.5 - a) Remove issues when multiple files are there with same logical names
3232
b) **Add functionality to handle multiple comma separated @oldVolume names (This would be quite complex)**
33+
--@optimizeLogFiles -- Removes high VLF counts, and set good autogrowth settings
34+
--@releaseSpaceByShrinkingFiles -- Release free space from Data/Log files
35+
--@getVolumeSpaceConsumers -- Get All the files and Folder inside drive with their size, author
36+
$path = 'E:';
37+
Get-ChildItem -Path $path -Recurse -File |
38+
Select-Object Name,
39+
@{l='ParentPath';e={$_.DirectoryName}},
40+
@{l='SizeBytes';e={$_.Length}},
41+
@{l='Owner';e={((Get-ACL $_.FullName).Owner)}},
42+
CreationTime,
43+
LastAccessTime,
44+
LastWriteTime,
45+
@{l='IsFolder';e={if($_.PSIsContainer) {1} else {0}}} |
46+
foreach{ $_.Name + '|' + $_.ParentPath + '|' + $_.SizeBytes + '|' + $_.Owner + '|' + $_.CreationTime + '|' + $_.LastAccessTime + '|' + $_.LastWriteTime + '|' + $_.IsFolder }
3347
3448
Purpose: This procedure can be used to generate automatic TSQL code for working with ESCs like 'DBSEP2537- Data- Create and Restrict Database File Names' type.
3549
*/

0 commit comments

Comments
 (0)