DSCResources/AzureServiceBusCreation/AzureServiceBusCreation.psm1

function Get-TargetResource
{
    [CmdletBinding()]
    [OutputType([System.Collections.Hashtable])]
    param
    (
        [parameter(Mandatory = $true)]
        [System.String]
        $SubScriptionName,

        [ValidateSet("Absent","Present")]
        [System.String]
        $Ensure,

        [parameter(Mandatory = $true)]
        [System.String]
        $PublishSettingsFile,

        [parameter(Mandatory = $true)]
        [System.String]
        $SubscriptionID,

        [parameter(Mandatory = $true)]
        [System.String]
        $Location,

        [parameter(Mandatory = $true)]
        [System.String]
        $StorageAccount,

        [parameter(Mandatory = $true)]
        [System.String]
        $SBNameSpace
    )

    #Write-Verbose "Use this cmdlet to deliver information about command processing."

    #Write-Debug "Use this cmdlet to write debug information while troubleshooting."


    <#
    $returnValue = @{
        ConfigPath = [System.String]
        Ensure = [System.String]
    }
 
    $returnValue
    #>

}


function Set-TargetResource
{
    [CmdletBinding()]
    param
    (
        [parameter(Mandatory = $true)]
        [System.String]
        $SubScriptionName,

        [ValidateSet("Absent","Present")]
        [System.String]
        $Ensure,

        [parameter(Mandatory = $true)]
        [System.String]
        $PublishSettingsFile,

        [parameter(Mandatory = $true)]
        [System.String]
        $SubscriptionID,

        [parameter(Mandatory = $true)]
        [System.String]
        $Location,

        [parameter(Mandatory = $true)]
        [System.String]
        $StorageAccount,

        [parameter(Mandatory = $true)]
        [System.String]
        $SBNameSpace
    )
     Write-Verbose "set function execution starts......."    
       
     if(Test-Path "$env:SystemDrive\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\Azure") 
  { 
      Import-Module "$env:SystemDrive\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\Azure"
     }
     elseif(Test-Path "$env:SystemDrive\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure")
     {
          Import-Module "$env:SystemDrive\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure"
     }
     else
     {
         Import-Module "$env:SystemDrive\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure"
     }
     if($? -eq $false)
     {
       $exitcode=1
       exit $exitcode
     }

     
    Import-AzurePublishSettingsFile -PublishSettingsFile $PublishSettingsFile
    Set-AzureSubscription -SubscriptionName $SubScriptionName -CurrentStorageAccountName $StorageAccount
    Select-AzureSubscription -SubscriptionName $SubScriptionName
    $CheckServicebusResult= Get-AzureSBNamespace -Name $SBNameSpace

    if (((Get-Variable CheckServicebusResult).Value) -ne $null )
    {
        Write-Verbose "ServiceBus already exists with namespace $SBNameSpace"
    }
    else
    {
        Write-Verbose "Creating new servicebus $SBNameSpace"
        New-AzureSBNamespace -Name $SBNameSpace -CreateACSNamespace $false -NamespaceType Messaging -Location $Location -ErrorAction SilentlyContinue
        Write-Verbose "Azure Service Bus with namespace $SBNameSpace created successfully"
    }
       

       Write-Verbose "set function execution ends......."
}


function Test-TargetResource
{
    [CmdletBinding()]
    [OutputType([System.Boolean])]
    param
    (
        [parameter(Mandatory = $true)]
        [System.String]
        $SubScriptionName,

        [ValidateSet("Absent","Present")]
        [System.String]
        $Ensure,

        [parameter(Mandatory = $true)]
        [System.String]
        $PublishSettingsFile,

        [parameter(Mandatory = $true)]
        [System.String]
        $SubscriptionID,

        [parameter(Mandatory = $true)]
        [System.String]
        $Location,

        [parameter(Mandatory = $true)]
        [System.String]
        $StorageAccount,

        [parameter(Mandatory = $true)]
        [System.String]
        $SBNameSpace
    )

    #Write-Verbose "Use this cmdlet to deliver information about command processing."

    #Write-Debug "Use this cmdlet to write debug information while troubleshooting."


    
    $result = [System.Boolean]$false
    
    $result
    
}


Export-ModuleMember -Function *-TargetResource