Get-DPsApp.ps1
# .\Get-DPsApp.ps1
param($SiteServer,$MP,$SiteCode,[switch]$Grps)
#region [Init]
$erroractionpreference = 'silentlycontinue'
$here = $PSScriptRoot
if(!$here){$here = (Get-Location).path}
#endregion [Init]
#region [Function]
function scriptlog{
param($val)
write-host $val
}
function Connex($MP){
# Importer le module SCCM
Import-Module "$($Env:SMS_ADMIN_UI_PATH)\..\ConfigurationManager.psd1"
# Récupérer le nom du lecteur pour le chemin spécifié
[string]$SCCMDrive = (Get-PSDrive | Where-Object { $_.Root -match $MP }).Name
if(!$SCCMDrive){$SCCMDrive = (Get-PSdrive | where-object{$_.Provider -eq "CMSite"}).Name}
$DriveCM = $SCCMDrive.replace('\','')
$DriveCM = "$DriveCM`:"
$DriveCM = $DriveCM.replace('::',':')
return $DriveCM
}
#endregion [Function]
#region [Get-Variables]
set-location $here
$Global:CMDrive = Connex($MP)
[string]$SiteCode = $CMDrive.split(':')[0]
if(!$SiteServer){[string]$SiteServer = (Get-PSdrive -Name $SiteCode | where-object{$_.Provider -eq "CMSite"}).Root}
$Namespace = "ROOT/SMS/Site_{0}" -f $SiteCode
scriptlog -val "CMDrive = $CMDrive"
scriptlog -val "SiteCode = $SiteCode"
scriptlog -val "Namespace = $Namespace"
#endregion [Get-Variables]
#region [Set-PSCMContentMgmt]
function getDPsApp{
set-location $CMDrive
$DistributionPointGroup = Get-CMDistributionPointGroup
foreach ($TargetDPGroup in $DistributionPointGroup.Name) {
$Query = "SELECT * FROM SMS_DPGroupContentInfo WHERE SMS_DPGroupContentInfo.GroupID in ( SELECT SMS_DPGroupInfo.GroupID FROM SMS_DPGroupInfo WHERE Name = '$TargetDPGroup' )"
[string]$resObjectType = "ObjectType = '{0}'" -f [Int][SMS_DPContentInfo]"Application"
$Qry = "{0} AND ( {1} )" -f $Query, $resObjectType
Get-CimInstance -ComputerName $SiteServer -Namespace $Namespace -Query $Qry | ForEach-Object {
$ObjectIDQry = "SELECT CI_ID FROM SMS_ApplicationLatest WHERE ModelName = '{0}'" -f $_.ObjectID
$AppObjectID = (Get-CimInstance -ComputerName $SiteServer -Namespace $Namespace -Query $ObjectIDQry).CI_ID
[PSCustomObject]@{
PSTypeName = "PSCMContentMgmt"
ObjectName = $_.Name
Description = $_.Description
ObjectType = ([SMS_DPContentInfo]$_.ObjectType).ToString()
ObjectID = $AppObjectID
SourceSize = $_.SourceSize
DistributionPointGroup = $TargetDPGroup
}
}
}
}
#endregion [Set-PSCMContentMgmt]
#region [Get-DPsApp]
$getDPsApps = getDPsApp
foreach($getDPsApp in $getDPsApps){
if($getDPsApp.ObjectName -match $AppName){
$DPGroup = $getDPsApp.DistributionPointGroup
$DPGroups += "$DPGroup;"
}
}
$DPGroups = $DPGroups.trimend(';')
if($Grps){return $DPGroups}else{
$DPs = (Get-CMDistributionPointGroup -Name $DPGroups | Get-CMDistributionPoint).Name
return $DPs
}
#endregion [Get-DPsApp]
/image%2F0881799%2F20140610%2Fob_a8c7fe_logo2.jpg)
Commenter cet article