SCCM Tools

I have just completed a new tool to add to my tool box, SCCM Tools. SCCM Tools is a single executable that can help me to gather some information about a SCCM site or do some basic administration tasks. The tool is portable can be ran from a flash drive or a network location.

To use the tool launch the exe file with an account that has access to the sit. Then you will be shown a page that where you can type the site information. If you have the SCCM console installed on the computer you are running the tool from you can check the box to the right of the Site Code. Other wise the tool will use the resources needed from the Site Server.



Once you connect to a site you will be presented with the Read Me landing page. This page simply tells you what you can do with the tool. Notice the black bar at the bottom of the tool will tell you the status of the action you performed, letting you know when it is safe to perform your next task.


You can get the PowerShell script that creates the tool below or you can download the tool from the Tools Download Page.



<#
.SYNOPSIS
A Tool to help a SCCM Admin find info about a SCCM Site and do some basic tasks

.DESCRIPTION
The Tool can gather info about a site such as administrationrs and roles installed in the site. The tool is 
also able to create a collection and add devices to a collection. 

.NOTES
Created By: Kris Gross
Contact: KrisGross@sccmtst.com
Twitter: @kmgamd
Version 1.0.2.1

.LINK
http://sccmtst.com

#>

Param(
    $Global:SiteServer,
    $Global:SiteCode,
    $InstallLocation = "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\",
    [switch]$LoadLocal
    )


#Sets the version 
$Global:Version = "SCCM Tools 1.0.2.1"
$Global:Date = Get-date

