search
Categories
Sponsors
VirtualMetric Hyper-V Monitoring, Hyper-V Reporting
Archive
Blogroll

Badges
MCSE
Community

Cozumpark Bilisim Portali
Posted in Windows Powershell | No Comment | 4,031 views | 29/01/2016 21:01

This is an example Mime Type script to show you how to get it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Create Content Type Map
$ContentTypeMap = @{
	".jpg"  = "image/jpeg";
	".jpeg" = "image/jpeg";
	".gif"  = "image/gif";
	".png"  = "image/png";
	".tiff" = "image/tiff";
	".zip"  = "application/zip";
	".json" = "application/json";
	".xml"  = "application/xml";
	".rar"  = "application/x-rar-compressed";
	".gzip" = "application/x-gzip";
}
 
$File = Get-ChildItem C:\YourFilePath.json
$FileMimeType = $ContentTypeMap[$File.Extension.ToLower()];
Write-Output $FileMimeType

You can get mime types from IIS.


Posted in Windows Powershell | No Comment | 1,273 views | 23/01/2016 17:38

You can use Test-Path to test if file is exist.

But you can also use [System.IO.File]::Exists() to check it fast.

1
[System.IO.File]::Exists("Your File Path")

You can use in if block to check it on one line:

1
2
3
4
if ([System.IO.File]::Exists("C:\setup.log"))
{
Write-Output "File Exist"
}

It will also use less memory.


Posted in Windows Powershell | No Comment | 1,918 views | 16/01/2016 15:20

You can simply check .NET Core status with following code:

1
2
3
4
5
# Check PSEdition
if ($PSVersionTable.PSEdition -eq "Core")
{
Write-Host "Core Edition";
}

You can check it on Nano server.


Posted in Windows Powershell | No Comment | 1,865 views | 10/01/2016 00:16

Bir değişkenin değerini, dosya içeriğinden aşağıdaki gibi okuyabilirsiniz.

${C:\deneme.txt}

Değişkene aşağıdaki gibi yazdığınızda ise dosya içeriği güncellenir.

${C:\deneme.txt} = "test"

Farklı PowerShell session’larına bu şekilde variable aktarılabilir.


Posted in Hosting & IIS7 | No Comment | 2,960 views | 01/12/2015 10:44

Cronjob’a günlük olarak tanımlayıp, 1 hafta önceki log dosyalarının otomatik ziplenerek silinmesini sağlayabilirsiniz.

IIS’in PowerShell Management Yönetim aracına ihtiyaç duyar. Kurulu değil ise Roles’den ekleyebilirsiniz. Fakat default olarak genelde kurulu olur.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
Import-Module WebAdministration
 
