SCCM (ConfigMgr)

Export Task Sequence

function Export-AllCMTaskSequences {
    param (
        [Parameter(Mandatory)]
        [string]$SiteCode,

        [string]$ExportPath = "C:\SCCM_Export\TaskSequences",

        [switch]$WithDependence
    )

    # ConfigMgr modülünü yükle
    Import-Module "$($ENV:SMS_ADMIN_UI_PATH)\..\ConfigurationManager.psd1" -ErrorAction Stop

    # SCCM site kodunu ayarla
    Set-Location "$SiteCode`:"

    # Export edilecek klasör oluşturulmazsa oluştur
    if (-not (Test-Path $ExportPath)) {
        New-Item -Path $ExportPath -ItemType Directory | Out-Null
        Write-Host "📁 Export klasörü oluşturuldu: $ExportPath"
    }

    # Task Sequence listesini al
    $taskSequences = Get-CMTaskSequence

    foreach ($ts in $taskSequences) {
        $tsName = $ts.Name
        $tsPackageID = $ts.PackageID

        # OSD olup olmadığını kontrol et
        $isOSD = $ts.BootImageID -or $tsName -match "(Deploy|Install).*(OS|Operating System)"

        # Dosya adı belirle
        if ($isOSD) {
            $exportFileName = "OS - $tsName"
        } else {
            $exportFileName = $tsName
        }

        # Dosya adı geçersiz karakter temizliği
        $exportFileName = $exportFileName -replace '[\\/:*?"<>|]', '_'
        $exportFile = Join-Path $ExportPath "$exportFileName.zip"

        # Export işlemi
        Write-Host "`n📦 Exporting Task Sequence: $tsName"
        try {
            if ($WithDependence) {
                Export-CMTaskSequence -TaskSequencePackageId $tsPackageID -ExportFilePath $exportFile -WithDependence -Force
            } else {
                Export-CMTaskSequence -TaskSequencePackageId $tsPackageID -ExportFilePath $exportFile -Force
            }

            Write-Host "✅ Exported to: $exportFile"
        }
        catch {
            Write-Warning "❌ Export başarısız: $tsName - $_"
        }
    }

    Write-Host "`n🎉 Tüm Task Sequence'ler export edildi. Export klasörü: $ExportPath"
}

Usage

Export-AllCMTaskSequences -SiteCode "P01" -ExportPath "D:\SCCM_Backup\TaskSequences"

Last updated