<commit_before>function Get-TargetResource
{
    [CmdletBinding()]
    [OutputType([System.Collections.Hashtable])]
    param
    (
        [parameter(Mandatory = $true)]  [System.String] $Url,
        [parameter(Mandatory = $true)]  [System.String] $OwnerAlias,        
        [parameter(Mandatory = $false)] [System.UInt32] $CompatibilityLevel,        
        [parameter(Mandatory = $false)] [System.String] $ContentDatabase,        
        [parameter(Mandatory = $false)] [System.String] $Description,
        [parameter(Mandatory = $false)] [System.String] $HostHeaderWebApplication,        
        [parameter(Mandatory = $false)] [System.UInt32] $Language,        
        [parameter(Mandatory = $false)] [System.String] $Name,        
        [parameter(Mandatory = $false)] [System.String] $OwnerEmail,        
        [parameter(Mandatory = $false)] [System.String] $QuotaTemplate,        
        [parameter(Mandatory = $false)] [System.String] $SecondaryEmail,        
        [parameter(Mandatory = $false)] [System.String] $SecondaryOwnerAlias,
        [parameter(Mandatory = $false)] [System.String] $Template,
        [parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount
    )

    Write-Verbose -Message "Getting site collection $Url"

    $result = Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
        $params = $args[0]
        $site = Invoke-xSharePointSPCmdlet -CmdletName "Get-SPSite" -Arguments @{ Identity = $params.Url } -ErrorAction SilentlyContinue
        
        if ($null -eq $site) { return @{} }
        else {
            if ($site.HostHeaderIsSiteName) { $HostHeaderWebApplication = $site.Url } 

            if ($site.WebApplication.UseClaimsAuthentication) {
                $owner = Invoke-xSharePointSPCmdlet -CmdletName "New-SPClaimsPrincipal" -Arguments @{ Identity = $site.Owner.UserLogin; IdentityType = "EncodedClaim" }
            } else {
                $owner = $site.Owner.UserLogin
            }

            if ($null -eq $site.SecondaryContact) {
                $secondaryOwner = $null
            } else {
                if ($site.WebApplication.UseClaimsAuthentication) {
                    $secondaryOwner = Invoke-xSharePointSPCmdlet -CmdletName "New-SPClaimsPrincipal" -Arguments @{ Identity = $site.SecondaryContact.UserLogin; IdentityType = "EncodedClaim" }
                } else {
                    $secondaryOwner = $site.SecondaryContact.UserLogin
                }
            }

            return @{
                Url = $site.Url
                OwnerAlias = $owner
                CompatibilityLevel = $site.CompatibilityLevel
                ContentDatabase = $site.ContentDatabase.Name
                Description = $site.RootWeb.Description
                HostHeaderWebApplication = $HostHeaderWebApplication
                Language = $site.RootWeb.Language
                Name = $site.RootWeb.Name
                OwnerEmail = $site.Owner.Email
                QuotaTemplate = $site.Quota
                SecondaryEmail = $site.SecondaryContact.Email
                SecondaryOwnerAlias = $secondaryOwner
                Template = "$($site.RootWeb.WebTemplate)#$($site.RootWeb.WebTemplateId)"
                InstallAccount = $params.InstallAccount
            }
        }
    }
    return $result
}


function Set-TargetResource
{
    [CmdletBinding()]
    param
    (
        [parameter(Mandatory = $true)]  [System.String] $Url,
        [parameter(Mandatory = $true)]  [System.String] $OwnerAlias,        
        [parameter(Mandatory = $false)] [System.UInt32] $CompatibilityLevel,        
        [parameter(Mandatory = $false)] [System.String] $ContentDatabase,        
        [parameter(Mandatory = $false)] [System.String] $Description,        
        [parameter(Mandatory = $false)] [System.String] $HostHeaderWebApplication,        
        [parameter(Mandatory = $false)] [System.UInt32] $Language,        
        [parameter(Mandatory = $false)] [System.String] $Name,        
        [parameter(Mandatory = $false)] [System.String] $OwnerEmail,        
        [parameter(Mandatory = $false)] [System.String] $QuotaTemplate,        
        [parameter(Mandatory = $false)] [System.String] $SecondaryEmail,        
        [parameter(Mandatory = $false)] [System.String] $SecondaryOwnerAlias,
        [parameter(Mandatory = $false)] [System.String] $Template,
        [parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount
    )

    Write-Verbose -Message "Creating site collection $Url"

    $result = Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
        $params = $args[0]
        $params.Remove("InstallAccount") | Out-Null

        $site = Invoke-xSharePointSPCmdlet -CmdletName "Get-SPSite" -Arguments @{ Identity = $params.Url } -ErrorAction SilentlyContinue

        if ($null -eq $site) {
            Invoke-xSharePointSPCmdlet -CmdletName "New-SPSite" -Arguments $params | Out-Null
        }
    }
}


