_______________________________________________________________________________________

Note: This e-mail is subject to the disclaimer contained at the bottom of this 
message.
_______________________________________________________________________________________


Below is the Powershell Script that I ended up putting together, it's to 
migrate new collections and their objects from 2007 to 2012 but only once that 
exist under certain parent collections.


Also note... I had this advertised to the site server (we only have 1 primary 
site server)running as the machine.. however it did not have rights to create 
or start migration jobs...
And you cannot use credentials if you are connecting to local WMI...
So this script is advertised to run on a different machine connecting with an 
account that has the rights




#------------- Begin Script  ------------------------
Write-Host " Starting...."

$Teir3Col = '' #
$Teir1Col = ''
$Teir2Col = ''

$SITECODE = ''
$siteServer = ''


$username = ""  # account that has rights to do migrations 'domain\user'
$key = (111,111,111,111,111,111,111,111,111, 111, 111, 111, 111, 111, 111, 111, 
111, 111, 111, 111, 111, 111, 111, 111) # the key that was used to encode the 
password for the account
$password = get-content automig.data | convertto-securestring -key $key

$creds = new-object -typename System.Management.Automation.PSCredential 
-argumentlist $username, $password

Write-Host " Run query to find T2 and T3 collections..."
$Teir3ColEntity = GWMI -Namespace "ROOT\SMS\Site_$SITECODE" -ComputerName 
"$siteServer" -Query "SELECT * FROM SMS_MigrationCollectionInfo WHERE 
(SourceSiteCollectionID = '$Teir3Col' or SourceSiteCollectionID = '$Teir2Col' 
or SourceSiteCollectionID = '$Teir1Col')" -Credential $creds
$SourceSiteID = $Teir3ColEntity.SourceSiteID[0]
$SourceSiteCode = $Teir3ColEntity.SiteCodes[0]

$EntityIsIn = "("
foreach ($Entitiy in $($Teir3ColEntity.Children.Split(",")))
{
    $EntityIsIn += "'$Entitiy',"
}
$EntityIsIn += "'Dummy')"
Write-Host " Lets see if there are any new collections apllicable for migration 
in this bunch.. "

$ChildEntities = GWMI -Namespace "ROOT\SMS\Site_$SITECODE " -ComputerName 
"$siteServer " -Query "SELECT * FROM SMS_MigrationEntity sME left join 
SMS_MigrationEntityDependency sMED on sME.EntityID = sMED.EntityID join 
SMS_MigrationEntity sMDE on (sMDE.EntityID = sMED.Dependant and sMDE.Status = 0 
and sMDE.type !=253) where sME.EntityKey in $EntityIsIn and type= 1 and 
sME.ObjectTypeID=5 and sME.Status=0" -Credential $creds

if($($ChildEntities.length) -gt 0 -or $($ChildEntities.smde.SourceSiteID) -eq 
16777217)  # errr... that is the source site ID in our environment, used just 
to check if its array or single object
{
    Write-Host " Found at least one... "
    $EntitiesToMigrate = @{}
    $EntitiesToMigrate.add("entitykey",@())
    $EntitiesToMigrate.add("entityID",@())

    $EntitiesToMigrate.entitykey += $ChildEntities.smde.entitykey | Get-Unique
    $EntitiesToMigrate.entitykey += $ChildEntities.sME.entitykey | Get-Unique
    $EntitiesToMigrate.entityID += $ChildEntities.smde.entityID | Get-Unique
    $EntitiesToMigrate.entityID += $ChildEntities.sME.entityID | Get-Unique

    $collectionsToMigrate = $ChildEntities.sME.entitykey | Get-Unique

    $AdditionalInfo = "<MigrationJob>`n"
    foreach($Entitiy in $collectionsToMigrate)
    {
        $AdditionalInfo += '<Collection ID="' + $Entitiy + '" Type = "2" />' + 
"`n"
    }
    $AdditionalInfo += "</MigrationJob> "
    Write-Host " These are the collection ID's we are going to migrate `n 
$additionalInfo"

    $SourceCollectionIDs = $($EntitiesToMigrate.EntityKey)
    $SourceObjectIDs = $($EntitiesToMigrate.EntityID)
    $SourceSiteID = $($Teir3ColEntity.SourceSiteID)
    $SourceSiteCode = $($Teir3ColEntity.SiteCodes)
    $DestinationSiteCode = ""  #<--------------------------------- 2012 site 
code hard coded.
    $JobType = 2

    $MigJobClass = get-wmiobject -list -namespace "root\sms\site_$sitecode" 
-Class SMS_MigrationJob -computername "$siteserver" -Credential $creds
    $newMigJob = $MigJobClass.CreateInstance()

    $newMigJob.AdditionalConfiguration= $AdditionalInfo
    $newMigJob.Description = "Scripted MigJob"
    $newMigJob.DestinationSiteCode= "" #<--------------------------------- 2012 
site code hard coded.
    $newMigJob.DisableAdvertisements = $false
    $newMigJob.JobName = "Auto T2 and T3  MigrationJob-$(get-date -Format 
'yyyy-MM-dd-HH-mm')"
    $newMigJob.MigrateWithFolders= $true
    $newMigJob.ResolveObjectConflictOption = 1
    $newMigJob.ScopeIDs = "SMS00UNA"
    $newMigJob.SourceCollectionIDs = $SourceCollectionIDs
    $newMigJob.SourceObjectIDs = $SourceObjectIDs
    $newMigJob.SourceSiteCode = ""  #<------------------------------------ 2007 
Site code... hard coded....
    $newMigJob.SourceSiteID = $Teir3ColEntity.SourceSiteID[0]
    $newMigJob.Type = 2
    Write-Host " Got our migrationjob object assembled... just going to save..."
    $newMigJob.Put()
    Write-Host " Then we can start the migration Job"
    $newMigJob.start()
    Write-Host " And we are done...."

}
else
{
    write-host "No new collections to migrate"
}


From: [email protected] [mailto:[email protected]] On 
Behalf Of s kissel
Sent: Friday, 15 November 2013 7:28 AM
To: [email protected]
Subject: [mssms] Automating Migration Jobs

Hi

Does anyone have a tool or script to automate migration jobs from SCCM 2007 to 
SCCM 2012? Specifically, I'm looking for a way to migrate new or updated 
objects (packages) only from SCCM 2007 to SCCM 2012 on a daily or twice-daily 
basis and overwrite existing objects if they exist. The reason for this is that 
there are a lot package changes occurring in SCCM 2007 during the migration, 
and creating a migration job daily seems like an opportunity for automation.

Thanks!


_______________________________________________________________________________________

The information transmitted in this message and its attachments (if any) is 
intended 
only for the person or entity to which it is addressed.
The message may contain confidential and/or privileged material. Any review, 
retransmission, dissemination or other use of, or taking of any action in 
reliance 
upon this information, by persons or entities other than the intended recipient 
is 
prohibited.

If you have received this in error, please contact the sender and delete this 
e-mail 
and associated material from any computer.

The intended recipient of this e-mail may only use, reproduce, disclose or 
distribute 
the information contained in this e-mail and any attached files, with the 
permission 
of the sender.

This message has been scanned for viruses.
_______________________________________________________________________________________



Reply via email to