This is a base runbook template developed by CT Global.

This version was first presented at Experts Live EU 2017.

[CmdletBinding()]
[OutputType([Object])] #Set to specific object type if possible (fx. if script gets a ADUser, set output type to ADUser)
Param
(
    [Parameter (Mandatory = $true)]
    [String] $ResourceGroupName
)

    $ErrorActionPreference = "stop"
    $VerbosePreference = "silentlycontinue"

    #//----------------------------------------------------------------------------
    #//
    #//  Global constant and variable declarations
    #//  Shared Resource retrieval (Assets)
    #//
    #//----------------------------------------------------------------------------
    #Constants
    $Prefix = "CT-"
    
    #Assets
    $Credential = Get-AutomationCredential -Name "Admin"

    #//----------------------------------------------------------------------------
    #//  Procedures (Logging etc.)
    #//----------------------------------------------------------------------------
    #region Procedures
    Function Add-Tracelog {
    
    param($Message, $TraceLog)

        $Message = "$(get-date) - $Message`n"
        Write-Verbose $Message
        if ([String]::IsNullOrEmpty($TraceLog)) {
            $TraceLog = $Message
        }
        else {
            $TraceLog += $Message
        }
    }
    Function ConvertTo-IndexedTable {
    
        param(
            [Parameter(Mandatory = $true,
                ValueFromPipelineByPropertyName = $false,
                Position = 0)]
            $IndexFieldName,
            [Parameter(Mandatory = $true,
                ValueFromPipelineByPropertyName = $true,
                ValueFromPipeline = $true,
                Position = 1)]
            [Object]$Object
        )

        #begin { $ReturnArray = @() } #New-Object System.Collections.ArrayList }
        process {
            @{ 
                $IndexFieldName = $Object.$IndexFieldName
                Object          = $Object
            }
        }
        #end { $ReturnArray }
    }
    #endregion

    #//----------------------------------------------------------------------------
    #//  Main routines
    #//----------------------------------------------------------------------------

    Try { #Main Catch
        $script:TraceLog = $null #when testing in ISE, tracelog is not reset
        $StartTime = get-date
        Add-Tracelog -TraceLog $TraceLog -Message "Job Started at $StartTime"
        Add-Tracelog -TraceLog $TraceLog -Message "Running on: $env:computername"

        $OutputData = @{}

        #region Main Code
        #Import Modules
        Add-Tracelog -TraceLog $TraceLog -Message "Import SCCM Module"
        Import-Module AzureRM

        #Redirect all outputs to $null
        $null = . {




        }
    
        #endregion
        $EndTime = Get-date
        Add-Tracelog -TraceLog $TraceLog -Message "Finished at: $EndTime"
        Add-Tracelog -TraceLog $TraceLog -Message "Total Runtime: $($Endtime - $StartTime)"

        $OutputData.Add("TraceLog", $TraceLog)
        $OutputData.Add("Status", "Success")
        
        Write-Output $OutputData

        Write-Verbose $TraceLog
    }
    Catch {
        $ErrorMessage = $_.Exception.Message + "`nAt Line number: $($_.InvocationInfo.ScriptLineNumber)"
        Write-Error -Message $ErrorMessage
        $OutputData.Add("ErrorMessage", $ErrorMessage)
        $OutputData.Add("Status", "Failed")
        Write-Output $OutputData
    } 
    
    #//----------------------------------------------------------------------------
    #//  End Script
    #//----------------------------------------------------------------------------
    #>
Previous articleIt’s here, Android O aka Android Oreo
Next articleEnhanced Sync-VSTSGit runbook that support Pull Requests
Jakob is a Microsoft System Center Cloud and Data center Management MVP. Working as Senior Consultant, trainer and Chief Developer at Coretech A/S, where he is one of the driving forces in keeping Coretech a System Center Gold Partner and member of the System Center Alliance. Since he started at Coretech in 2007, he has focused on Scripting and Development, primarily developing tools, extensions and scripts for the System Center Suite. His main product focus is System Center Orchestrator, the former Opalis, a product he has been invited to speak about at different summits and user group meetings, becoming a renowned voice in his field. He is passionately devoted to the community, for which he contributes to, by being a moderator at TechNet, member of the TechNet Influencers team and sharing his knowledge through hid blog.