Friday, October 11, 2024

Use this script to refresh a list content to a specific dp

 

# Use this script to refresh a list content to a specific dp, or a list of dps to a specific piece of content.


# Paste output list from SQL of packageids

$PKGIDS = @"

"@


# Paste output list from SQL of the full servernalpaths

$serverNalPath = @"


"@


<# Begin #>

<# do not modify below #>

# Splitting up the Here strings for Packageids and Servernalpaths to turn it into an array of objects

$PKGIDS = $PKGIDS.Split("`r`n") | Where-Object {$_ -ne ""}

$ServerNalPath  = $ServerNalPath.Split("`r`n") | Where-Object {$_ -ne ""}

$ServerShortName = $ServerNalPath  |  % {$_.Split("\\")[5]}


# Testing the counts of the arrays to make sure we don't loop improperly

$ErrorActionPreference = "Stop"

$shouldrun = $false

if ($PKGIDS.count -eq 1 -and $ServerShortName.count -ge 1) {$shouldrun = $true}

elseif ($PKGIDS.count -ge 1 -and $ServerShortName.count -eq 1) {$shouldrun = $true}

    else {$shouldrun = $false}


if ($shouldrun) {

    $ServerShortName | % { 

        $ServerNalPath = $_

        $PKGIDS | % {

            TRY {

                $PKGID = $_

                $DP = gwmi -ComputerName xxxxxx -Class sms_distributionpoint -filter "ServerNALPath like '%$ServerNalPath%' and packageid = `'$PKGID`'" -Namespace root\sms\site_XXX

                $dp.RefreshNow = $true

                $dp.put() | Out-Null

                Write-Output "Success - Refreshing $PKGID on $ServerNalPath"

                }

            CATCH { 

                Write-Output "Error - Refreshing $PKGID on $ServerNalPath"

                }


        }

    }

}

else {

    Write-Output "Error - Script only supports running against a single packageid or a single servernal path at a time, validate input"

    }


<# END #>





SQL Queries to get :
-- 1, get list of all pending packageids, change nalpath to broken DP
select * from v_PackageStatusDistPointsSumm
where servernalpath like '%xxxx%'  and state != 0
order by packageid
 
-- 2, get dpip to send to distribuitonjobs, note the dpid for the dp
select * from v_distributionpoints where servername like '%xxxx%'




No comments:

Post a Comment

SCCM to Tanium

SCCM transition Options: of course intune otherwise  Deployment, Patching - Tanium Image - Tazier Inventory - Tanium Remote Control - Zoom  ...