Below is the Powershell PS1 script to get the all deployments in SCCM 2012
Function Get-SCCMFolderDeployments
{
<#
.Synopsis
Collects Deployment details using Collection ID information available in that folder
.DESCRIPTION
Deployment Summary of all the deployments assigned to the collection obtained from the folder
.EXAMPLE
.EXAMPLE
.INPUTS
FolderName
SiteServer
Sitecode
.OUTPUTS
AdvertisementName
ExpirationTime
AdvertisementID
PackageID
Comment
Softwarename
IsExpired
CollectionID
CollectionName
PresentTime
ProgramName
FolderName
.NOTES
This function would be useful only in SCCM perspective when the values are pulled from database
.ROLE
Role is to Pull the deployment information from SCCM for the specified collection under respective folder
.FUNCTIONALITY
Using the Folder name, Fetches deployment information for the collections residing in that folder
#>
[CmdletBinding(DefaultParameterSetName='Parameter Set 1',
PositionalBinding=$false)]
Param
(
# Folder Name
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false,
Position=0,
ParameterSetName='Parameter Set 1')]
[ValidateNotNullOrEmpty()]
[Alias("Name")]
$FolderName = "Temporary Delivery",
# Site server Name
[Parameter(Mandatory=$false,
Position=1,
ParameterSetName='Parameter Set 1')]
$SiteServer = "Primary server name",
# Site Code of the SCCM environment
[Parameter(Mandatory=$false,
Position=2,
ParameterSetName='Parameter Set 1')]
$SiteCode = "Site code"
)
Begin
{
Write-host "Script Started!!!" -ForegroundColor Green
}
Process
{
$Collection = _Get-SCCMCollection[Inner_Module] -FolderName $FolderName -SiteServer $SiteServer -SiteCode $SiteCode
$Deployment = _Get-SCCMDeploymentSummary[Inner_Module] -CollectionIDs $Collection -SiteServer $SiteServer -SiteCode $SiteCode
}
End
{
Return $Deployment
Write-host "Script Completed!!!" -ForegroundColor Green
}
}
Function Get-SCCMCollectionDeployments
{
<#
.Synopsis
Collects Deployment details using Collection ID information
.DESCRIPTION
Deployment Summary of all the deployments assigned to the collection
.EXAMPLE
.EXAMPLE
.INPUTS
CollectionID
SiteServer
Sitecode
.OUTPUTS
AdvertisementName
ExpirationTime
AdvertisementID
PackageID
Comment
Softwarename
IsExpired
CollectionID
CollectionName
PresentTime
ProgramName
FolderName
.NOTES
This function would be useful only in SCCM perspective when the values are pulled from database
.ROLE
Role is to Pull the deployment information from SCCM for the specified collection
.FUNCTIONALITY
Using the Folder name, Fetches deployment information for the collections specified
#>
[CmdletBinding(DefaultParameterSetName='Parameter Set 1',
PositionalBinding=$false)]
Param
(
# Folder Name
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false,
Position=0,
ParameterSetName='Parameter Set 1')]
[ValidateNotNullOrEmpty()]
[Alias("IDs")]
$CollectionIDs ,
# Site server Name
[Parameter(Mandatory=$false,
Position=1,
ParameterSetName='Parameter Set 1')]
$SiteServer = "primary server name",
# Site Code of the SCCM environment
[Parameter(Mandatory=$false,
Position=2,
ParameterSetName='Parameter Set 1')]
$SiteCode = "site code"
)
Begin
{
Write-host "Script Started!!!" -ForegroundColor Green
}
Process
{
$Collection = _Get-SCCMFolderName[Inner_Module] -Objects $CollectionIDs -SiteServer $SiteServer -SiteCode $SiteCode -ObjectTypeName "SMS_Collection_Device"
$Deployment = _Get-SCCMDeploymentSummary[Inner_Module] -CollectionIDs $Collection -SiteServer $SiteServer -SiteCode $SiteCode
}
End
{
Return $Deployment
Write-host "Script Completed!!!" -ForegroundColor Green
}
}
Function Get-SCCMPackageDeployments
{
<#
.Synopsis
Collects Deployment details using Package name or ID information
.DESCRIPTION
Deployment Summary of all the deployments assigned to the Package
.EXAMPLE
.EXAMPLE
Get-SCCMPackageDeployments -Package 001fc -SiteServer primary server name -SiteCode site code
Script Started!!!
ExpirationTime : 9/10/2014 3:00:00 PM
PresentTime : 9/10/2014 3:00:00 PM
PackageFolderName : Restricted Software
Softwarename : Master Collection CC 2014 Suite (Install)
AdvertisementName : Install_001FC_AdobeETLAMasterCollectionCC2014Suite1.0
AdvertisementID : 203CA
Comment : 2014-09-09 - blahblah - blahblahblah - Adobe ETLA Master Collection CC 2014 Suite 1.0
CollectionFolderName : Application Management
IsExpired : Not Set
CollectionName : Adobe ETLA Master Collection CC 2014 Suite 1.0
PackageID : 001FC
CollectionID : 0022D
ProgramName : Install
ExpirationTime : 9/10/2014 3:00:00 PM
PresentTime : 9/10/2014 3:00:00 PM
PackageFolderName : Restricted Software
Softwarename : Master Collection CC 2014 Suite (Uninstall)
AdvertisementName : Uninstall_001FC_AdobeETLAMasterCollectionCC2014Suite1.0
AdvertisementID : 203CB
Comment : 2014-09-09 - blahblhablha - nlahblahblah - Adobe ETLA Master Collection CC 2014 Suite 1.0
CollectionFolderName : Application Management
IsExpired : Not Set
CollectionName : Adobe ETLA Master Collection CC 2014 Suite 1.0
PackageID : 001FC
CollectionID : 0022D
ProgramName : Uninstall
.INPUTS
Packagedetail
SiteServer
Sitecode
.OUTPUTS
AdvertisementName
ExpirationTime
AdvertisementID
PackageID
Comment
Softwarename
IsExpired
CollectionID
CollectionName
PresentTime
ProgramName
FolderName
.NOTES
This function would be useful only in SCCM perspective when the values are pulled from database
.ROLE
Role is to Pull the deployment information from SCCM for the specified collection
.FUNCTIONALITY
Using the Folder name, Fetches deployment information for the collections specified
#>
[CmdletBinding(DefaultParameterSetName='Parameter Set 1',
PositionalBinding=$false)]
Param
(
# Folder Name
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false,
Position=0,
ParameterSetName='Parameter Set 1')]
[ValidateNotNullOrEmpty()]
[Alias("PackageID","PackageName")]
$Package ,
# Site server Name
[Parameter(Mandatory=$false,
Position=1,
ParameterSetName='Parameter Set 1')]
$SiteServer = "primary server name",
# Site Code of the SCCM environment
[Parameter(Mandatory=$false,
Position=2,
ParameterSetName='Parameter Set 1')]
$SiteCode = "site code"
)
Begin
{
Write-host "Script Started!!!" -ForegroundColor Green
}
Process
{
$PackageInfo = _Get-SCCMPackage[Inner_Module] -Objects $Package -SiteServer $SiteServer -SiteCode $SiteCode
$Deployment = _Get-SCCMDeploymentSummary[Inner_Module] -PackageIDs $PackageInfo -SiteServer $SiteServer -SiteCode $SiteCode
}
End
{
Return $Deployment
Write-host "Script Completed!!!" -ForegroundColor Green
}
}
Function _Get-SCCMFolderName[Inner_Module]
{
<#
.Synopsis
Collects Foldername using CollectionIDs
.DESCRIPTION
Foldernames are fetched using the CollectionIDs
.EXAMPLE
.EXAMPLE
.INPUTS
FolderName
.OUTPUTS
CollectionIDs
.NOTES
This function would be useful only in SCCM perspective when the values are pulled from database
.ROLE
Role is to Pull the Collection information from SCCM for the specified Collection
.FUNCTIONALITY
Fetches Collection information
#>
[CmdletBinding(DefaultParameterSetName='Parameter Set 1',
PositionalBinding=$false)]
Param
(
# Folder Name
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false,
Position=0,
ParameterSetName='Parameter Set 1')]
[ValidateNotNullOrEmpty()]
[Alias("Object")]
[string[]]$Objects,
# Site server Name
[Parameter(Mandatory=$false,
Position=1,
ParameterSetName='Parameter Set 1')]
$SiteServer = "primary server name",
# Site Code of the SCCM environment
[Parameter(Mandatory=$false,
Position=2,
ParameterSetName='Parameter Set 1')]
$SiteCode = "site code",
[Parameter(Mandatory=$True,
Position=3)]
[ValidateSet("SMS_Package","SMS_Query","SMS_ApplicationLatest","SMS_Collection_Device","SMS_SoftwareUpdate","SMS_TaskSequencePackage","SMS_Driver","SMS_OperatingSystemInstallPackage","SMS_ConfigurationBaselineInfo","SMS_ConfigurationItemLatest","SMS_ImagePackage ","SMS_DriverPackage","SMS_BootImagePackage","SMS_Collection_User")]
$ObjectTypeName
)
Begin
{
$CollectedID = @()
$filter = "ObjectTypeName= '$ObjectTypeName'"
}
Process
{
Foreach ($Object in $Objects)
{
$Collecting = gwmi -Namespace root\Sms\site_$SiteCode -Class SMS_ObjectContainerItem -ComputerName $SiteServer -filter $filter|
where {($_.InstanceKey -like "$Object*" )}
# If ($objectInfo -eq $null)
# {
# $pack = _Get-SCCMPackage[Inner_Module] -Objects $Object -SiteServer $SiteServer -SiteCode $SiteCode
# $coll = _Get-SCCMCollection[Inner_Module] -Objects $Object -SiteServer $SiteServer -SiteCode $SiteCode
# }
$Foldername = gwmi -Namespace root\Sms\site_$SiteCode -Class SMS_ObjectContainerNode -ComputerName $SiteServer -Filter $filter|
where {$_.ContainerNodeID -eq $Collecting.ContainerNodeID}
If ($Foldername -eq $null)
{
$value = "Maybe Parent Folder"
}
else
{
$value = $($Foldername.Name)
}
Add-Member -InputObject $Collecting -MemberType NoteProperty -Name "FolderName" -Value $value -Force
$CollectedID += $Collecting
}
}
End
{
Return $CollectedID
}
}
Function _Get-SCCMCollection[Inner_Module]
{
<#
.Synopsis
Collects CollectionIDs using Foldername
.DESCRIPTION
CollectionIDs are fetched using the foldername provided
.EXAMPLE
.EXAMPLE
.INPUTS
FolderName
.OUTPUTS
CollectionIDs
.NOTES
This function would be useful only in SCCM perspective when the values are pulled from database
.ROLE
Role is to Pull the Collection information from SCCM for the specified Folders
.FUNCTIONALITY
Fetches Collection information
#>
[CmdletBinding(DefaultParameterSetName='Parameter Set 1',
PositionalBinding=$false)]
Param
(
# Folder Name
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false,
Position=0,
ParameterSetName='Parameter Set 1')]
[ValidateNotNullOrEmpty()]
[Alias("Folder")]
$FolderName,
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false,
Position=0,
ParameterSetName='Parameter Set 2')]
[ValidateNotNullOrEmpty()]
[Alias("Collection")]
$Objects,
# Site server Name
[Parameter(Mandatory=$false,
Position=1)]
$SiteServer = "Primary server name",
# Site Code of the SCCM environment
[Parameter(Mandatory=$false,
Position=2)]
$SiteCode = "Site code"
)
Begin
{
$CollectionIDs = @()
}
Process
{
If ($FolderName)
{
$FolderIDs = gwmi -Namespace root\Sms\site_$SiteCode -Class SMS_ObjectContainerNode -ComputerName $SiteServer |
where {$_.Name -like "*$($FolderName)*"} |
select ContainerNodeID, ObjectType, ObjectTypeName, @{n="FolderName"; e={$_.Name}}
Foreach ($FolderID in $FolderIDs)
{
$CollectionIDs += gwmi -Namespace root\Sms\site_$SiteCode -Class SMS_ObjectContainerItem -ComputerName $SiteServer |
where {$_.ContainerNodeID -eq $($FolderID.ContainerNodeID)} |
Select *,@{n="FolderName";e={$FolderID.FolderName}}
}
}
If ($Objects)
{
Foreach ($Object in $Objects)
{
$CollectionIDs += gwmi -Namespace root\Sms\site_$SiteCode -Class SMS_Collection -ComputerName $SiteServer |
where {$_.CollectionID -like "*$object*" -or $_.Name -like "*$object*"} |
Select *,@{n="CollectionFolderName";e={$FolderID.FolderName}}
}
}
}
End
{
Return $CollectionIDs
}
}
Function _Get-SCCMPackage[Inner_Module]
{
<#
.Synopsis
Collects Package Information using Package ID
.DESCRIPTION
Package Information is fetched using the PackageID or Package Name
.EXAMPLE
.EXAMPLE
.INPUTS
FolderName
.OUTPUTS
CollectionIDs
.NOTES
This function would be useful only in SCCM perspective when the values are pulled from database
.ROLE
Role is to Pull the Collection information from SCCM for the specified Folders
.FUNCTIONALITY
Fetches Collection information
#>
[CmdletBinding(DefaultParameterSetName='Parameter Set 1',
PositionalBinding=$false)]
Param
(
# Name
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false,
Position=0,
ParameterSetName='Parameter Set 1')]
[ValidateNotNullOrEmpty()]
[Alias("PackageName")]
[String[]]
$Objects,
# Site server Name
[Parameter(Mandatory=$false,
Position=1,
ParameterSetName='Parameter Set 1')]
$SiteServer = "Primary server name",
# Site Code of the SCCM environment
[Parameter(Mandatory=$false,
Position=2,
ParameterSetName='Parameter Set 1')]
$SiteCode = "site code"
)
Begin
{
$Package = @()
}
Process
{
Foreach ($Object in $Objects)
{
$Output = Get-WmiObject -Namespace root\sms\site_$sitecode -Class sms_package -ComputerName $SiteServer |
Where {$_.PackageID -like "*$Object*" -or $_.Name -like "*$Object*"} |
select Name, NumOfPrograms, SourceVersion, Version, PackageID, @{n="Size in (MB)"; e={(($_.packagesize)/1024)}}
#$folder = (_Get-SCCMFolderName[Inner_Module] -Objects $output.packageID -SiteServer $SiteServer -SiteCode $SiteCode -ObjectTypeName "SMS_Package").foldername
#Add-Member -InputObject $Output -MemberType NoteProperty -Name "PackageFolderName" -Value $folder -Force
$Package += $Output
}
}
End
{
Return $Package
}
}
Function _Get-SCCMDeploymentSummary[Inner_Module]
{
<#
.Synopsis
Collects Deployment details using Collection ID information
.DESCRIPTION
Deployment Summary of all the deployments assigned to the collection obtained
.EXAMPLE
.EXAMPLE
.INPUTS
Collection
.OUTPUTS
Deployment
.NOTES
This function would be useful only in SCCM perspective when the values are pulled from database
.ROLE
Role is to Pull the deployment information from SCCM for the specified collection
.FUNCTIONALITY
Fetches deployment information
#>
[CmdletBinding(DefaultParameterSetName='Parameter Set 1',
PositionalBinding=$false)]
Param
(
# Folder Name
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false,
Position=0,
ParameterSetName='Parameter Set 1')]
[ValidateNotNullOrEmpty()]
[Alias("CollectionID")]
$CollectionIDs,
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false,
Position=0,
ParameterSetName='Parameter Set 2')]
[ValidateNotNullOrEmpty()]
[Alias("PackageID")]
$PackageIDs,
# Site server Name
[Parameter(Mandatory=$false,
Position=1)]
$SiteServer = "primary server name",
# Site Code of the SCCM environment
[Parameter(Mandatory=$false,
Position=2)]
$SiteCode = "site code"
)
Begin
{
$MYResult = @()
$deployments = @()
}
Process
{
If ($collectionIDs)
{
Foreach ($CollectionID in $CollectionIDs)
{
$Deployments += gwmi -Namespace root\Sms\site_$SiteCode -Class SMS_DeploymentSummary -ComputerName $SiteServer |
where { $_.CollectionID -eq $CollectionID.InstanceKey} |
Select *, @{n="CollectionFolderName";e={If ($CollectionID.CollectionfolderName) {$CollectionID.CollectionfolderName}Else {"No Name"}}}
}
}
If ($PackageIDs)
{
Foreach ($PackageID in $PackageIDs)
{
$Deployments += gwmi -Namespace root\Sms\site_$SiteCode -Class SMS_DeploymentSummary -ComputerName $SiteServer |
where { $_.PackageID -eq $PackageID.PackageID} |
Select *, @{n="PackageFolderName";e={If ($PackageID.folderName) {$PackageID.folderName}Else {"No Name"}}}
}
}
Foreach ($Deployment in $Deployments)
{
$DeploymentTime = $Deployment.DeploymentTime
$Deploymentresult = gwmi -Namespace root\Sms\site_$SiteCode -Class SMS_Advertisement -ComputerName $SiteServer |
where { $_.CollectionID -eq $Deployment.CollectionID -and $_.advertisementID -eq $Deployment.DeploymentID} |
Select PackageID, ProgramName, AdvertisementName, PresentTime, ExpirationTime, Comment, CollectionID , @{n="IsExpired"; e={If((_Convert-datestring[Inner_Module] $_.ExpirationTime) -eq (_Convert-datestring[Inner_Module] $_.PresentTime)) {"Not Set"} Elseif ((_Convert-datestring[Inner_Module] $_.ExpirationTime) -lt (get-date) ) {"Yes"} Else {"No"}}}
if ($Deploymentresult)
{
$collectionfoldername = If ($Deployment.CollectionFolderName) {$Deployment.CollectionFolderName} else {(_Get-SCCMFolderName[Inner_Module] -Objects $Deploymentresult.CollectionID -SiteServer $SiteServer -SiteCode $SiteCode -ObjectTypeName "SMS_Collection_Device").foldername}
$PackageFoldername = If ($Deployment.PackageFolderName) {$Deployment.PackageFolderName} else {(_Get-SCCMFolderName[Inner_Module] -Objects $Deploymentresult.packageID -SiteServer $SiteServer -SiteCode $SiteCode -ObjectTypeName "SMS_Package").foldername}
$ObjectProperty = ""
$ObjectProperty = @{
DeploymentID = $Deployment.DeploymentID
CollectionID = $Deployment.CollectionID
CollectionName = $Deployment.CollectionName
PackageID = $Deploymentresult.PackageID
ProgramName = $Deploymentresult.ProgramName
AdvertisementName = $Deploymentresult.AdvertisementName
PresentTime = _Convert-datestring[Inner_Module] $Deploymentresult.PresentTime
ExpirationTime = _Convert-datestring[Inner_Module] $Deploymentresult.ExpirationTime
Comment = $Deploymentresult.Comment
IsExpired = $Deploymentresult.IsExpired
Softwarename = $Deployment.SoftwareName
CollectionFolderName = $collectionFoldername
PackageFolderName = $PackageFoldername
}
$Object = New-Object PSObject -Property $ObjectProperty
$MYResult += $Object
}
}
}
End
{
Return $MYResult
}
}
Function _Convert-datestring[Inner_Module]
{
<#
.Synopsis
Convert a string to date time
.DESCRIPTION
Date information is stored as string in database, we were unable to compare ot with the current date so we have to convert it to Datetime format
.EXAMPLE
PS C:\> _Convert-datestring[Inner_Module] "20140708080000.000000+***"
Tuesday, July 08, 2014 8:00:00 AM
.INPUTS
Datestring
.OUTPUTS
Date
.NOTES
This function would be useful only in SCCM perspective when the values are pulled from database
.ROLE
Role is to convert the string format date value to date
.FUNCTIONALITY
Converts string to date Time
#>
[CmdletBinding(DefaultParameterSetName='Parameter Set 1')]
[OutputType([DateTime])]
Param
(
# Datestring which needs to be converted
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
Position=0,
ParameterSetName='Parameter Set 1')]
[ValidateNotNullOrEmpty()]
[Alias("String")]
$DateString
)
begin
{
$a = $datestring
Write-Debug "Assigning value to `$a - $a"
$a = $a.Remove($a.LastIndexOf("."))
Write-Debug "Removing the values after '.', so `$a - $a"
$b = $a.tochararray()
Write-Debug "Converting the string into array as i have some issues in using them, so `$b - $b"
}
Process
{
Write-Debug "Grouping all values to form a Date and Time"
$Splittime = @{
Year = [int]$a.Remove(4)
Month = [int]"$($b[4])$($b[5])"
Day = [int]"$($b[6])$($b[7])"
Hour = [int]"$($b[8])$($b[9])"
Minute = [int]"$($b[10])$($b[11])"
Second = [int]"$($b[12])$($b[13])"
}
$ExpirationTime = [datetime] "$($Splittime.year)/$($Splittime.month)/$($Splittime.day) $($Splittime.hour):$($Splittime.minute):$($Splittime.second)"
Write-Debug "Assigned all values and converted to Date time, the output is `n $ExpirationTime"
}
End
{
Write-Debug "Returning ExpirationTime!"
return $ExpirationTime
}
#Date Property datetime Date {get;}
#Day Property int Day {get;}
#DayOfWeek Property System.DayOfWeek DayOfWeek {get;}
#DayOfYear Property int DayOfYear {get;}
#Hour Property int Hour {get;}
#Kind Property System.DateTimeKind Kind {get;}
#Millisecond Property int Millisecond {get;}
#Minute Property int Minute {get;}
#Month Property int Month {get;}
#Second Property int Second {get;}
#Ticks Property long Ticks {get;}
#TimeOfDay Property timespan TimeOfDay {get;}
#Year Property int Year {get;}
}
Function Get-SCCMFolderDeployments
{
<#
.Synopsis
Collects Deployment details using Collection ID information available in that folder
.DESCRIPTION
Deployment Summary of all the deployments assigned to the collection obtained from the folder
.EXAMPLE
.EXAMPLE
.INPUTS
FolderName
SiteServer
Sitecode
.OUTPUTS
AdvertisementName
ExpirationTime
AdvertisementID
PackageID
Comment
Softwarename
IsExpired
CollectionID
CollectionName
PresentTime
ProgramName
FolderName
.NOTES
This function would be useful only in SCCM perspective when the values are pulled from database
.ROLE
Role is to Pull the deployment information from SCCM for the specified collection under respective folder
.FUNCTIONALITY
Using the Folder name, Fetches deployment information for the collections residing in that folder
#>
[CmdletBinding(DefaultParameterSetName='Parameter Set 1',
PositionalBinding=$false)]
Param
(
# Folder Name
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false,
Position=0,
ParameterSetName='Parameter Set 1')]
[ValidateNotNullOrEmpty()]
[Alias("Name")]
$FolderName = "Temporary Delivery",
# Site server Name
[Parameter(Mandatory=$false,
Position=1,
ParameterSetName='Parameter Set 1')]
$SiteServer = "Primary server name",
# Site Code of the SCCM environment
[Parameter(Mandatory=$false,
Position=2,
ParameterSetName='Parameter Set 1')]
$SiteCode = "Site code"
)
Begin
{
Write-host "Script Started!!!" -ForegroundColor Green
}
Process
{
$Collection = _Get-SCCMCollection[Inner_Module] -FolderName $FolderName -SiteServer $SiteServer -SiteCode $SiteCode
$Deployment = _Get-SCCMDeploymentSummary[Inner_Module] -CollectionIDs $Collection -SiteServer $SiteServer -SiteCode $SiteCode
}
End
{
Return $Deployment
Write-host "Script Completed!!!" -ForegroundColor Green
}
}
Function Get-SCCMCollectionDeployments
{
<#
.Synopsis
Collects Deployment details using Collection ID information
.DESCRIPTION
Deployment Summary of all the deployments assigned to the collection
.EXAMPLE
.EXAMPLE
.INPUTS
CollectionID
SiteServer
Sitecode
.OUTPUTS
AdvertisementName
ExpirationTime
AdvertisementID
PackageID
Comment
Softwarename
IsExpired
CollectionID
CollectionName
PresentTime
ProgramName
FolderName
.NOTES
This function would be useful only in SCCM perspective when the values are pulled from database
.ROLE
Role is to Pull the deployment information from SCCM for the specified collection
.FUNCTIONALITY
Using the Folder name, Fetches deployment information for the collections specified
#>
[CmdletBinding(DefaultParameterSetName='Parameter Set 1',
PositionalBinding=$false)]
Param
(
# Folder Name
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false,
Position=0,
ParameterSetName='Parameter Set 1')]
[ValidateNotNullOrEmpty()]
[Alias("IDs")]
$CollectionIDs ,
# Site server Name
[Parameter(Mandatory=$false,
Position=1,
ParameterSetName='Parameter Set 1')]
$SiteServer = "primary server name",
# Site Code of the SCCM environment
[Parameter(Mandatory=$false,
Position=2,
ParameterSetName='Parameter Set 1')]
$SiteCode = "site code"
)
Begin
{
Write-host "Script Started!!!" -ForegroundColor Green
}
Process
{
$Collection = _Get-SCCMFolderName[Inner_Module] -Objects $CollectionIDs -SiteServer $SiteServer -SiteCode $SiteCode -ObjectTypeName "SMS_Collection_Device"
$Deployment = _Get-SCCMDeploymentSummary[Inner_Module] -CollectionIDs $Collection -SiteServer $SiteServer -SiteCode $SiteCode
}
End
{
Return $Deployment
Write-host "Script Completed!!!" -ForegroundColor Green
}
}
Function Get-SCCMPackageDeployments
{
<#
.Synopsis
Collects Deployment details using Package name or ID information
.DESCRIPTION
Deployment Summary of all the deployments assigned to the Package
.EXAMPLE
.EXAMPLE
Get-SCCMPackageDeployments -Package 001fc -SiteServer primary server name -SiteCode site code
Script Started!!!
ExpirationTime : 9/10/2014 3:00:00 PM
PresentTime : 9/10/2014 3:00:00 PM
PackageFolderName : Restricted Software
Softwarename : Master Collection CC 2014 Suite (Install)
AdvertisementName : Install_001FC_AdobeETLAMasterCollectionCC2014Suite1.0
AdvertisementID : 203CA
Comment : 2014-09-09 - blahblah - blahblahblah - Adobe ETLA Master Collection CC 2014 Suite 1.0
CollectionFolderName : Application Management
IsExpired : Not Set
CollectionName : Adobe ETLA Master Collection CC 2014 Suite 1.0
PackageID : 001FC
CollectionID : 0022D
ProgramName : Install
ExpirationTime : 9/10/2014 3:00:00 PM
PresentTime : 9/10/2014 3:00:00 PM
PackageFolderName : Restricted Software
Softwarename : Master Collection CC 2014 Suite (Uninstall)
AdvertisementName : Uninstall_001FC_AdobeETLAMasterCollectionCC2014Suite1.0
AdvertisementID : 203CB
Comment : 2014-09-09 - blahblhablha - nlahblahblah - Adobe ETLA Master Collection CC 2014 Suite 1.0
CollectionFolderName : Application Management
IsExpired : Not Set
CollectionName : Adobe ETLA Master Collection CC 2014 Suite 1.0
PackageID : 001FC
CollectionID : 0022D
ProgramName : Uninstall
.INPUTS
Packagedetail
SiteServer
Sitecode
.OUTPUTS
AdvertisementName
ExpirationTime
AdvertisementID
PackageID
Comment
Softwarename
IsExpired
CollectionID
CollectionName
PresentTime
ProgramName
FolderName
.NOTES
This function would be useful only in SCCM perspective when the values are pulled from database
.ROLE
Role is to Pull the deployment information from SCCM for the specified collection
.FUNCTIONALITY
Using the Folder name, Fetches deployment information for the collections specified
#>
[CmdletBinding(DefaultParameterSetName='Parameter Set 1',
PositionalBinding=$false)]
Param
(
# Folder Name
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false,
Position=0,
ParameterSetName='Parameter Set 1')]
[ValidateNotNullOrEmpty()]
[Alias("PackageID","PackageName")]
$Package ,
# Site server Name
[Parameter(Mandatory=$false,
Position=1,
ParameterSetName='Parameter Set 1')]
$SiteServer = "primary server name",
# Site Code of the SCCM environment
[Parameter(Mandatory=$false,
Position=2,
ParameterSetName='Parameter Set 1')]
$SiteCode = "site code"
)
Begin
{
Write-host "Script Started!!!" -ForegroundColor Green
}
Process
{
$PackageInfo = _Get-SCCMPackage[Inner_Module] -Objects $Package -SiteServer $SiteServer -SiteCode $SiteCode
$Deployment = _Get-SCCMDeploymentSummary[Inner_Module] -PackageIDs $PackageInfo -SiteServer $SiteServer -SiteCode $SiteCode
}
End
{
Return $Deployment
Write-host "Script Completed!!!" -ForegroundColor Green
}
}
Function _Get-SCCMFolderName[Inner_Module]
{
<#
.Synopsis
Collects Foldername using CollectionIDs
.DESCRIPTION
Foldernames are fetched using the CollectionIDs
.EXAMPLE
.EXAMPLE
.INPUTS
FolderName
.OUTPUTS
CollectionIDs
.NOTES
This function would be useful only in SCCM perspective when the values are pulled from database
.ROLE
Role is to Pull the Collection information from SCCM for the specified Collection
.FUNCTIONALITY
Fetches Collection information
#>
[CmdletBinding(DefaultParameterSetName='Parameter Set 1',
PositionalBinding=$false)]
Param
(
# Folder Name
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false,
Position=0,
ParameterSetName='Parameter Set 1')]
[ValidateNotNullOrEmpty()]
[Alias("Object")]
[string[]]$Objects,
# Site server Name
[Parameter(Mandatory=$false,
Position=1,
ParameterSetName='Parameter Set 1')]
$SiteServer = "primary server name",
# Site Code of the SCCM environment
[Parameter(Mandatory=$false,
Position=2,
ParameterSetName='Parameter Set 1')]
$SiteCode = "site code",
[Parameter(Mandatory=$True,
Position=3)]
[ValidateSet("SMS_Package","SMS_Query","SMS_ApplicationLatest","SMS_Collection_Device","SMS_SoftwareUpdate","SMS_TaskSequencePackage","SMS_Driver","SMS_OperatingSystemInstallPackage","SMS_ConfigurationBaselineInfo","SMS_ConfigurationItemLatest","SMS_ImagePackage ","SMS_DriverPackage","SMS_BootImagePackage","SMS_Collection_User")]
$ObjectTypeName
)
Begin
{
$CollectedID = @()
$filter = "ObjectTypeName= '$ObjectTypeName'"
}
Process
{
Foreach ($Object in $Objects)
{
$Collecting = gwmi -Namespace root\Sms\site_$SiteCode -Class SMS_ObjectContainerItem -ComputerName $SiteServer -filter $filter|
where {($_.InstanceKey -like "$Object*" )}
# If ($objectInfo -eq $null)
# {
# $pack = _Get-SCCMPackage[Inner_Module] -Objects $Object -SiteServer $SiteServer -SiteCode $SiteCode
# $coll = _Get-SCCMCollection[Inner_Module] -Objects $Object -SiteServer $SiteServer -SiteCode $SiteCode
# }
$Foldername = gwmi -Namespace root\Sms\site_$SiteCode -Class SMS_ObjectContainerNode -ComputerName $SiteServer -Filter $filter|
where {$_.ContainerNodeID -eq $Collecting.ContainerNodeID}
If ($Foldername -eq $null)
{
$value = "Maybe Parent Folder"
}
else
{
$value = $($Foldername.Name)
}
Add-Member -InputObject $Collecting -MemberType NoteProperty -Name "FolderName" -Value $value -Force
$CollectedID += $Collecting
}
}
End
{
Return $CollectedID
}
}
Function _Get-SCCMCollection[Inner_Module]
{
<#
.Synopsis
Collects CollectionIDs using Foldername
.DESCRIPTION
CollectionIDs are fetched using the foldername provided
.EXAMPLE
.EXAMPLE
.INPUTS
FolderName
.OUTPUTS
CollectionIDs
.NOTES
This function would be useful only in SCCM perspective when the values are pulled from database
.ROLE
Role is to Pull the Collection information from SCCM for the specified Folders
.FUNCTIONALITY
Fetches Collection information
#>
[CmdletBinding(DefaultParameterSetName='Parameter Set 1',
PositionalBinding=$false)]
Param
(
# Folder Name
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false,
Position=0,
ParameterSetName='Parameter Set 1')]
[ValidateNotNullOrEmpty()]
[Alias("Folder")]
$FolderName,
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false,
Position=0,
ParameterSetName='Parameter Set 2')]
[ValidateNotNullOrEmpty()]
[Alias("Collection")]
$Objects,
# Site server Name
[Parameter(Mandatory=$false,
Position=1)]
$SiteServer = "Primary server name",
# Site Code of the SCCM environment
[Parameter(Mandatory=$false,
Position=2)]
$SiteCode = "Site code"
)
Begin
{
$CollectionIDs = @()
}
Process
{
If ($FolderName)
{
$FolderIDs = gwmi -Namespace root\Sms\site_$SiteCode -Class SMS_ObjectContainerNode -ComputerName $SiteServer |
where {$_.Name -like "*$($FolderName)*"} |
select ContainerNodeID, ObjectType, ObjectTypeName, @{n="FolderName"; e={$_.Name}}
Foreach ($FolderID in $FolderIDs)
{
$CollectionIDs += gwmi -Namespace root\Sms\site_$SiteCode -Class SMS_ObjectContainerItem -ComputerName $SiteServer |
where {$_.ContainerNodeID -eq $($FolderID.ContainerNodeID)} |
Select *,@{n="FolderName";e={$FolderID.FolderName}}
}
}
If ($Objects)
{
Foreach ($Object in $Objects)
{
$CollectionIDs += gwmi -Namespace root\Sms\site_$SiteCode -Class SMS_Collection -ComputerName $SiteServer |
where {$_.CollectionID -like "*$object*" -or $_.Name -like "*$object*"} |
Select *,@{n="CollectionFolderName";e={$FolderID.FolderName}}
}
}
}
End
{
Return $CollectionIDs
}
}
Function _Get-SCCMPackage[Inner_Module]
{
<#
.Synopsis
Collects Package Information using Package ID
.DESCRIPTION
Package Information is fetched using the PackageID or Package Name
.EXAMPLE
.EXAMPLE
.INPUTS
FolderName
.OUTPUTS
CollectionIDs
.NOTES
This function would be useful only in SCCM perspective when the values are pulled from database
.ROLE
Role is to Pull the Collection information from SCCM for the specified Folders
.FUNCTIONALITY
Fetches Collection information
#>
[CmdletBinding(DefaultParameterSetName='Parameter Set 1',
PositionalBinding=$false)]
Param
(
# Name
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false,
Position=0,
ParameterSetName='Parameter Set 1')]
[ValidateNotNullOrEmpty()]
[Alias("PackageName")]
[String[]]
$Objects,
# Site server Name
[Parameter(Mandatory=$false,
Position=1,
ParameterSetName='Parameter Set 1')]
$SiteServer = "Primary server name",
# Site Code of the SCCM environment
[Parameter(Mandatory=$false,
Position=2,
ParameterSetName='Parameter Set 1')]
$SiteCode = "site code"
)
Begin
{
$Package = @()
}
Process
{
Foreach ($Object in $Objects)
{
$Output = Get-WmiObject -Namespace root\sms\site_$sitecode -Class sms_package -ComputerName $SiteServer |
Where {$_.PackageID -like "*$Object*" -or $_.Name -like "*$Object*"} |
select Name, NumOfPrograms, SourceVersion, Version, PackageID, @{n="Size in (MB)"; e={(($_.packagesize)/1024)}}
#$folder = (_Get-SCCMFolderName[Inner_Module] -Objects $output.packageID -SiteServer $SiteServer -SiteCode $SiteCode -ObjectTypeName "SMS_Package").foldername
#Add-Member -InputObject $Output -MemberType NoteProperty -Name "PackageFolderName" -Value $folder -Force
$Package += $Output
}
}
End
{
Return $Package
}
}
Function _Get-SCCMDeploymentSummary[Inner_Module]
{
<#
.Synopsis
Collects Deployment details using Collection ID information
.DESCRIPTION
Deployment Summary of all the deployments assigned to the collection obtained
.EXAMPLE
.EXAMPLE
.INPUTS
Collection
.OUTPUTS
Deployment
.NOTES
This function would be useful only in SCCM perspective when the values are pulled from database
.ROLE
Role is to Pull the deployment information from SCCM for the specified collection
.FUNCTIONALITY
Fetches deployment information
#>
[CmdletBinding(DefaultParameterSetName='Parameter Set 1',
PositionalBinding=$false)]
Param
(
# Folder Name
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false,
Position=0,
ParameterSetName='Parameter Set 1')]
[ValidateNotNullOrEmpty()]
[Alias("CollectionID")]
$CollectionIDs,
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false,
Position=0,
ParameterSetName='Parameter Set 2')]
[ValidateNotNullOrEmpty()]
[Alias("PackageID")]
$PackageIDs,
# Site server Name
[Parameter(Mandatory=$false,
Position=1)]
$SiteServer = "primary server name",
# Site Code of the SCCM environment
[Parameter(Mandatory=$false,
Position=2)]
$SiteCode = "site code"
)
Begin
{
$MYResult = @()
$deployments = @()
}
Process
{
If ($collectionIDs)
{
Foreach ($CollectionID in $CollectionIDs)
{
$Deployments += gwmi -Namespace root\Sms\site_$SiteCode -Class SMS_DeploymentSummary -ComputerName $SiteServer |
where { $_.CollectionID -eq $CollectionID.InstanceKey} |
Select *, @{n="CollectionFolderName";e={If ($CollectionID.CollectionfolderName) {$CollectionID.CollectionfolderName}Else {"No Name"}}}
}
}
If ($PackageIDs)
{
Foreach ($PackageID in $PackageIDs)
{
$Deployments += gwmi -Namespace root\Sms\site_$SiteCode -Class SMS_DeploymentSummary -ComputerName $SiteServer |
where { $_.PackageID -eq $PackageID.PackageID} |
Select *, @{n="PackageFolderName";e={If ($PackageID.folderName) {$PackageID.folderName}Else {"No Name"}}}
}
}
Foreach ($Deployment in $Deployments)
{
$DeploymentTime = $Deployment.DeploymentTime
$Deploymentresult = gwmi -Namespace root\Sms\site_$SiteCode -Class SMS_Advertisement -ComputerName $SiteServer |
where { $_.CollectionID -eq $Deployment.CollectionID -and $_.advertisementID -eq $Deployment.DeploymentID} |
Select PackageID, ProgramName, AdvertisementName, PresentTime, ExpirationTime, Comment, CollectionID , @{n="IsExpired"; e={If((_Convert-datestring[Inner_Module] $_.ExpirationTime) -eq (_Convert-datestring[Inner_Module] $_.PresentTime)) {"Not Set"} Elseif ((_Convert-datestring[Inner_Module] $_.ExpirationTime) -lt (get-date) ) {"Yes"} Else {"No"}}}
if ($Deploymentresult)
{
$collectionfoldername = If ($Deployment.CollectionFolderName) {$Deployment.CollectionFolderName} else {(_Get-SCCMFolderName[Inner_Module] -Objects $Deploymentresult.CollectionID -SiteServer $SiteServer -SiteCode $SiteCode -ObjectTypeName "SMS_Collection_Device").foldername}
$PackageFoldername = If ($Deployment.PackageFolderName) {$Deployment.PackageFolderName} else {(_Get-SCCMFolderName[Inner_Module] -Objects $Deploymentresult.packageID -SiteServer $SiteServer -SiteCode $SiteCode -ObjectTypeName "SMS_Package").foldername}
$ObjectProperty = ""
$ObjectProperty = @{
DeploymentID = $Deployment.DeploymentID
CollectionID = $Deployment.CollectionID
CollectionName = $Deployment.CollectionName
PackageID = $Deploymentresult.PackageID
ProgramName = $Deploymentresult.ProgramName
AdvertisementName = $Deploymentresult.AdvertisementName
PresentTime = _Convert-datestring[Inner_Module] $Deploymentresult.PresentTime
ExpirationTime = _Convert-datestring[Inner_Module] $Deploymentresult.ExpirationTime
Comment = $Deploymentresult.Comment
IsExpired = $Deploymentresult.IsExpired
Softwarename = $Deployment.SoftwareName
CollectionFolderName = $collectionFoldername
PackageFolderName = $PackageFoldername
}
$Object = New-Object PSObject -Property $ObjectProperty
$MYResult += $Object
}
}
}
End
{
Return $MYResult
}
}
Function _Convert-datestring[Inner_Module]
{
<#
.Synopsis
Convert a string to date time
.DESCRIPTION
Date information is stored as string in database, we were unable to compare ot with the current date so we have to convert it to Datetime format
.EXAMPLE
PS C:\> _Convert-datestring[Inner_Module] "20140708080000.000000+***"
Tuesday, July 08, 2014 8:00:00 AM
.INPUTS
Datestring
.OUTPUTS
Date
.NOTES
This function would be useful only in SCCM perspective when the values are pulled from database
.ROLE
Role is to convert the string format date value to date
.FUNCTIONALITY
Converts string to date Time
#>
[CmdletBinding(DefaultParameterSetName='Parameter Set 1')]
[OutputType([DateTime])]
Param
(
# Datestring which needs to be converted
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
Position=0,
ParameterSetName='Parameter Set 1')]
[ValidateNotNullOrEmpty()]
[Alias("String")]
$DateString
)
begin
{
$a = $datestring
Write-Debug "Assigning value to `$a - $a"
$a = $a.Remove($a.LastIndexOf("."))
Write-Debug "Removing the values after '.', so `$a - $a"
$b = $a.tochararray()
Write-Debug "Converting the string into array as i have some issues in using them, so `$b - $b"
}
Process
{
Write-Debug "Grouping all values to form a Date and Time"
$Splittime = @{
Year = [int]$a.Remove(4)
Month = [int]"$($b[4])$($b[5])"
Day = [int]"$($b[6])$($b[7])"
Hour = [int]"$($b[8])$($b[9])"
Minute = [int]"$($b[10])$($b[11])"
Second = [int]"$($b[12])$($b[13])"
}
$ExpirationTime = [datetime] "$($Splittime.year)/$($Splittime.month)/$($Splittime.day) $($Splittime.hour):$($Splittime.minute):$($Splittime.second)"
Write-Debug "Assigned all values and converted to Date time, the output is `n $ExpirationTime"
}
End
{
Write-Debug "Returning ExpirationTime!"
return $ExpirationTime
}
#Date Property datetime Date {get;}
#Day Property int Day {get;}
#DayOfWeek Property System.DayOfWeek DayOfWeek {get;}
#DayOfYear Property int DayOfYear {get;}
#Hour Property int Hour {get;}
#Kind Property System.DateTimeKind Kind {get;}
#Millisecond Property int Millisecond {get;}
#Minute Property int Minute {get;}
#Month Property int Month {get;}
#Second Property int Second {get;}
#Ticks Property long Ticks {get;}
#TimeOfDay Property timespan TimeOfDay {get;}
#Year Property int Year {get;}
}
No comments:
Post a Comment