<commit_before>Function Test-DbaDiskAlignment
{
<#
    .SYNOPSIS
        Verifies that your non-dynamic disks are aligned according to physical constraints.
    
    .DESCRIPTION
        Returns $true or $false by default for one server. Returns Server name and IsBestPractice for more than one server.
        
        Specify -Detailed for additional information which returns some additional optional "best practice" columns, which may show false even though you pass the alignment test.
        This is because your offset is not one of the "expected" values that Windows uses, but your disk is still physically aligned.
        
        Please refer to your storage vendor best practices before following any advice below.
        By default issues with disk alignment should be resolved by a new installation of Windows Server 2008, Windows Vista, or later operating systems, but verifying disk alignment continues to be recommended as a best practice.
        While some versions of Windows use different starting alignments, if you are starting anew 1MB is generally the best practice offset for current operating systems (because it ensures that the partition offset % common stripe unit sizes == 0 )
        
        Caveats:
        Dynamic drives (or those provisioned via third party software) may or may not have accurate results when polled by any of the built in tools, see your vendor for details.
        Windows does not have a reliable way to determine stripe unit Sizes. These values are obtained from vendor disk management software or from your SAN administrator.
        System drives in versions previous to Windows Server 2008 cannot be aligned, but it is generally not recommended to place SQL Server databases on system drives.
    
    .PARAMETER ComputerName
        The SQL Server(s) you would like to connect to and check disk alignment.
    
    .PARAMETER Detailed
        DEPRECATED: This parameter will be removed on version 1.0.0.0
        This parameter used to show additional disk details such as offset calculations and IsOffsetBestPractice, which returns false if you do not have one of the offsets described by Microsoft. Returning false does not mean you are not phyiscally aligned.
    
    .PARAMETER Credential
        An alternate domain/username when enumerating the drives on the SQL Server(s), if needed password will be requested when queries run. May require Administrator privileges.
    
    .PARAMETER SQLCredential
        An alternate SqlCredential object when connecting to and verifying the location of the SQL Server databases on the target SQL Server(s).
    
    .PARAMETER NoSqlCheck
        Skip checking for the presence of SQL Server and simply check all disks for alignment. This can be useful if SQL Server is not yet installed or is dormant.
    
    .PARAMETER Silent
        Use this switch to disable any kind of verbose messages.
        Setting this will cause the function to throw exceptions when something breaks, which can then be caught by the caller.
    
    .EXAMPLE
        Test-DbaDiskAlignment -ComputerName sqlserver2014a
        
        Tests the disk alignment of a single server named sqlserver2014a
    
    .EXAMPLE
        Test-DbaDiskAlignment -ComputerName sqlserver2014a, sqlserver2014b, sqlserver2014c
        
        Tests the disk alignment of mulitiple servers
    
    .NOTES
        Tags: Storage
        The preferred way to determine if your disks are aligned (or not) is to calculate:
        1. Partition offset - stripe unit size
        2. Stripe unit size - File allocation unit size
        
        References:
        Disk Partition Alignment Best Practices for SQL Server - https://technet.microsoft.com/en-us/library/dd758814(v=sql.100).aspx
        A great article and behind most of this code.
        
        Getting Partition Offset information with Powershell - http://sqlblog.com/blogs/jonathan_kehayias/archive/2010/03/01/getting-partition-Offset-information-with-powershell.aspx
        Thanks to <NAME>!
        
        Decree: Set your partition Offset and block Size and make SQL Server faster - http://www.midnightdba.com/Jen/2014/04/decree-set-your-partition-Offset-and-block-Size-make-sql-server-faster/
        Thanks to Jen McCown!
        
        Disk Performance Hands On - http://www.kendalvandyke.com/2009/02/disk-performance-hands-on-series-recap.html
        Thanks to Kendal Van Dyke!
        
        Get WMI Disk Information - http://powershell.com/cs/media/p/7937.aspx
        Thanks to jbruns2010!
        
        Original Author: <NAME> (https://constantinekokkinos.com, @mobileck)
        
        dbatools PowerShell module (https://dbatools.io, <EMAIL>,)
        Copyright (C) 2016 <NAME>
        
        This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
        
        This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
        
        You should have received a copy of the GNU General Public License along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    .LINK
        https://dbatools.io/Test-DbaDiskAlignment
#>    
    Param (
        [parameter(Mandatory = $true, ValueFromPipeline = $true)]
        [Alias("ServerInstance", "SqlInstance", "SqlServer")]
        [object[]]
        $ComputerName,
        
        [switch]
        $Detailed,
        
        [System.Data.SqlClient.SqlCredential]
        $Credential,
        
        [System.Data.SqlClient.SqlCredential]
        $SqlCredential,
        
        [switch]
        $NoSqlCheck,
        
        [switch]
        $Silent
    )
    BEGIN
    {
        Test-DbaDeprecation -DeprecatedOn "1.0.0.0" -Parameter 'Detailed' 
        
        $sessionoption = New-CimSessionOption -Protocol DCom
        
        Function Get-DiskAlignment
        {
            [CmdletBinding()]
            Param (
                $CimSession,
                
                [string]
                $FunctionName = (Get-PSCallStack)[0].Command,
                
                [bool]<commit_msg>Fixed Credential type<commit_after>Function Test-DbaDiskAlignment
{
<#
    .SYNOPSIS
        Verifies that your non-dynamic disks are aligned according to physical constraints.
    
    .DESCRIPTION
        Returns $true or $false by default for one server. Returns Server name and IsBestPractice for more than one server.
        
        Specify -Detailed for additional information which returns some additional optional "best practice" columns, which may show false even though you pass the alignment test.
        This is because your offset is not one of the "expected" values that Windows uses, but your disk is still physically aligned.
        
        Please refer to your storage vendor best practices before following any advice below.
        By default issues with disk alignment should be resolved by a new installation of Windows Server 2008, Windows Vista, or later operating systems, but verifying disk alignment continues to be recommended as a best practice.
        While some versions of Windows use different starting alignments, if you are starting anew 1MB is generally the best practice offset for current operating systems (because it ensures that the partition offset % common stripe unit sizes == 0 )
        
        Caveats:
        Dynamic drives (or those provisioned via third party software) may or may not have accurate results when polled by any of the built in tools, see your vendor for details.
        Windows does not have a reliable way to determine stripe unit Sizes. These values are obtained from vendor disk management software or from your SAN administrator.
        System drives in versions previous to Windows Server 2008 cannot be aligned, but it is generally not recommended to place SQL Server databases on system drives.
    
    .PARAMETER ComputerName
        The SQL Server(s) you would like to connect to and check disk alignment.
    
    .PARAMETER Detailed
        DEPRECATED: This parameter will be removed on version 1.0.0.0
        This parameter used to show additional disk details such as offset calculations and IsOffsetBestPractice, which returns false if you do not have one of the offsets described by Microsoft. Returning false does not mean you are not phyiscally aligned.
    
    .PARAMETER Credential
        An alternate domain/username when enumerating the drives on the SQL Server(s), if needed password will be requested when queries run. May require Administrator privileges.
    
    .PARAMETER SQLCredential
        An alternate SqlCredential object when connecting to and verifying the location of the SQL Server databases on the target SQL Server(s).
    
    .PARAMETER NoSqlCheck
        Skip checking for the presence of SQL Server and simply check all disks for alignment. This can be useful if SQL Server is not yet installed or is dormant.
    
    .PARAMETER Silent
        Use this switch to disable any kind of verbose messages.
        Setting this will cause the function to throw exceptions when something breaks, which can then be caught by the caller.
    
    .EXAMPLE
        Test-DbaDiskAlignment -ComputerName sqlserver2014a
        
        Tests the disk alignment of a single server named sqlserver2014a
    
    .EXAMPLE
        Test-DbaDiskAlignment -ComputerName sqlserver2014a, sqlserver2014b, sqlserver2014c
        
        Tests the disk alignment of mulitiple servers
    
    .NOTES
        Tags: Storage
        The preferred way to determine if your disks are aligned (or not) is to calculate:
        1. Partition offset - stripe unit size
        2. Stripe unit size - File allocation unit size
        
        References:
        Disk Partition Alignment Best Practices for SQL Server - https://technet.microsoft.com/en-us/library/dd758814(v=sql.100).aspx
        A great article and behind most of this code.
        
        Getting Partition Offset information with Powershell - http://sqlblog.com/blogs/jonathan_kehayias/archive/2010/03/01/getting-partition-Offset-information-with-powershell.aspx
        Thanks to <NAME>!
        
        Decree: Set your partition Offset and block Size and make SQL Server faster - http://www.midnightdba.com/Jen/2014/04/decree-set-your-partition-Offset-and-block-Size-make-sql-server-faster/
        Thanks to Jen McCown!
        
        Disk Performance Hands On - http://www.kendalvandyke.com/2009/02/disk-performance-hands-on-series-recap.html
        Thanks to Kendal Van Dyke!
        
        Get WMI Disk Information - http://powershell.com/cs/media/p/7937.aspx
        Thanks to jbruns2010!
        
        Original Author: <NAME> (https://constantinekokkinos.com, @mobileck)
        
        dbatools PowerShell module (https://dbatools.io, <EMAIL>,)
        Copyright (C) 2016 <NAME>
        
        This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
        
        This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
        
        You should have received a copy of the GNU General Public License along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    .LINK
        https://dbatools.io/Test-DbaDiskAlignment
#>    
    Param (
        [parameter(Mandatory = $true, ValueFromPipeline = $true)]
        [Alias("ServerInstance", "SqlInstance", "SqlServer")]
        [object[]]
        $ComputerName,
        
        [switch]
        $Detailed,
        
        [System.Management.Automation.PSCredential]
        $Credential,
        
        [System.Management.Automation.PSCredential]
        $SqlCredential,
        
        [switch]
        $NoSqlCheck,
        
        [switch]
        $Silent
    )
    BEGIN
    {
        Test-DbaDeprecation -DeprecatedOn "1.0.0.0" -Parameter 'Detailed' 
        
        $sessionoption = New-CimSessionOption -Protocol DCom
        
        Function Get-DiskAlignment
        {
            [CmdletBinding()]
            Param (
                $CimSession,
                
                [string]
                $FunctionName = (Get-PSCallStack)[0].Command,
                
                [bool]
{'fraction_non_alphanumeric': 0.05117803089405523, 'fraction_numerical': 0.012950538305507879, 'mean_word_length': 2.490062619112442, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 8, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4993214', 'n_tokens_mistral': 3264, 'n_tokens_neox': 3050, 'n_words': 1409}