#Sets the Main form for the GUI
Function Start-MainForm
{   
    #Needed for the form to show
    Add-Type -AssemblyName System.Windows.Forms
    Add-Type -AssemblyName System.Drawing
    
    #Variables for form objects
    $ButtonSize = New-Object System.Drawing.Size(75,23)
    $CheckBoxSize = New-Object System.Drawing.Size(50,23)
    $TextBoxFont = 'Lucida Console'
    $ButtonColor = "CadetBlue"
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 4
    $System_Drawing_Point.Y = 22
    $System_Windows_Forms_Padding = New-Object System.Windows.Forms.Padding
    $System_Windows_Forms_Padding.All = 3
    $System_Windows_Forms_Padding.Bottom = 3
    $System_Windows_Forms_Padding.Left = 3
    $System_Windows_Forms_Padding.Right = 3
    $System_Windows_Forms_Padding.Top = 3
    #set the computer name label
    $ComputerLabel = New-Object System.Windows.Forms.Label
    $ComputerLabel.Location = New-Object System.Drawing.Point(10,20) 
    $ComputerLabel.Size = New-Object System.Drawing.Size(280,20) 
    $ComputerLabel.Text = "Please enter the computer name:"

    #Set the standrads of the form window
    $form = New-Object System.Windows.Forms.Form 
    $form.Text = $Version
    $form.Size = New-Object System.Drawing.Size(700,440) 
    $form.StartPosition = "CenterScreen"
    $form.BackColor = "Black"
    $Icon = [system.drawing.icon]::ExtractAssociatedIcon($PSScriptRoot + "\SCCMTools.exe")
    $Form.Icon = $Icon
    $Form.MaximizeBox = $False
    $Form.SizeGripStyle = "Hide"

    #Creates the Tab form
    $TabForm = New-Object System.Windows.Forms.TabControl
    $TabForm.DataBindings.DefaultDataSourceUpdateMode = 0
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 0
    $System_Drawing_Point.Y = 0
    $TabForm.Location = $System_Drawing_Point
    $TabForm.Name = "tabControl"
    $TabForm.SelectedIndex = 0
    $TabForm.ShowToolTips = $True
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 370
    $System_Drawing_Size.Width = 700
    $TabForm.Size = $System_Drawing_Size

    #Site Info tab
    $SetSiteInfoTab= New-Object System.Windows.Forms.TabPage
    $SetSiteInfoTab.DataBindings.DefaultDataSourceUpdateMode = 0
    $SetSiteInfoTab.Location = $System_Drawing_Point
    $SetSiteInfoTab.Name = "Connect to Site"
    $SetSiteInfoTab.Padding = $System_Windows_Forms_Padding
    $SetSiteInfoTab.Text = "Connect to Site"
    #Create the Set Info button
    $SetSiteButton = New-Object System.Windows.Forms.Button
    $SetSiteButton.Location = New-Object System.Drawing.Point(25,130)
    $SetSiteButton.Size = $ButtonSize
    $SetSiteButton.Text = "Connect"
    $SetSiteButton.Add_Click({Click_SetSite})
    #label for the site code
    $Sitelabel = New-Object System.Windows.Forms.Label
    $Sitelabel.Location = New-Object System.Drawing.Point(10,20) 
    $Sitelabel.Size = New-Object System.Drawing.Size(280,20) 
    $Sitelabel.Text = "Please enter the Site Code:"
    #Box to enter site code
    $SiteCodeTextBox = New-Object System.Windows.Forms.TextBox 
    $SiteCodeTextBox.Location = New-Object System.Drawing.Point(15,42) 
    $SiteCodeTextBox.Size = New-Object System.Drawing.Size(50,20)
    $SiteCodeTextBox.MaxLength = 3
    #Site server label
    $Serverlabel = New-Object System.Windows.Forms.Label
    $Serverlabel.Location = New-Object System.Drawing.Point(10,70) 
    $Serverlabel.Size = New-Object System.Drawing.Size(280,20) 
    $Serverlabel.Text = "Please enter Site Server name:"
    #Box to enter site server
    $SiteServerTextBox = New-Object System.Windows.Forms.TextBox 
    $SiteServerTextBox.Location = New-Object System.Drawing.Point(15,90) 
    $SiteServerTextBox.Size = New-Object System.Drawing.Size(250,20) 
    #Sets the load local check box 
    $LocalCheckBox = New-Object System.Windows.Forms.Checkbox
    $LocalCheckBox.Location = New-Object System.Drawing.Point(310,45)
    $LocalCheckbox.Size = new-object System.Drawing.Size(105,52)
    $LocalCheckbox.Text = "Check this box if you have the SCCM Console installed."
    $LocalCheckbox.Checked = $False
    
    #Device Info tab
    $DeviceInfoTab = New-Object System.Windows.Forms.TabPage
    $DeviceInfoTab.DataBindings.DefaultDataSourceUpdateMode = 0
    $DeviceInfoTab.Location = $System_Drawing_Point
    $DeviceInfoTab.Name = "Get Device Info"
    $DeviceInfoTab.Padding = $System_Windows_Forms_Padding
    $DeviceInfoTab.Text = "Get Device Info"
    #Sets the Get Info button
    $GetInfoButton = New-Object System.Windows.Forms.Button
    $GetInfoButton.Location = New-Object System.Drawing.Point(300,30)
    $GetInfoButton.Size = $ButtonSize
    $GetInfoButton.Text = "Get Info"
    $GetInfoButton.Add_Click({Click_DeviceInfoResults})
    #sets the export button
    $DeviceInfoExportButton = New-Object System.Windows.Forms.Button
    $DeviceInfoExportButton.Location = New-Object System.Drawing.Point(50,280)
    $DeviceInfoExportButton.Size = $ButtonSize
    $DeviceInfoExportButton.Text = "Export"
    $DeviceInfoExportButton.Add_Click({Click_DeviceInfoExport})
    #sets the clear Button
    $DeviceInfoClearButton = New-Object System.Windows.Forms.Button
    $DeviceInfoClearButton.Location = New-Object System.Drawing.Point(200,280)
    $DeviceInfoClearButton.Size = $ButtonSize
    $DeviceInfoClearButton.Text = "Clear"
    $DeviceInfoClearButton.Add_Click({Click_DeviceInfoClear})
    #Sets the check box
    $DeviceInfoCheckBox = New-Object System.Windows.Forms.Checkbox
    $DeviceInfoCheckBox.Location = New-Object System.Drawing.Point(400,15)
    $DeviceInfoCheckBox.Size = new-object System.Drawing.Size(105,52)
    $DeviceInfoCheckBox.Text = "Get Device Collection Membership."
    $DeviceInfoCheckBox.Checked = $False
    #set the Computer entry box
    $DeviceInfoComputerBox = New-Object System.Windows.Forms.TextBox 
    $DeviceInfoComputerBox.Location = New-Object System.Drawing.Point(10,40) 
    $DeviceInfoComputerBox.Size = New-Object System.Drawing.Size(260,20) 
    #sets the area where the computer info will be shown
    $DeviceInfoInfoBox = New-Object System.Windows.Forms.ListBox
    $DeviceInfoInfoBox.Size = New-Object System.Drawing.Point(365,170)
    $DeviceInfoInfoBox.Location = New-Object System.Drawing.Point(10,100)
    $DeviceInfoInfoBox.HorizontalScrollbar = $true
    
    #Add Device Tab
    $AddDeviceTab = New-Object System.Windows.Forms.TabPage
    $AddDeviceTab.DataBindings.DefaultDataSourceUpdateMode = 0
    $AddDeviceTab.Location = $System_Drawing_Point
    $AddDeviceTab.Name = "Add Device to Collection"
    $AddDeviceTab.Padding = $System_Windows_Forms_Padding
    $AddDeviceTab.Text = "Add Device to Collection"
    #sets the button to get sccm collections
    $GetCollectionsButton = New-Object System.Windows.Forms.Button
    $GetCollectionsButton.Location = New-Object System.Drawing.Point(300,120)
    $GetCollectionsButton.Size = $ButtonSize
    $GetCollectionsButton.Text = "OK"
    $GetCollectionsButton.Add_Click({Click_GetCollections})
    #Sets the box for the collection filter
    $GetCollectionsBox = New-Object System.Windows.Forms.TextBox 
    $GetCollectionsBox.Location = New-Object System.Drawing.Point(10,120) 
    $GetCollectionsBox.Size = New-Object System.Drawing.Size(260,20)
    #sets the label for the filter
    $GetCollectionlabel = New-Object System.Windows.Forms.Label
    $GetCollectionlabel.Location = New-Object System.Drawing.Point(10,20) 
    $GetCollectionlabel.Size = New-Object System.Drawing.Size(290,30) 
    $GetCollectionlabel.Font = "Tahoma"
    $GetCollectionlabel.Text = "Click ok to start the process of getting the Collections you can add a device to"
    #sets the second label for the filter
    $GetCollectionlabel2 = New-Object System.Windows.Forms.Label
    $GetCollectionlabel2.Location = New-Object System.Drawing.Point(10,60) 
    $GetCollectionlabel2.Size = New-Object System.Drawing.Size(310,40)
    $GetCollectionlabel2.Font = "Tahoma"
    $GetCollectionlabel2.Text = "You can filter the Collections by keywords using * as a wildcard. If you want to see all Collections type *"

    #Adds the Site info tab
    $SiteInfoTab = New-Object System.Windows.Forms.TabPage
    $SiteInfoTab.DataBindings.DefaultDataSourceUpdateMode = 0
    $SiteInfoTab.Location = $System_Drawing_Point
    $SiteInfoTab.Name = "Site Info"
    $SiteInfoTab.Padding = $System_Windows_Forms_Padding
    $SiteInfoTab.Text = "Site Info"
    #Sets the Get Info button
    $GetSiteInfoButton = New-Object System.Windows.Forms.Button
    $GetSiteInfoButton.Location = New-Object System.Drawing.Point(510,40)
    $GetSiteInfoButton.Size = $ButtonSize
    $GetSiteInfoButton.Text = "Get Info"
    $GetSiteInfoButton.Add_Click({Click_GetSiteInfo})
    #sets the export button
    $SiteInfoExportButton = New-Object System.Windows.Forms.Button
    $SiteInfoExportButton.Location = New-Object System.Drawing.Point(510,140)
    $SiteInfoExportButton.Size = $ButtonSize
    $SiteInfoExportButton.Text = "Export"
    $SiteInfoExportButton.Add_Click({Click_ExportSiteInfo})
    #sets the clear Button
    $SiteInfoClearButton = New-Object System.Windows.Forms.Button
    $SiteInfoClearButton.Location = New-Object System.Drawing.Point(510,240)
    $SiteInfoClearButton.Size = $ButtonSize
    $SiteInfoClearButton.Text = "Clear"
    $SiteInfoClearButton.Add_Click({Click_SiteInfoClear})
    #sets the area where the computer info will be shown
    $SiteInfoInfoBox = New-Object System.Windows.Forms.ListBox
    $SiteInfoInfoBox.Size = New-Object System.Drawing.Point(350,330)
    $SiteInfoInfoBox.Location = New-Object System.Drawing.Point(10,10)
    $SiteInfoInfoBox.HorizontalScrollbar = $true

    #Adds the Site Collections Tab
    $SiteCollectionsTab = New-Object System.Windows.Forms.TabPage
    $SiteCollectionsTab.DataBindings.DefaultDataSourceUpdateMode = 0
    $SiteCollectionsTab.Location = $System_Drawing_Point
    $SiteCollectionsTab.Name = "Site Collections"
    $SiteCollectionsTab.Padding = $System_Windows_Forms_Padding
    $SiteCollectionsTab.Text = "Site Collections"
    #Sets the Get Info button
    $GetSiteCollectionsButton = New-Object System.Windows.Forms.Button
    $GetSiteCollectionsButton.Location = New-Object System.Drawing.Point(510,40)
    $GetSiteCollectionsButton.Size = New-Object System.Drawing.Size(90,23)
    $GetSiteCollectionsButton.Text = "Get Collections"
    $GetSiteCollectionsButton.Add_Click({Click_GetSiteColelctions})
    #sets the export button
    $SiteCollectionsExportButton = New-Object System.Windows.Forms.Button
    $SiteCollectionsExportButton.Location = New-Object System.Drawing.Point(510,140)
    $SiteCollectionsExportButton.Size = $ButtonSize
    $SiteCollectionsExportButton.Text = "Export"
    $SiteCollectionsExportButton.Add_Click({Click_ExportSiteCollections})
    #sets the area where the computer info will be shown
    $SiteCollectionsInfoBox = New-Object System.Windows.Forms.ListBox
    $SiteCollectionsInfoBox.Size = New-Object System.Drawing.Point(350,330)
    $SiteCollectionsInfoBox.Location = New-Object System.Drawing.Point(10,10)
    $SiteCollectionsInfoBox.HorizontalScrollbar = $true

    #Adds the Site Component Status Tab
    $DeviceComponentStatusTab = New-Object System.Windows.Forms.TabPage
    $DeviceComponentStatusTab.DataBindings.DefaultDataSourceUpdateMode = 0
    $DeviceComponentStatusTab.Location = $System_Drawing_Point
    $DeviceComponentStatusTab.Name = "Component Status"
    $DeviceComponentStatusTab.Padding = $System_Windows_Forms_Padding
    $DeviceComponentStatusTab.Text = "Component Status"
    #Sets the Get component status button
    $GetDeviceComponentStatusButton = New-Object System.Windows.Forms.Button
    $GetDeviceComponentStatusButton.Location = New-Object System.Drawing.Point(25,315)
    $GetDeviceComponentStatusButton.Size = New-Object System.Drawing.Size(85,23)
    $GetDeviceComponentStatusButton.Text = "Get Messages"
    $GetDeviceComponentStatusButton.Add_Click({Click_GetComponentStatus})
    #Sets the export component status button
    $ExportDeviceComponentStatusButton = New-Object System.Windows.Forms.Button
    $ExportDeviceComponentStatusButton.Location = New-Object System.Drawing.Point(180,315)
    $ExportDeviceComponentStatusButton.Size = $ButtonSize
    $ExportDeviceComponentStatusButton.Text = "Export"
    $ExportDeviceComponentStatusButton.Add_Click({Click_ExportComponentStatus})
    #Sets the clear component status button
    $ClearDeviceComponentStatusButton = New-Object System.Windows.Forms.Button
    $ClearDeviceComponentStatusButton.Location = New-Object System.Drawing.Point(335,315)
    $ClearDeviceComponentStatusButton.Size = $ButtonSize
    $ClearDeviceComponentStatusButton.Text = "Clear"
    $ClearDeviceComponentStatusButton.Add_Click({Click_ClearComponentStatus})
    #Sets the component status info box
    $DeviceComponentStatusTextBox = New-Object System.Windows.Forms.TextBox
    $DeviceComponentStatusTextBox.Location = New-Object System.Drawing.Point(10,50) 
    $DeviceComponentStatusTextBox.Size = New-Object System.Drawing.Size(655,250)
    $DeviceComponentStatusTextBox.ReadOnly = $True
    $DeviceComponentStatusTextBox.Multiline = $True
    $DeviceComponentStatusTextBox.Font = $TextBoxFont
    $DeviceComponentStatusTextBox.Text = ""
    $DeviceComponentStatusTextBox.ScrollBars = "Vertical"
    #Sets the label for message selection box
    $ComponentStatusMessageLabel = New-Object System.Windows.Forms.Label
    $ComponentStatusMessageLabel.Location = New-Object System.Drawing.Point(10,10)
    $ComponentStatusMessageLabel.Size = New-Object System.Drawing.Size(50,40)
    $ComponentStatusMessageLabel.Text = "Message type"
    #Sets the label for the group by selection box
    $ComponentStatusGroupByLabel = New-Object System.Windows.Forms.Label
    $ComponentStatusGroupByLabel.Location = New-Object System.Drawing.Point(200,10)
    $ComponentStatusGroupByLabel.Size = New-Object System.Drawing.Size(50,40)
    $ComponentStatusGroupByLabel.Text = "Group By"
    #Sets the label for the filter box
    $ComponentStatusFilterLabel = New-Object System.Windows.Forms.Label
    $ComponentStatusFilterLabel.Location = New-Object System.Drawing.Point(380,10)
    $ComponentStatusFilterLabel.Size = New-Object System.Drawing.Size(80,40)
    $ComponentStatusFilterLabel.Text = "Filter computer name"
    #Sets the filter box 
    $ComponentStatusFilterBox = New-Object System.Windows.Forms.TextBox 
    $ComponentStatusFilterBox.Location = New-Object System.Drawing.Point(465,10) 
    $ComponentStatusFilterBox.Size = New-Object System.Drawing.Size(200,20)
    $ComponentStatusFilterBox.Text = ""
    #Sets the selection box for message type
    $ComponentStatusSeveritySelect = New-Object System.Windows.Forms.ComboBox
    $ComponentStatusSeveritySelect.Location = New-Object System.Drawing.Point(70,10)
    $ComponentStatusSeveritySelect.Size = New-Object System.Drawing.Size(75,20)
    $ComponentStatusSeveritySelect.DropDownStyle = "DropDownList"
    Foreach ($item in ("","Error", "Warning","Information"))
    {
        $ComponentStatusSeveritySelect.Items.Add($item) | Out-Null
    }
    #Sets the selection box for the grouping options
    $ComponentStatusGroupBySelect = New-Object System.Windows.Forms.ComboBox
    $ComponentStatusGroupBySelect.Location = New-Object System.Drawing.Point(250,10)
    $ComponentStatusGroupBySelect.Size = New-Object System.Drawing.Size(110,20)
    $ComponentStatusGroupBySelect.DropDownStyle = "DropDownList"
    Foreach ($item in ("","Component","MachineName", "MessageID","Time"))
    {
        $ComponentStatusGroupBySelect.Items.Add($item) | Out-Null
    }

    #Adds the Read Me tab
    $ReadMeTab = New-Object System.Windows.Forms.TabPage
    $ReadMeTab.DataBindings.DefaultDataSourceUpdateMode = 0
    $ReadMeTab.Location = $System_Drawing_Point
    $ReadMeTab.Name = "Read Me"
    $ReadMeTab.Padding = $System_Windows_Forms_Padding
    $ReadMeTab.Text = "Read Me"
    #Read me heading label
    $ReadMeHeadingLabel = New-Object System.Windows.Forms.Label
    $ReadMeHeadingLabel.Location = New-Object System.Drawing.Point(235,10)
    $ReadMeHeadingLabel.Size = New-Object System.Drawing.Size(350,40)
    $ReadMeHeadingLabel.Text = "SCCM Tools"
    $ReadMeHeadingLabel.Font = New-Object System.Drawing.Font("Tahoma",24)
    #Read me label 1
    $ReadMeLabel1 = New-Object System.Windows.Forms.Label
    $ReadMeLabel1.Location = New-Object System.Drawing.Point(110,55)
    $ReadMeLabel1.Size = New-Object System.Drawing.Size(410,32)
    $ReadMeLabel1.Text = "This set of tools is used to help a SCCM admin do some daily tasks or gather info about a new site"
    $ReadMeLabel1.Font = "Tahoma"
    #Read me label 2
    $ReadMeLabel2 = New-Object System.Windows.Forms.Label
    $ReadMeLabel2.Location = New-Object System.Drawing.Point(110,95)
    $ReadMeLabel2.Size = New-Object System.Drawing.Size(410,20)
    $ReadMeLabel2.Text = "At this time you can do the following:"
    $ReadMeLabel2.Font = "Tahoma"
    #Read me lable 3
    $ReadMeLabel3 = New-Object System.Windows.Forms.Label
    $ReadMeLabel3.Location = New-Object System.Drawing.Point(110,112)
    $ReadMeLabel3.Size = New-Object System.Drawing.Size(410,85)
    $ReadMeLabel3.Text = "Add a device to a collection`nGet device info`nGet info about the site`nGet the component status of devices`nGet all collections in a site`nCreate a device collection"
    $ReadMeLabel3.Font = "Tahoma"

    $ReadMeLabel4 = New-Object System.Windows.Forms.Label
    $ReadMeLabel4.Location = New-Object System.Drawing.Point(110,210)
    $ReadMeLabel4.Size = New-Object System.Drawing.Size(400,50)
    $ReadMeLabel4.Text = "You can find updates to this tool and other information at`nsccmtst.com"
    $ReadMeLabel4.Font = "Tahoma"
    #Read me donate button
    $ReadMeButton = New-Object System.Windows.Forms.Button
    $ReadMeButton.Location = New-Object System.Drawing.Point(200,300)
    $ReadMeButton.Size = New-Object System.Drawing.Size(275,35)
    $ReadMeButton.Text = "Donate"
    $ReadMeButton.Font = "Tahoma"
    $ReadMeButton.Add_Click({Click_Donate})

    #Create Collection Tab
    $CreateCollectionTab = New-Object System.Windows.Forms.TabPage
    $CreateCollectionTab.DataBindings.DefaultDataSourceUpdateMode = 0
    $CreateCollectionTab.Location = $System_Drawing_Point
    $CreateCollectionTab.Name = "Create Collections"
    $CreateCollectionTab.Padding = $System_Windows_Forms_Padding
    $CreateCollectionTab.Text = "Create Collections"
    #Create a Collection Label
    $CreateCollectionLabel = New-Object System.Windows.Forms.Label
    $CreateCollectionLabel.Location = New-Object System.Drawing.Point(10,25)
    $CreateCollectionLabel.Size = New-Object System.Drawing.Size(150,23)
    $CreateCollectionLabel.Text = "Collection Name"
    $CreateCollectionLabel.Font = "Tahoma"
    
    $Global:CreateCollectionCollectionBox = New-Object System.Windows.Forms.TextBox
    $Global:CreateCollectionCollectionBox.Location = New-Object System.Drawing.Point(10,50)
    $Global:CreateCollectionCollectionBox.Size = New-Object System.Drawing.Size(250,32)
    $Global:CreateCollectionCollectionBox.Text = ""

    $CreateCollectionCheckBox = New-Object System.Windows.Forms.CheckBox
    $CreateCollectionCheckBox.Location = New-Object System.Drawing.Point(10,75)
    $CreateCollectionCheckBox.Size = New-Object System.Drawing.Size(250,23)
    $CreateCollectionCheckBox.Text = "Create Collections based on a list"
    $CreateCollectionCheckBox.Checked = $False
    $CreateCollectionCheckBox.Add_CheckStateChanged({IF($CreateCollectionCheckBox.Checked) {$CreateCollectionBrowseButton.Visible = $True}})
    $CreateCollectionCheckBox.Add_CheckStateChanged({IF(!($CreateCollectionCheckBox.Checked)) {$CreateCollectionBrowseButton.Visible = $False}})

    $CreateCollectionBrowseButton = New-Object System.Windows.Forms.Button
    $CreateCollectionBrowseButton.Location = New-Object System.Drawing.Point(300,45)
    $CreateCollectionBrowseButton.Size = $ButtonSize
    $CreateCollectionBrowseButton.Text = "Browse"
    $CreateCollectionBrowseButton.Visible = $False
    $CreateCollectionBrowseButton.Add_Click({Click_CreateCollectionBrowse})

    $ChooseScheduleLabel = New-Object System.Windows.Forms.Label
    $ChooseScheduleLabel.Location = New-Object System.Drawing.Point(10,105)
    $ChooseScheduleLabel.Size = New-Object System.Drawing.Size(190,20)
    $ChooseScheduleLabel.Text = "Refresh Schedule Type"

    #Sets the selection box for the Update type options
    $ScheduletypeSelect = New-Object System.Windows.Forms.ComboBox
    $ScheduletypeSelect.Location = New-Object System.Drawing.Point(10,125)
    $ScheduletypeSelect.Size = New-Object System.Drawing.Size(110,20)
    $ScheduletypeSelect.DropDownStyle = "DropDownList"
    Foreach ($item in ("","Days","Hours", "Minutes", "Continuous"))
    {
        $ScheduletypeSelect.Items.Add($item) | Out-Null
    }
    $ScheduletypeSelect.Add_SelectedIndexChanged(
        {
            If($ScheduletypeSelect.Text -eq "Days"){
                $ScheduletypeLabel.Text = "How many days between refresh"
                $ScheduletypeParam.Visible = $True
            }
            IF($ScheduletypeSelect.Text -eq "Hours"){
                $ScheduletypeLabel.Text = "How many hours between refesh"
                $ScheduletypeParam.Visible = $True
            }
            If($ScheduletypeSelect.Text -eq "Minutes"){
                $ScheduletypeLabel.Text = "How many minutes between refresh"
                $ScheduletypeParam.Visible = $True
            }
            IF($ScheduletypeSelect.Text -eq ""){
                $ScheduletypeLabel.Text = ""
                $ScheduletypeParam.Visible = $False
            }
            IF($ScheduletypeSelect.Test -eq "Continuous"){
                $ScheduletypeLabel.Text = ""
                $ScheduletypeParam.Visible = $False
            }
        })
        

    $ScheduletypeLabel = New-Object System.Windows.Forms.Label
    $ScheduletypeLabel.Location = New-Object System.Drawing.Point(135,125)
    $ScheduletypeLabel.Size = New-Object System.Drawing.Size(190,20)
    $ScheduletypeLabel.Text = ""

    $ScheduletypeParam = New-Object System.Windows.Forms.TextBox
    $ScheduletypeParam.Location = New-Object System.Drawing.Point(325,125)
    $ScheduletypeParam.Size = New-Object System.Drawing.Size(50,20)
    $ScheduletypeParam.Text = ""
    $ScheduletypeParam.Visible = $false

    $CreateCollectionLimitingLabel = New-Object System.Windows.Forms.Label
    $CreateCollectionLimitingLabel.Location = New-Object System.Drawing.Point(10,160)
    $CreateCollectionLimitingLabel.Size = New-Object System.Drawing.Size(150,23)
    $CreateCollectionLimitingLabel.Text = "Limiting Collection"
    $CreateCollectionLimitingLabel.Font = "Tahoma"

    $CreateCollectionLimitingBox = New-Object System.Windows.Forms.TextBox
    $CreateCollectionLimitingBox.Location = New-Object System.Drawing.Point(10,180)
    $CreateCollectionLimitingBox.Size = New-Object System.Drawing.Size(250,32)
    $CreateCollectionLimitingBox.Text = ""

    $CreateCollectionCreateButton = New-Object System.Windows.Forms.Button
    $CreateCollectionCreateButton.Location = New-Object System.Drawing.Point(10,230)
    $CreateCollectionCreateButton.Size = $ButtonSize
    $CreateCollectionCreateButton.Text = "Create"
    $CreateCollectionCreateButton.Add_Click({Click_CreateCollection})

    #Shows Info at the bottom of form
    $Global:RunningLabel = New-Object System.Windows.Forms.Label
    $Global:RunningLabel.Location = New-Object System.Drawing.Point(10,380)
    $Global:RunningLabel.Size = New-Object System.Drawing.Size(680,20)
    $Global:RunningLabel.ForeColor = "LightSteelBlue"
    $Global:RunningLabel.Text = "Ready"

    #Add Items to Form
    $Form.Controls.Add($TabForm)
    $Form.Controls.Add($Global:RunningLabel)

    #Add Tabs to form
    if ((!$Global:SiteCode) -or (!$Global:SiteServer)) {$TabForm.Controls.Add($SetSiteInfoTab)}
    $TabForm.Controls.Add($ReadMeTab)
    $TabForm.Controls.Add($SiteInfoTab)
    $TabForm.Controls.Add($DeviceComponentStatusTab)
    $TabForm.Controls.Add($SiteCollectionsTab)
    $TabForm.Controls.Add($DeviceInfoTab)
    $TabForm.Controls.Add($CreateCollectionTab)
    $TabForm.Controls.Add($AddDeviceTab)
    
    #Adds Items to Tabs
    $ReadMeTab.Controls.Add($ReadMeHeadingLabel)
    $ReadMeTab.Controls.Add($ReadMeLabel1)
    $ReadMeTab.Controls.Add($ReadMeLabel2)
    $ReadMeTab.Controls.Add($ReadMeLabel3)
    $ReadMeTab.Controls.Add($ReadMeLabel4)
    $ReadMeTab.Controls.Add($ReadMeButton)

    $DeviceInfoTab.Controls.Add($ComputerLabel) 
    $DeviceInfoTab.Controls.Add($DeviceInfoClearButton)
    $DeviceInfoTab.Controls.Add($GetInfoButton)
    $DeviceInfoTab.Controls.Add($DeviceInfoComputerBox)
    $DeviceInfoTab.Controls.Add($DeviceInfoExportButton)
    $DeviceInfoTab.Controls.Add($DeviceInfoInfoBox)
    $DeviceInfoTab.Controls.Add($DeviceInfoCheckBox)

    $SetSiteInfoTab.Controls.Add($SetSiteButton)
    $SetSiteInfoTab.Controls.Add($Sitelabel)
    $SetSiteInfoTab.Controls.Add($SiteCodeTextBox)
    $SetSiteInfoTab.Controls.Add($Serverlabel)
    $SetSiteInfoTab.Controls.Add($SiteServerTextBox)
    $SetSiteInfoTab.Controls.Add($LocalCheckBox)

    $AddDeviceTab.Controls.Add($GetCollectionsButton)
    $AddDeviceTab.Controls.Add($GetCollectionsBox)
    $AddDeviceTab.Controls.Add($GetCollectionlabel)
    $AddDeviceTab.Controls.Add($GetCollectionlabel2)

    $SiteInfoTab.Controls.Add($GetSiteInfoButton)
    $SiteInfoTab.Controls.Add($SiteInfoExportButton)
    $SiteInfoTab.Controls.Add($SiteInfoClearButton)
    $SiteInfoTab.Controls.Add($SiteInfoInfoBox)

    $SiteCollectionsTab.Controls.Add($SiteCollectionsInfoBox)
    $SiteCollectionsTab.Controls.Add($GetSiteCollectionsButton)
    $SiteCollectionsTab.Controls.Add($SiteCollectionsExportButton)

    $DeviceComponentStatusTab.Controls.Add($DeviceComponentStatusTextBox)
    $DeviceComponentStatusTab.Controls.Add($ExportDeviceComponentStatusButton)
    $DeviceComponentStatusTab.Controls.Add($GetDeviceComponentStatusButton)
    $DeviceComponentStatusTab.Controls.Add($ComponentStatusSeveritySelect)
    $DeviceComponentStatusTab.Controls.Add($ComponentStatusGroupBySelect)
    $DeviceComponentStatusTab.Controls.Add($ComponentStatusMessageLabel)
    $DeviceComponentStatusTab.Controls.Add($ComponentStatusGroupByLabel)
    $DeviceComponentStatusTab.Controls.Add($ClearDeviceComponentStatusButton)
    $DeviceComponentStatusTab.Controls.Add($ComponentStatusFilterLabel)
    $DeviceComponentStatusTab.Controls.Add($ComponentStatusFilterBox)

    $CreateCollectionTab.Controls.Add($CreateCollectionLabel)
    $CreateCollectionTab.Controls.Add($Global:CreateCollectionCollectionBox)
    $CreateCollectionTab.Controls.Add($CreateCollectionCheckBox)
    $CreateCollectionTab.Controls.Add($CreateCollectionBrowseButton)
    $CreateCollectionTab.Controls.Add($CreateCollectionLimitingBox)
    $CreateCollectionTab.Controls.Add($CreateCollectionLimitingLabel)
    $CreateCollectionTab.Controls.Add($CreateCollectionCreateButton)
    $CreateCollectionTab.Controls.Add($ScheduletypeSelect)
    $CreateCollectionTab.Controls.Add($ScheduletypeLabel)
    $CreateCollectionTab.Controls.Add($ScheduletypeParam)
    $CreateCollectionTab.Controls.Add($ChooseScheduleLabel)

    #Show the Form 
    [void]$form.ShowDialog()
}

    #Actios taken when the site is set button
    Function Click_SetSite
    {
        If ((!$SiteServerTextBox.text) -or (!$SiteCodeTextBox.text))
        {
            $Global:RunningLabel.ForeColor = "Red"
            $Global:RunningLabel.Text = "ERROR: You must specify a Site Code and and Site Server"
        }
        else
        {
            $Global:SiteServer = $SiteServerTextBox.text
            $Global:SiteCode = $SiteCodeTextBox.text
            IF ($LocalCheckbox.Checked){$LoadLocal = "$True"}
            $Global:RunningLabel.Text = "Setting Site Info"
            if ($LoadLocal -eq "$True") 
            {
                Set-Location $InstallLocation
                Import-Module .\ConfigurationManager.psd1 -verbose:$false 
            }     
            else 
            {
                Import-Module \\$Global:SiteServer\SMS_$Global:SiteCode\AdminConsole\bin\ConfigurationManager.psd1 -verbose:$false
            }
            #Sets the site code so the script can connect to the site
            $site = $Global:SiteCode + ":"
            Set-Location $site
            $location = Get-Location
            $siteLocation = $site + "\"
            if (($location -like $siteLocation) -and (Get-Module ConfigurationManager)) 
            {
                $Global:RunningLabel.ForeColor = "GreenYellow"
                $Global:RunningLabel.Text = "Successfully connected to Site"
                $TabForm.Controls.Remove($SetSiteInfoTab)
            } 
            else 
            {
                $Global:RunningLabel.ForeColor = "Red"
                $Global:RunningLabel.Text = "ERROR: Could not connect to Site"
            }
        }
            
    }

    #action taken then the clear button is pressed
    function Click_DeviceInfoClear
    {   
        $DeviceInfoComputerBox.text = ""
        [void]$DeviceInfoInfoBox.Items.Clear()
    }

    #Action taken when the export button is pressed
    function Click_DeviceInfoExport
    {   
        $Comp = $DeviceInfoComputerBox.Text
        $LogFile = $Comp + "_Export.log"
        ForEach ($item in ($DeviceInfoInfoBox.Items))
            {
                Add-Content $PSScriptRoot\$LogFile $item
            }
        [void] $DeviceInfoInfoBox.Items.Clear()
        $Global:RunningLabel.Text = "Exported to $LogFile"
        [void] $DeviceInfoInfoBox.Items.Add("Export Can be found at: ")
        [void] $DeviceInfoInfoBox.Items.Add("$PSScriptRoot\$LogFile")
        
    }

    #Actions ran when the Get info button is pressed
    Function Click_DeviceInfoResults
    {   
        if ((!$Global:SiteCode) -or (!$Global:SiteServer)) 
        {
            $Global:RunningLabel.ForeColor = "Red"
            $Global:RunningLabel.Text = "ERROR: You need to conenct to a site before the tool will work"
        }
        else 
        {
            #Clears the info box of all old data
        [void]$DeviceInfoInfoBox.Items.Clear()
        if (!($DeviceInfoComputerBox.Text))
        {
            $Global:RunningLabel.ForeColor = "Red"
            $Global:RunningLabel.Text = "ERROR: You must specify a computer name"
        }
        else 
        {
            #Gets the computer number
            $Comp = $DeviceInfoComputerBox.Text
            if (Get-CMDevice -Name $Comp) 
            {   
                $Global:RunningLabel.ForeColor = "LightSteelBlue"
                $Global:RunningLabel.Text = "Gathering Device Info"
                #gets the info from the sccm server
                $ActiveTime = (Get-CMDevice -name $comp).LastActiveTime 
                
                #Adds all info to the info box
                [void] $DeviceInfoInfoBox.Items.Add("Computer Name: $comp")
                $Active = (Get-CMDevice -Name $comp).IsActive
                [void] $DeviceInfoInfoBox.Items.Add("Device Active: $Active")
                $ID = (Get-CMDevice -Name $comp).ResourceID 
                [void] $DeviceInfoInfoBox.Items.Add("Computer Resorce ID: $ID")
                $DeviceOS = (Get-CMDevice -name $comp).DeviceOS
                [void] $DeviceInfoInfoBox.Items.Add("OS: $DeviceOS")
                $MPServer = (Get-CMDevice -name $comp).LastMPServerName 
                [void] $DeviceInfoInfoBox.Items.Add("Management Point: $MPServer")
                $User = (Get-CMUserDeviceAffinity -DeviceName $comp).UniqueUserName 
                [void] $DeviceInfoInfoBox.Items.Add("Primary User: $User")
                $login = (Get-CMDevice -name $comp).ADLastLogonTime
                [void] $DeviceInfoInfoBox.Items.Add("Last Logged in: $login")
                $Hardwarescan = (Get-CMDevice -name $comp).LastHardwareScan
                [void] $DeviceInfoInfoBox.Items.Add("Hardware Scan: $Hardwarescan")
                $SoftwareScan = (Get-CMDevice -name $comp).LastSoftwareScan 
                [void] $DeviceInfoInfoBox.Items.Add("Software Scan: $SoftwareScan")
                $PolicyRequest = (Get-CMDevice -name $comp).LastPolicyRequest 
                [void] $DeviceInfoInfoBox.Items.Add("Policy Request: $PolicyRequest")
                if ($DeviceInfoCheckBox.Checked) 
                {
                    $Global:RunningLabel.ForeColor = "LightSteelBlue"
                    $Global:RunningLabel.Text = "Gathering Collection Membership"
                    [void] $DeviceInfoInfoBox.Items.Add("")
                    [void] $DeviceInfoInfoBox.Items.Add("Collections:")
                    $CMCollections = (Get-CMDeviceCollection).Name
                    foreach ($Collection in $CMCollections ){if (Get-CMCollectionMember -CollectionName "$Collection" -ResourceID $ID){[void] $DeviceInfoInfoBox.Items.Add("$Collection")}}
                }
                $Global:RunningLabel.ForeColor = "GreenYellow"
                $Global:RunningLabel.Text = "Complete"
            }
            else 
            {
                $Global:RunningLabel.ForeColor = "Red"
                $Global:RunningLabel.Text = "ERROR: $Comp cannot be found"
            }
            }
        }
        
    }

    function Set-Site 
    {
        if ($LoadLocal -eq "$True") 
        {
            Set-Location $InstallLocation
            Import-Module .\ConfigurationManager.psd1 -verbose:$false 
        }     
        else 
        {
            Import-Module \\$Global:SiteServer\SMS_$Global:SiteCode\AdminConsole\bin\ConfigurationManager.psd1 -verbose:$false
        }
        $site = $Global:SiteCode + ":"
        Set-Location $site
        $location = Get-Location
        $siteLocation = $site + "\"
        Start-MainForm
    }

    function Click_GetCollections
    {
        if ((!$Global:SiteCode) -or (!$Global:SiteServer)) 
        {
            $Global:RunningLabel.Text = "ERROR: You need to conenct to a site before the tool will work"
            $Global:RunningLabel.ForeColor = "Red"
        }
        else
        {
            $Global:RunningLabel.ForeColor = "LightSteelBlue"
            $Global:RunningLabel.Text = "Gathering Collections, Please Wait..."
            $Filter = $GetCollectionsBox.Text
            $CMCollections = (Get-CMCollection | Where-Object Name -like $Filter | Sort-Object -Property Name ).name
            
            $Global:AddDeviceButton = New-Object System.Windows.Forms.Button
            $Global:AddDeviceButton.Location = New-Object System.Drawing.Point(45,140)
            $Global:AddDeviceButton.Size = $ButtonSize
            $Global:AddDeviceButton.Text = "Add Device"
            $Global:AddDeviceButton.Add_Click({click_AddDevice})

            $Global:ClearAddDeviceButton = New-Object System.Windows.Forms.Button
            $Global:ClearAddDeviceButton.Location = New-Object System.Drawing.Point(150,140)
            $Global:ClearAddDeviceButton.Size = $ButtonSize
            $Global:ClearAddDeviceButton.Text = "Clear"
            $Global:ClearAddDeviceButton.Add_Click({click_AddDeviceClear})

            #Collection dropdown label
            $Global:AddDeviceCollectionlabel = New-Object System.Windows.Forms.Label
            $Global:AddDeviceCollectionlabel.Location = New-Object System.Drawing.Point(10,20) 
            $Global:AddDeviceCollectionlabel.Size = New-Object System.Drawing.Size(280,20) 
            $Global:AddDeviceCollectionlabel.Text = "Select a Collection:"

            #Collection Dropdown list
            $Global:objCollection = New-Object System.Windows.Forms.ComboBox
            $Global:objCollection.Location = New-Object System.Drawing.Point(10,40)
            $Global:objCollection.Size = New-Object System.Drawing.Size(305,20)
            $Global:objCollection.DropDownStyle = "DropDownList"
            Foreach ($item in ($CMCollections))
            {
                $Global:objCollection.Items.Add($item) | Out-Null
            }

            $Global:BrowseForDevicesFileButton = New-Object System.Windows.Forms.Button
            $Global:BrowseForDevicesFileButton.Location = New-Object System.Drawing.Point(350,100)
            $Global:BrowseForDevicesFileButton.Size = $ButtonSize
            $Global:BrowseForDevicesFileButton.Text = "Browse"
            $Global:BrowseForDevicesFileButton.Add_Click({click_BrowseForDeviceFile})
            $Global:BrowseForDevicesFileButton.Visible = $False

            #Sets the load local check box 
            $Global:AddDevicesFromListCheckBox = New-Object System.Windows.Forms.Checkbox
            $Global:AddDevicesFromListCheckBox.Location = New-Object System.Drawing.Point(400,25)
            $Global:AddDevicesFromListCheckBox.Size = new-object System.Drawing.Size(105,52)
            $Global:AddDevicesFromListCheckBox.Text = "Check this box if you want to add devices from a file."
            $Global:AddDevicesFromListCheckBox.Checked = $False
            $Global:AddDevicesFromListCheckBox.Add_CheckStateChanged({IF($Global:AddDevicesFromListCheckBox.Checked) {$Global:BrowseForDevicesFileButton.Visible = $True}})
            $Global:AddDevicesFromListCheckBox.Add_CheckStateChanged({IF(!($Global:AddDevicesFromListCheckBox.Checked)) {$Global:BrowseForDevicesFileButton.Visible = $False}})
            
            #Computer name textbox
            $Global:AddDeviceBox = New-Object System.Windows.Forms.TextBox 
            $Global:AddDeviceBox.Location = New-Object System.Drawing.Point(10,85) 
            $Global:AddDeviceBox.Size = New-Object System.Drawing.Size(260,20) 

            $AddDeviceTab.Controls.Remove($GetCollectionsButton)
            $AddDeviceTab.Controls.Remove($GetCollectionsBox)
            $AddDeviceTab.Controls.Remove($GetCollectionlabel)
            $AddDeviceTab.Controls.Remove($GetCollectionlabel2)
            $AddDeviceTab.Controls.Add($AddDeviceButton)
            $AddDeviceTab.Controls.Add($AddDeviceBox)
            $AddDeviceTab.Controls.Add($AddDeviceCollectionlabel)
            $AddDeviceTab.Controls.Add($objCollection)
            $AddDeviceTab.Controls.Add($ClearAddDeviceButton)
            $AddDeviceTab.Controls.Add($Global:BrowseForDevicesFileButton)
            $AddDeviceTab.Controls.Add($Global:AddDevicesFromListCheckBox)
            $Global:RunningLabel.ForeColor = "GreenYellow"
            $Global:RunningLabel.Text = "Ready to add Device"
        }
    }

    function Click_AddDevice
    {
        if ((!$Global:SiteCode) -or (!$Global:SiteServer)) 
        {
            $Global:RunningLabel.ForeColor = "Red"
            $Global:RunningLabel.Text = "ERROR: You need to conenct to a site before the tool will work"
        }
        else 
        {
            If ($Global:AddDevicesFromListCheckBox.Checked)
            {
                $Global:RunningLabel.ForeColor = "LightSteelBlue"
                $Global:RunningLabel.Text = "Adding Devices from File"
                $Collection = $objCollection.Text
                $ComputersFile = $AddDeviceBox.Text
                $CollectionID = (Get-CMDeviceCollection -Name $Collection).CollectionID
                $Computers = Get-Content $ComputersFile
                Foreach ($Computer in $Computers)
                {
                    if (Get-Cmdevice -Name $Computer)
                    {
                        #Finds the computers ResourceID so it can be added to the collection
                        $PCID = (get-cmdevice -Name $Computer).ResourceID 
                        #Checks to see if the device is already in the collection 
                        if (Get-CMCollectionMember -CollectionName "$Collection" -ResourceID $PCID) 
                        {
                            $Global:RunningLabel.ForeColor = "Yellow"
                            $Global:RunningLabel.Text = "WARNING: $Computer is already in $Collection"
                            start-sleep -s 5                       
                        }
                        else 
                        {
                            #Adds the computer to the collection
                            Add-CMDeviceCollectionDirectMembershipRule -CollectionName "$Collection" -ResourceID $PCID
                            Invoke-WmiMethod -Path "ROOT\SMS\Site_$($Global:SiteCode):SMS_Collection.CollectionId='$CollectionId'" -Name RequestRefresh -ComputerName $Global:SiteServer
                            start-sleep -s 10
                            if (Get-CMCollectionMember -CollectionName "$Collection" -ResourceID $PCID)
                            {
                                $Global:RunningLabel.ForeColor = "GreenYellow"
                                $Global:RunningLabel.Text = " SUCCESS: $Computer was added to $Collection"
                                start-sleep -s 5
                            }
                            if (!(Get-CMCollectionMember -CollectionName "$Collection" -ResourceID $PCID))
                            {
                                $Global:RunningLabel.ForeColor = "Red"
                                $Global:RunningLabel.Text = "ERROR: $Computer was not added to $Collection"
                                start-sleep -s 5
                            }
                        }
                    }
                    else 
                    {
                        $Global:RunningLabel.ForeColor = "Red"
                        $Global:RunningLabel.Text = "ERROR: $Computer cannot be found"
                    }
                }
            }
            IF(!($Global:AddDevicesFromListCheckBox.Checked))
            {
                $Global:RunningLabel.ForeColor = "LightSteelBlue"
                $Global:RunningLabel.Text = "Adding Single Device"
                $Collection = $objCollection.Text
                $Computer = $AddDeviceBox.Text
                $CollectionID = (Get-CMDeviceCollection -Name $Collection).CollectionID
                if (Get-Cmdevice -Name $Computer)
                {
                    #Finds the computers ResourceID so it can be added to the collection
                    $PCID = (get-cmdevice -Name $Computer).ResourceID 
                    #Checks to see if the device is already in the collection 
                    if (Get-CMCollectionMember -CollectionName "$Collection" -ResourceID $PCID) 
                    {
                        $Global:RunningLabel.ForeColor = "Yellow"
                        $Global:RunningLabel.Text = "WARNING: $Computer is already in $Collection"                       
                    }
                    else 
                    {   
                        #Adds the computer to the collection
                        Add-CMDeviceCollectionDirectMembershipRule -CollectionName "$Collection" -ResourceID $PCID
                        Invoke-WmiMethod -Path "ROOT\SMS\Site_$($Global:SiteCode):SMS_Collection.CollectionId='$CollectionId'" -Name RequestRefresh -ComputerName $Global:SiteServer
                        start-sleep -s 10
                        if (Get-CMCollectionMember -CollectionName "$Collection" -ResourceID $PCID)
                        {
                            $Global:RunningLabel.ForeColor = "GreenYellow"
                            $Global:RunningLabel.Text = " SUCCESS: $Computer was added to $Collection"
                        }
                        if (!(Get-CMCollectionMember -CollectionName "$Collection" -ResourceID $PCID))
                        {
                            $Global:RunningLabel.ForeColor = "Red"
                            $Global:RunningLabel.Text = "ERROR: $Computer was not added to $Collection"
                        }
                    }
                }
                else 
                {
                    $Global:RunningLabel.ForeColor = "Red"
                    $Global:RunningLabel.Text = "ERROR: $Computer cannot be found"
                }
            }
            
        }
    }

    Function Click_BrowseForDeviceFile
    {
        [CmdletBinding()]
        Param(
        [String]$Filter = "|*.*",
        [String]$InitialDirectory = "C:\")
        [void][System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
        $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
        $OpenFileDialog.initialDirectory = $InitialDirectory
        $OpenFileDialog.filter = $Filter
        [void]$OpenFileDialog.ShowDialog()
        $OpenFileDialog.filename
        #Runs the form function over so the results are added to the text box
        $Global:DeviceFile = $OpenFileDialog.filename
        $Global:AddDeviceBox.Text = $Global:DeviceFile
    }

    function click_AddDeviceClear
    {
        $AddDeviceTab.Controls.Remove($AddDeviceButton)
        $AddDeviceTab.Controls.Remove($ComputerLabel)
        $AddDeviceTab.Controls.Remove($AddDeviceBox)
        $AddDeviceTab.Controls.Remove($AddDeviceCollectionlabel)
        $AddDeviceTab.Controls.Remove($objCollection)
        $AddDeviceTab.Controls.Remove($ClearAddDeviceButton)
        $AddDeviceTab.Controls.Remove($Global:AddDevicesFromListCheckBox)
        $AddDeviceTab.Controls.Remove($Global:BrowseForDevicesFileButton)

        $AddDeviceTab.Controls.Add($GetCollectionsButton)
        $AddDeviceTab.Controls.Add($GetCollectionsBox)
        $AddDeviceTab.Controls.Add($GetCollectionlabel)
        $AddDeviceTab.Controls.Add($GetCollectionlabel2)

        $Global:RunningLabel.ForeColor = "LightSteelBlue"
        $Global:RunningLabel.Text = "Ready"
    }

    function Click_GetSiteInfo
    {  
        if ((!$Global:SiteCode) -or (!$Global:SiteServer)) 
        {
            $Global:RunningLabel.ForeColor = "Red"
            $Global:RunningLabel.Text = "ERROR: You need to conenct to a site before the tool will work"
        }
        else 
        {
            $Global:RunningLabel.ForeColor = "LightSteelBlue"
            $Global:RunningLabel.Text = "Gathering Info, Please wait"
            #gets the info from the sccm server
            [void] $SiteInfoInfoBox.Items.Add("Site Info:")
            $Global:RunningLabel.Text = "Getting Site Name"
            $Global:CMName = (Get-CMSite).SiteName
            [void] $SiteInfoInfoBox.Items.Add("Site Name: $CMName")

            $Global:RunningLabel.Text = "Getting Site Code"
            $Global:CMCode = (Get-CMSite).SiteCode
            [void] $SiteInfoInfoBox.Items.Add("Site Code: $CMCode")

            $Global:RunningLabel.Text = "Getting Site Server"
            $Global:CMSiteServer = (Get-CMSite).ServerName
            [void] $SiteInfoInfoBox.Items.Add("Site Server: $CMSiteServer")

            $Global:RunningLabel.Text = "Getting Site Version"
            $Global:CMVersion = (Get-CMSite).Version
            [void] $SiteInfoInfoBox.Items.Add("Site Version: $CMVersion")
           
            [void] $SiteInfoInfoBox.Items.Add("")
            [void] $SiteInfoInfoBox.Items.Add("Object Info:")
            $Global:RunningLabel.Text = "Getting Number of Collections"
            $CMCollectionCount = (Get-CMCollection).count
            [void] $SiteInfoInfoBox.Items.Add("Collection Count: $CMCollectionCount")

            $Global:RunningLabel.Text = "Getting Count of All Systems Members"
            $CMAllSystemCount = (Get-CMCollection -Name "All Systems").LocalMemberCount
            [void] $SiteInfoInfoBox.Items.Add("All Systems Count: $CMAllSystemCount")

            $Global:RunningLabel.Text = "Getting Number of Applications"
            $CMAppCount = (Get-CMApplication).count
            [void] $SiteInfoInfoBox.Items.Add("Application Count: $CMAppCount")

            $Global:RunningLabel.Text = "Getting Number of Packages"
            $CMPackageCount = (Get-CMPackage).count
            [void] $SiteInfoInfoBox.Items.Add("Package Count: $CMPackageCount")

            $Global:RunningLabel.Text = "Getting Number of Task Sequence"
            $CMTSCount = (Get-CMTaskSequence).count
            [void] $SiteInfoInfoBox.Items.Add("Task Sequence Count: $CMTSCount")

            $Global:RunningLabel.Text = "Getting Deployment Count"
            $CMDeploymentCount = (Get-CMDeployment).count
            [void] $SiteInfoInfoBox.Items.Add("Deployment Count: $CMDeploymentCount")

            [void] $SiteInfoInfoBox.Items.Add("")
            [void] $SiteInfoInfoBox.Items.Add("Admins:")
            $Global:RunningLabel.Text = "Getting All Admins"
            $CMAdmins = (Get-CMAdministrativeUser).LogonName
            Foreach ($account in ($CMAdmins)){[void] $SiteInfoInfoBox.Items.Add("$account")}
            
            if (Get-CMBaseline) {$CMBaseLinestatus = "Set"} else {$CMBaseLinestatus = "Not Set"}

            [void] $SiteInfoInfoBox.Items.Add("")
            [void] $SiteInfoInfoBox.Items.Add("Installed Roles:")
            $Global:RunningLabel.Text = "Getting Installed Roles"
            $CMInstalledRoles = (Get-CMSiteRole).rolename
            foreach ($role in ($CMInstalledRoles)){[void] $SiteInfoInfoBox.Items.Add("$role")}

            $Global:RunningLabel.ForeColor = "GreenYellow"
            $Global:RunningLabel.Text = "Complete"
        } 
    }   

    function Click_SiteInfoClear
    {
        $Global:RunningLabel.ForeColor = "LightSteelBlue"
        $Global:RunningLabel.Text = "Ready"
        [void]$SiteInfoInfoBox.Items.Clear()
    }

    #Action taken when export is click on Site info form
    function Click_ExportSiteInfo
    {
        $Global:CMCode = (Get-CMSite).SiteCode
        $SiteInfoExport = $PSScriptRoot + "\" + "$Global:CMName" + "_Export.log"
        ForEach ($item in ($SiteInfoInfoBox.Items))
            {
                Add-Content $SiteInfoExport $item
            }
        [void] $SiteInfoInfoBox.Items.Clear()
        $Global:RunningLabel.Text = "Exported to $SiteInfoExport"
        [void] $SiteInfoInfoBox.Items.Add("Export Can be found at: ")
        [void] $SiteInfoInfoBox.Items.Add("$SiteInfoExport")
    }

    #Action taken when get errors is pressed 
    function Click_GetComponentStatus
    {   
        if ((!$Global:SiteCode) -or (!$Global:SiteServer)) 
        {
            $Global:RunningLabel.ForeColor = "Red"
            $Global:RunningLabel.Text = "ERROR: You need to conenct to a site before the tool will work"
        }
        else 
        {
            if (!($ComponentStatusSeveritySelect.Text)){
            $Global:RunningLabel.ForeColor = "Red"
            $Global:RunningLabel.Text = "ERROR: You Must Select A Message Type"
            }
            if ($ComponentStatusSeveritySelect.Text)
            {
                $Global:CMCode = (Get-CMSite).SiteCode
                $Global:RunningLabel.ForeColor = "LightSteelBlue"
                $Global:RunningLabel.Text = "Getting Component Status"
                if (!($ComponentStatusFilterBox.Text))
                {
                    if ($ComponentStatusGroupBySelect.Text -eq "Component") {$DeviceComponentStatusTextBox.Text = Get-CMComponentStatusMessage -SiteCode $Global:CMCode -StartTime $Global:Date -Severity $ComponentStatusSeveritySelect.Text | Format-Table -Property Time, MachineName, MessageID -AutoSize -GroupBy $ComponentStatusGroupBySelect.Text | Out-String}
                    if ($ComponentStatusGroupBySelect.Text -eq "MachineName") {$DeviceComponentStatusTextBox.Text = Get-CMComponentStatusMessage -SiteCode $Global:CMCode -StartTime $Global:Date -Severity $ComponentStatusSeveritySelect.Text | Format-Table -Property Time, Component, MessageID -AutoSize -GroupBy $ComponentStatusGroupBySelect.Text | Out-String}
                    if ($ComponentStatusGroupBySelect.Text -eq "MessageID") {$DeviceComponentStatusTextBox.Text = Get-CMComponentStatusMessage -SiteCode $Global:CMCode -StartTime $Global:Date -Severity $ComponentStatusSeveritySelect.Text | Format-Table -Property Time, MachineName ,Component -AutoSize -GroupBy $ComponentStatusGroupBySelect.Text | Out-String}
                    if ($ComponentStatusGroupBySelect.Text -eq "Time") {$DeviceComponentStatusTextBox.Text = Get-CMComponentStatusMessage -SiteCode $Global:CMCode -StartTime $Global:Date -Severity $ComponentStatusSeveritySelect.Text | Format-Table -Property MachineName ,Component -AutoSize -GroupBy $ComponentStatusGroupBySelect.Text | Out-String}
                    if ($ComponentStatusGroupBySelect.Text -eq "") {$DeviceComponentStatusTextBox.Text = Get-CMComponentStatusMessage -SiteCode $Global:CMCode -StartTime $Global:Date -Severity $ComponentStatusSeveritySelect.Text | Format-Table -Property Time, MachineName, Component, MessageID -AutoSize | Out-String}
                }
                if ($ComponentStatusFilterBox.Text)
                {
                    if ($ComponentStatusGroupBySelect.Text -eq "MachineName") {$DeviceComponentStatusTextBox.Text = Get-CMComponentStatusMessage -SiteCode $Global:CMCode -ComputerName $ComponentStatusFilterBox.Text -StartTime $Global:Date -Severity $ComponentStatusSeveritySelect.Text | Format-Table -Property Time, Component, MessageID -AutoSize | Out-String}
                    if ($ComponentStatusGroupBySelect.Text -eq "Component") {$DeviceComponentStatusTextBox.Text = Get-CMComponentStatusMessage -SiteCode $Global:CMCode -ComputerName $ComponentStatusFilterBox.Text -StartTime $Global:Date -Severity $ComponentStatusSeveritySelect.Text | Format-Table -Property Time, MessageID -AutoSize -GroupBy $ComponentStatusGroupBySelect.Text | Out-String}
                    if ($ComponentStatusGroupBySelect.Text -eq "MessageID") {$DeviceComponentStatusTextBox.Text = Get-CMComponentStatusMessage -SiteCode $Global:CMCode -ComputerName $ComponentStatusFilterBox.Text -StartTime $Global:Date -Severity $ComponentStatusSeveritySelect.Text | Format-Table -Property Time, Component -AutoSize -GroupBy $ComponentStatusGroupBySelect.Text | Out-String}
                    if ($ComponentStatusGroupBySelect.Text -eq "") {$DeviceComponentStatusTextBox.Text = Get-CMComponentStatusMessage -SiteCode $Global:CMCode -ComputerName $ComponentStatusFilterBox.Text -StartTime $Global:Date -Severity $ComponentStatusSeveritySelect.Text | Format-Table -Property Time, MachineName, Component, MessageID -AutoSize | Out-String}
                    if ($ComponentStatusGroupBySelect.Text -eq "Time") {$DeviceComponentStatusTextBox.Text = Get-CMComponentStatusMessage -SiteCode $Global:CMCode -ComputerName $ComponentStatusFilterBox.Text -StartTime $Global:Date -Severity $ComponentStatusSeveritySelect.Text | Format-Table -Property Component, MessageID -AutoSize -GroupBy $ComponentStatusGroupBySelect.Text | Out-String}
                }
                IF (($ComponentStatusFilterBox.Text) -and ($ComponentStatusGroupBySelect.Text -eq "MachineName"))
                {
                    $Global:RunningLabel.ForeColor = "Yellow"
                    $Global:RunningLabel.Text = "WARNING: Completed but using Group by MachineName and Filter dose not filter and additionl information"
                }
                else 
                {
                    $Global:RunningLabel.Text = "Complete"
                }      
            }
        }
    }

    function Click_ExportComponentStatus
    {   
        $Global:CMName = (Get-CMSite).SiteName
        $CompStatusLog = $PSScriptRoot + "\" + $Global:CMName + "_" + "ComponentStatus.log"
        $DeviceComponentStatusTextBox.Text | Out-File -FilePath $CompStatusLog
        $Global:RunningLabel.ForeColor = "LightSteelBlue"
        $Global:RunningLabel.Text = "Exported $CompStatusLog"
    }

    function Click_ClearComponentStatus
    {
        $Global:RunningLabel.ForeColor = "LightSteelBlue"
        $Global:RunningLabel.Text = "Ready"
        $ComponentStatusFilterBox.Text = ""
        $DeviceComponentStatusTextBox.Text = ""
        $ComponentStatusSeveritySelect.Text = ""
        $ComponentStatusGroupBySelect.Text = ""
    }

    Function Click_CreateCollectionBrowse
    {
        [CmdletBinding()]
        Param(
        [String]$Filter = "|*.*",
        [String]$InitialDirectory = "C:\")
        [void][System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
        $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
        $OpenFileDialog.initialDirectory = $InitialDirectory
        $OpenFileDialog.filter = $Filter
        [void]$OpenFileDialog.ShowDialog()
        $OpenFileDialog.filename
        #Runs the form function over so the results are added to the text box
        $Global:FileText = $OpenFileDialog.filename
        $Global:CreateCollectionCollectionBox.Text = $Global:FileText
    }

    Function Click_CreateCollection
    {
        $CollectionName = $Global:CreateCollectionCollectionBox.Text
        $LimitingCollection = $CreateCollectionLimitingBox.Text

        IF ($ScheduletypeSelect.Text -eq "Continuous")
        {
            If ($CreateCollectionCheckBox.Checked -eq $True) 
            {
                $CollectionsFromFile = Get-Content "$CollectionName"
                Foreach ($Collection in ($CollectionsFromFile))
                {
                    New-CmDeviceCollection -Name "$CollectionName" -LimitingCollectionName "$LimitingCollection" -RefreshType Continuous
                }
            }
            IF ($CreateCollectionCheckBox.Checked -eq $False)
            {
                New-CmDeviceCollection -Name "$CollectionName" -LimitingCollectionName "$LimitingCollection" -RefreshType Continuous
                If (!(Get-CMCollection -name "$CollectionName")) 
                {
                    $Global:RunningLabel.ForeColor = "Red"
                    $Global:RunningLabel.Text = "$CollectionName Could Not Be Created"
                }
                IF (Get-CMCollection -Name "$CollectionName")
                {
                    $Global:RunningLabel.ForeColor = "GreenYellow"
                    $Global:RunningLabel.Text = "$CollectionName Created"
                }
            }
        } 
        else 
        {
            $RecurCount = $ScheduletypeParam.Text
            $RecurType = "$ScheduletypeSelect.Text"
            IF ($ScheduletypeSelect.Text -eq "Days"){$RecurType = "Days"}
            $Schedule = New-CMSchedule -RecurInterval "$RecurType" -RecurCount "$RecurCount"
            If ($CreateCollectionCheckBox.Checked -eq $True) 
            {
                $CollectionsFromFile = Get-Content "$CollectionName"
                Foreach ($Collection in ($CollectionsFromFile))
                {
                    New-CmDeviceCollection -Name "$CollectionName" -LimitingCollectionName "$LimitingCollection" -RefreshSchedule $Schedule
                }
            }
            IF ($CreateCollectionCheckBox.Checked -eq $False)
            {
                New-CmDeviceCollection -Name "$CollectionName" -LimitingCollectionName "$LimitingCollection" -RefreshSchedule $Schedule
                If (!(Get-CMCollection -name "$CollectionName")) 
                {
                    $Global:RunningLabel.ForeColor = "Red"
                    $Global:RunningLabel.Text = "$CollectionName Could Not Be Created"
                }
                IF (Get-CMCollection -Name "$CollectionName")
                {
                    $Global:RunningLabel.ForeColor = "GreenYellow"
                    $Global:RunningLabel.Text = "$CollectionName Created"
                }
            }
        }
    }

    Function Click_GetSiteColelctions
    {
        if ((!$Global:SiteCode) -or (!$Global:SiteServer)) 
        {
            $Global:RunningLabel.Text = "ERROR: You need to conenct to a site before the tool will work"
            $Global:RunningLabel.ForeColor = "Red"
        }
        else
        {
            $Global:RunningLabel.ForeColor = "LightSteelBlue"
            $Global:RunningLabel.Text = "Gathering Collections, Please Wait..."
            $CMCollections = (Get-CMCollection | Sort-Object -Property Name ).name
            Foreach ($item in ($CMCollections))
        {
            [void] $SiteCollectionsInfoBox.Items.Add("$Item")
        }
            $Global:RunningLabel.ForeColor = "GreenYellow"
            $Global:RunningLabel.Text = "Complete"
        }
    }

    function Click_Donate
    {
        [System.Diagnostics.Process]::Start("https://www.paypal.me/jackofalltech")    
    }
if ((!$Global:SiteCode) -or (!$Global:SiteServer)) {Start-MainForm} else {Set-Site}

Comments

  1. This comment has been removed by a blog administrator.

    ReplyDelete

Post a Comment

Popular posts from this blog

SCCM Task Sequence GUI - How to set up the TS to work with a GUI

SCCM Applications vs. SCCM Packages: Understanding the Key Differences

Windows 10 Setup Script - Version 2.5.0.1