function ConvertTo-CompressedFile
{
	param([string]$ZipPath)
 
	# Get Files
	[string[]]$Files = $input.FullName;
 
	if ($Files -ne $Null)
	{
		# Load the assembly
		[System.Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem") | Out-Null
 
		# Check Zip Extension
		if ($ZipPath -notlike "*.zip")
		{
			Write-Output "Please check your zip file path."
			break;
		}
 
		# Check Zip Path
		if(-not (Test-Path($ZipPath)))
		{
			# Get Zip File Name
			$ZipName = $ZipPath.Split("\")[-1]
 
			if ($ZipPath -notlike "*\*")
			{						
				# Get Current Location
				$CurrentLocation = (Get-Location).Path
 
				# Get Current Zip File Path
				$CurrentZipPath = $CurrentLocation + "\" + $ZipName
 
				# Update Zip Path
				$ZipPath = $CurrentZipPath;
			}
 
			# Create Zip File
			Set-Content $ZipPath ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
 
			# Set File Attributes
			(Get-ChildItem $ZipPath).IsReadOnly = $false
		}
 
		# Get Zip File
		$ZipFile = [System.IO.Compression.ZipFile]::Open($ZipPath,"Update")
 
		foreach($File in $Files)
		{
			# Get File Name
			$FileName = $File.Split("\")[-1]
 
			# Compress File
			[System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($ZipFile,$File,$FileName,"optimal") | Out-Null
 
			# Buffer
			Start-Sleep -milliseconds 5
		}
 
		# Close Zip File
		$ZipFile.Dispose()
 
		# Output Zip Path
		$ZipPath
	}
}
 
# Get Web Sites
$WebSites = Get-Website | Select Name, Id, LogFile
 
foreach ($WebSite in $WebSites)
{
	# Clear Variables
	$LogFiles = $Null;
	$LogFilePath = $Null;
 
	# Get Web Site Information
	$SiteName = $WebSite.Name
	$SiteID = $WebSite.Id
 
	# Get Web Site Log Path
	$LogDirectory = $WebSite.LogFile.Directory -Replace '%SystemDrive%', $env:SystemDrive
	$LogPath = $LogDirectory + "\W3SVC" +  $SiteID
	$LogFiles = Get-ChildItem $LogPath -Filter *.log -EA SilentlyContinue | Where {$_.LastWriteTime -lt (Get-Date).AddDays(-7)}
 
	foreach ($LogFile in $LogFiles)
	{
		# IO Optimizer
		Start-Sleep 5
 
		# Log File Name
		$LogPath = $LogFile.FullName
 
		# Zip Name
		$ZipPath = $LogPath + ".zip"
 
		# Compress
		$LogFile | ConvertTo-CompressedFile $ZipPath
 
		# Remove
		$LogFile | Remove-Item -Force -Confirm:$false
	}
}

Umarım faydası dokunur. Kolay gelsin.


Posted in Windows Server | No Comment | 1,744 views | 25/11/2015 15:00

This is a query of mine, which gives you detailed information about indexes on one query:

SELECT SO.NAME AS TableName, PS.object_id AS ObjectId, SI.NAME AS IndexName, PS.index_id AS IndexId, SUM(PS.RESERVED_PAGE_COUNT*8) TotalStorage, SUM(PS.USED_PAGE_COUNT*8) UsedStorage, SUM((PS.RESERVED_PAGE_COUNT - PS.USED_PAGE_COUNT)*8) FreeStorage,
SUM(CASE WHEN PS.INDEX_ID IN (0,1) THEN PS.ROW_COUNT ELSE 0 END) AS ROW_COUNT,
MAX(round(Avg_Fragmentation_In_Percent, 2)) AS 'AvgFragmentationInPercent',
MAX(fragment_count) AS FragmentCount,
MAX(ips.page_count) AS PageCount,
MAX(ius.user_scans) AS UserScans, MAX(ius.user_seeks) AS UserSeeks, MAX(ius.user_lookups) AS UserLookups
FROM
SYS.DM_DB_PARTITION_STATS PS
INNER JOIN sys.dm_db_index_physical_stats(5,NULL,NULL,NULL,'LIMITED') AS ips
ON ps.object_id = ips.object_id AND
       ps.index_id = ips.index_id
INNER JOIN SYS.OBJECTS SO ON SO.OBJECT_ID = PS.OBJECT_ID
LEFT JOIN SYS.INDEXES SI ON SI.OBJECT_ID = PS.OBJECT_ID
AND SI.INDEX_ID = PS.INDEX_ID
LEFT OUTER JOIN sys.dm_db_index_usage_stats ius ON ius.database_id = 5 AND ps.object_id = ius.object_id AND ps.index_id = ius.index_id
WHERE
SO.IS_MS_SHIPPED = 0
GROUP BY so.name, ps.object_id, si.name, ps.index_id
ORDER BY UserLookups DESC

You can also add Schema column if you have different db schemeas.


Posted in Windows Server | No Comment | 1,898 views | 10/11/2015 15:14

Check following query to improve your database performance:

EXEC sys.sp_configure N'show advanced options', N'1'  RECONFIGURE WITH OVERRIDE
GO
EXEC sys.sp_configure N'max server memory (MB)', N'11000'
GO
RECONFIGURE WITH OVERRIDE
GO
EXEC sys.sp_configure N'show advanced options', N'0'  RECONFIGURE WITH OVERRIDE
GO
EXEC sys.sp_configure N'show advanced options', N'1'  RECONFIGURE WITH OVERRIDE
GO
EXEC sys.sp_configure N'max degree of parallelism', N'1'
GO
EXEC sys.sp_configure N'max server memory (MB)', N'11000'
GO
EXEC sys.sp_configure N'optimize for ad hoc workloads', N'1'
GO
RECONFIGURE WITH OVERRIDE
GO
EXEC sys.sp_configure N'show advanced options', N'0'  RECONFIGURE WITH OVERRIDE
GO

This is a note for myself. So you should edit config to meet your requirements.