Thursday, September 7, 2017

Powershell script to get the all deployment report from SCCM 2012

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;}
}

Batch file to repair the WMI for SCCM client


Below is the batch file to repair the WMI for SCCM client


net stop ccmexec /y

if not exist c:\windows\syswow64 goto x86
If exist c:\windows\syswow64 GOTO x64

:x86
cd /d %windir%\System32\Wbem
net stop winmgmt /y

REM REG IMPORT %windir%\WBEM.reg

winmgmt /clearadap
winmgmt /kill
winmgmt /unregserver
winmgmt /regserver
winmgmt /resyncperf

del %windir%\System32\Wbem\Repository /Q
echo
del %windir%\System32\Wbem\AutoRecover /Q

for %%i in (*.dll) do Regsvr32 -s %%i
for %%i in (*.mof,*.mfl) do Mofcomp %%i
wmiadap.exe /Regsvr32
wmiapsrv.exe /Regsvr32
wmiprvse.exe /Regsvr32

net start winmgmt

net start ccmexec

:x64
cd /d %windir%\Syswow64\Wbem
winmgmt /salvagerepository
net stop winmgmt /y

REM REG IMPORT %windir%\WBEM.reg

winmgmt /clearadap
winmgmt /kill
winmgmt /unregserver
winmgmt /regserver
winmgmt /resyncperf

del %windir%\System32\Wbem\Repository /Q
echo
del %windir%\System32\Wbem\AutoRecover /Q

for %%i in (*.dll) do Regsvr32 -s %%i
for %%i in (*.mof,*.mfl) do Mofcomp %%i
wmiadap.exe /Regsvr32
wmiapsrv.exe /Regsvr32
wmiprvse.exe /Regsvr32

net start winmgmt

net start ccmexec

Batch file to wipe the SCCM client on the machine

Below is the batch file to wipe the SCCM client on the machine



@echo off
echo Please Wait while the system is uninstalling Microsoft's SMS/SCCM Client.

echo Checking for SCCM 2007 client...
IF EXIST %windir%\System32\ccmsetup\ccmsetup.exe GOTO DEL07
echo No SCCM 2007 client found.

echo Checking for SCCM client in 64bit...
IF EXIST %windir%\ccmsetup\ccmsetup.exe GOTO DEL12
echo No SCCM 2012 client found.

echo Checking for SMSCFG file...
IF EXIST %windir%\SMSCFG.INI GOTO DELINI
echo No SMSCFG file found.
echo All software already removed or no client installed.

GOTO END

:DEL07
echo Found SCCM Client v2007. Removing...
%windir%\System32\ccmsetup\ccmsetup.exe /uninstall
RD /S /Q %windir%\System32\ccmsetup
RD /S /Q %windir%\System32\ccm\cache
RD /S /Q %windir%\System32\ccm
echo SCCM Client 2007 removed.
IF EXIST %windir%\ccmsetup\ccmsetup.exe GOTO DEL12
IF EXIST %windir%\SMSCFG.INI GOTO DELINI
GOTO END

:DEL12
echo Found SCCM client in 64bit. Removing.
%windir%\ccmsetup\ccmsetup.exe /uninstall
RD /S /Q %windir%\ccmsetup
RD /S /Q %windir%\SysWOW64\ccm\cache
RD /S /Q %windir%\SysWOW64\ccm
echo SCCM Client in 64bit removed.
REG DELETE "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\CCMSetup" /F
REG DELETE "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\ccm" /F
REG DELETE "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\SMS" /F

IF EXIST %windir%\SMSCFG.INI GOTO DELINI
GOTO END

:DELINI
echo SMSCFG file found. Removing...
del /F %windir%\SMSCFG.INI
echo SMSCFG file removed.
GOTO END

:END
REG DELETE "HKLM\software\Microsoft\ccm" /F
REG DELETE "HKLM\software\Microsoft\CCMSETUP" /F
REG DELETE "HKLM\software\Microsoft\SMS" /F
echo Done!
rem I always put a pause for testing. derem and you can see the text fly by.
exit




SCCM Application Deployment Tool

SCCM Application Deployment Tool Streamlining SCCM Application Deployments: Introducing the SCCM Application Deployment Tool. In the realm o...