如何把例行的作業變成自動化規範來避免人為遺漏?
每當有新主機來報到的時候,總是需要做著相同的檢查及設定
心裡總想著如果能夠把這些動作變成一個簡單又快速的步驟
那我不就可以多個幾分鐘去泡咖啡了嗎 ???
所以接下來就用超 OP 的 PowerShell 搭配一下來動手做 Automatic 吧
例行公事:sql server disk format 64k block size
Why use 64k block for sql ??? 小弟我在這裡要推薦史丹利好熱的一篇超棒文章
[SQL Server]改善I/O效能- NTFS Allocation Unit Size(4KB vs 64KB)
用檢查 block size 有很多方法,但小弟我個人偏好撰寫快速又簡單的 PS 去呼叫 Get-WmiObject
打開 notepad 先定義幾個變數然後寫成 function,這樣在日後使用時就可以透過變數去檢查指定的 disk
然後檢查 block size 是否符合我們要的 64k,並且把檢查結果產生 report 待泡完咖啡後來點開查看即可
function CheckDrive()
{
$BytesPerCluster = Get-WmiObject -Query $query -ComputerName '.' | Select-Object Name, BlockSize
If ($BytesPerCluster.BlockSize -eq $value)
{
$message = "OK."
$message | Out-File -Append $reportPath"\"$reportFile
$BytesPerCluster | Out-File -Append $reportPath"\"$reportFile
$endmark | Out-File -Append $reportPath"\"$reportFile
}
Else
{
$message = "Warning! Please check " + $queryname + "."
$message | Out-File -Append $reportPath"\"$reportFile
$BytesPerCluster | Out-File -Append $reportPath"\"$reportFile
$endmark | Out-File -Append $reportPath"\"$reportFile
}
}
$query = "SELECT Name, BlockSize FROM Win32_Volume WHERE FileSystem='NTFS' and DriveLetter = 'D:'"
$value = 65536
$queryname = "disk block size"
CheckDrive
檢查完所產出的 report 結果就像這樣
(待續...)