function Test-TargetResource
{
    [CmdletBinding()]
    [OutputType([System.Boolean])]
    param
    (
        [parameter(Mandatory = $true)]  [System.String] $Url,
        [parameter(Mandatory = $true)]  [System.String] $OwnerAlias,        
        [parameter(Mandatory = $false)] [System.UInt32] $CompatibilityLevel,        
        [parameter(Mandatory = $false)] [System.String] $ContentDatabase,        
        [parameter(Mandatory = $false)] [System.String] $Description,        
        [parameter(Mandatory = $false)] [System.String] $HostHeaderWebApplication,        
        [parameter(Mandatory = $false)] [System.UInt32] $Language,        
        [parameter(Mandatory = $false)] [System.String] $Name,        
        [parameter(Mandatory = $false)] [System.String] $OwnerEmail,        
        [parameter(Mandatory = $false)] [System.String] $QuotaTemplate,        
        [parameter(Mandatory = $false)] [System.String] $SecondaryEmail,        
        [parameter(Mandatory = $false)] [System.String] $SecondaryOwnerAlias,
        [parameter(Mandatory = $false)] [System.String] $Template,
        [parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount
    )

    $CurrentValues = Get-TargetResource @PSBoundParameters
    Write-Verbose -Message "Testing site collection $Url"
    return Test-xSharePointSpecificParameters -CurrentValues $CurrentValues -DesiredValues $PSBoundParameters -ValuesToCheck @("Url")
}


Export-ModuleMember -Function *-TargetResource

<commit_msg>Fixed issue where owner could be null in get for xSPSite<commit_after>function Get-TargetResource
{
    [CmdletBinding()]
    [OutputType([System.Collections.Hashtable])]
    param
    (
        [parameter(Mandatory = $true)]  [System.String] $Url,
        [parameter(Mandatory = $true)]  [System.String] $OwnerAlias,        
        [parameter(Mandatory = $false)] [System.UInt32] $CompatibilityLevel,        
        [parameter(Mandatory = $false)] [System.String] $ContentDatabase,        
        [parameter(Mandatory = $false)] [System.String] $Description,
        [parameter(Mandatory = $false)] [System.String] $HostHeaderWebApplication,        
        [parameter(Mandatory = $false)] [System.UInt32] $Language,        
        [parameter(Mandatory = $false)] [System.String] $Name,        
        [parameter(Mandatory = $false)] [System.String] $OwnerEmail,        
        [parameter(Mandatory = $false)] [System.String] $QuotaTemplate,        
        [parameter(Mandatory = $false)] [System.String] $SecondaryEmail,        
        [parameter(Mandatory = $false)] [System.String] $SecondaryOwnerAlias,
        [parameter(Mandatory = $false)] [System.String] $Template,
        [parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount
    )

    Write-Verbose -Message "Getting site collection $Url"

    $result = Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
        $params = $args[0]
        $site = Invoke-xSharePointSPCmdlet -CmdletName "Get-SPSite" -Arguments @{ Identity = $params.Url } -ErrorAction SilentlyContinue
        
        if ($null -eq $site) { 
            return @{} 
        } else {
            if ($site.HostHeaderIsSiteName) { $HostHeaderWebApplication = $site.WebApplication.Url } 

            if ($null -eq $site.Owner) {
                $owner = $null
            } else {
                if ($site.WebApplication.UseClaimsAuthentication) {
                    $owner = (Invoke-xSharePointSPCmdlet -CmdletName "New-SPClaimsPrincipal" -Arguments @{ Identity = $site.Owner.UserLogin; IdentityType = "EncodedClaim" }).Value
                } else {
                    $owner = $site.Owner.UserLogin
                }
            }
            
            if ($null -eq $site.SecondaryContact) {
                $secondaryOwner = $null
            } else {
                if ($site.WebApplication.UseClaimsAuthentication) {
                    $secondaryOwner = (Invoke-xSharePointSPCmdlet -CmdletName "New-SPClaimsPrincipal" -Arguments @{ Identity = $site.SecondaryContact.UserLogin; IdentityType = "EncodedClaim" }).Value
                } else {
                    $secondaryOwner = $site.SecondaryContact.UserLogin
                }
            }

            return @{
                Url = $site.Url
                OwnerAlias = $owner
                CompatibilityLevel = $site.CompatibilityLevel
                ContentDatabase = $site.ContentDatabase.Name
                Description = $site.RootWeb.Description
                HostHeaderWebApplication = $HostHeaderWebApplication
                Language = $site.RootWeb.Language
                Name = $site.RootWeb.Name
                OwnerEmail = $site.Owner.Email
                QuotaTemplate = $site.Quota
                SecondaryEmail = $site.SecondaryContact.Email
                SecondaryOwnerAlias = $secondaryOwner
                Template = "$($site.RootWeb.WebTemplate)#$($site.RootWeb.WebTemplateId)"
                InstallAccount = $params.InstallAccount
            }
        }
    }
    return $result
}


function Set-TargetResource
{
    [CmdletBinding()]
    param
    (
        [parameter(Mandatory = $true)]  [System.String] $Url,
        [parameter(Mandatory = $true)]  [System.String] $OwnerAlias,        
        [parameter(Mandatory = $false)] [System.UInt32] $CompatibilityLevel,        
        [parameter(Mandatory = $false)] [System.String] $ContentDatabase,        
        [parameter(Mandatory = $false)] [System.String] $Description,        
        [parameter(Mandatory = $false)] [System.String] $HostHeaderWebApplication,        
        [parameter(Mandatory = $false)] [System.UInt32] $Language,        
        [parameter(Mandatory = $false)] [System.String] $Name,        
        [parameter(Mandatory = $false)] [System.String] $OwnerEmail,        
        [parameter(Mandatory = $false)] [System.String] $QuotaTemplate,        
        [parameter(Mandatory = $false)] [System.String] $SecondaryEmail,        
        [parameter(Mandatory = $false)] [System.String] $SecondaryOwnerAlias,
        [parameter(Mandatory = $false)] [System.String] $Template,
        [parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount
    )

    Write-Verbose -Message "Creating site collection $Url"

    $result = Invoke-xSharePointCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock {
        $params = $args[0]
        $params.Remove("InstallAccount") | Out-Null

        $site = Invoke-xSharePointSPCmdlet -CmdletName "Get-SPSite" -Arguments @{ Identity = $params.Url } -ErrorAction SilentlyContinue

        if ($null -eq $site) {
            Invoke-xSharePointSPCmdlet -CmdletName "New-SPSite" -Arguments $params | Out-Null
        }
    }
}


function Test-TargetResource
{
    [CmdletBinding()]
    [OutputType([System.Boolean])]
    param
    (
        [parameter(Mandatory = $true)]  [System.String] $Url,
        [parameter(Mandatory = $true)]  [System.String] $OwnerAlias,        
        [parameter(Mandatory = $false)] [System.UInt32] $CompatibilityLevel,        
        [parameter(Mandatory = $false)] [System.String] $ContentDatabase,        
        [parameter(Mandatory = $false)] [System.String] $Description,        
        [parameter(Mandatory = $false)] [System.String] $HostHeaderWebApplication,        
        [parameter(Mandatory = $false)] [System.UInt32] $Language,        
        [parameter(Mandatory = $false)] [System.String] $Name,        
        [parameter(Mandatory = $false)] [System.String] $OwnerEmail,        
        [parameter(Mandatory = $false)] [System.String] $QuotaTemplate,        
        [parameter(Mandatory = $false)] [System.String] $SecondaryEmail,        
        [parameter(Mandatory = $false)] [System.String] $SecondaryOwnerAlias,
        [parameter(Mandatory = $false)] [System.String] $Template,
        [parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount
    )

    $CurrentValues = Get-TargetResource @PSBoundParameters
    Write-Verbose -Message "Testing site collection $Url"
    return Test-xSharePointSpecificParameters -CurrentValues $CurrentValues -DesiredValues $PSBoundParameters -ValuesToCheck @("Url")
}


Export-ModuleMember -Function *-TargetResource


{'fraction_non_alphanumeric': 0.11888682745825603, 'fraction_numerical': 0.002077922077922078, 'mean_word_length': 2.50390015600624, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '6815323', 'n_tokens_mistral': 3809, 'n_tokens_neox': 3677, 'n_words': 695}