Get-SCCMDeviceInfo - V 1.0.0.2

This tool works much like my Add Computer to SCCM Collection Script but gathers select information about a device from SCCM

I have rereleased my Get-SCCMDeviceInfo script for some minor bug fixes
1. Fixed and issue that would duplicate the device status and resource Id of the device had more then 
    one primary user.
2. Fixed an issue that could result in an error if the user did not specify both a Site Code and Site Server



<#

.SYNOPSIS
The script will allow you to gather inforamtion about a device from SCCM

.DESCRIPTION
This script will gather Activation status, Resorce ID, OS, Managment Point,Primary User, Last log in time, Hardware scan,Software scan and Policy request time.

.EXAMPLE
If you do not want to use the Site form specify yoru site code and site server in the paramiters
.\Get-SCCMDeviceDeviceInfo.ps1 -SiteServer SCCMSiteServer -SiteCode CC1

.EXAMPLE
if you want to load the PowerShell Module from the local install path use 
.\Get-SCCMDeviceInfo.ps1 -LoadLocal True

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

.LINK
http://sccmtst.com

#>


Param(
    $SiteServer,
    $SiteCode,
    [switch]$LoadLocal
    )
#Generates the site info form
function Generate-SITEform
{
    Add-Type -AssemblyName System.Windows.Forms
    Add-Type -AssemblyName System.Drawing
    $ButtonSize = New-Object System.Drawing.Size(75,23)
    $Siteform = New-Object System.Windows.Forms.Form 
    $Siteform.Text = "Site Info"
    $Siteform.Size = New-Object System.Drawing.Size(300,230) 
    $Siteform.StartPosition = "CenterScreen"

    #Create the ok button
    $OKButton = New-Object System.Windows.Forms.Button
    $OKButton.Location = New-Object System.Drawing.Point(20,130)
    $OKButton.Size = $ButtonSize
    $OKButton.Text = "OK"
    $OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
    $Siteform.AcceptButton = $OKButton
    $OKButton.Add_Click({click-okSite})

    #Create the cancel button
    $CancelButton = New-Object System.Windows.Forms.Button
    $CancelButton.Location = New-Object System.Drawing.Point(120,130)
    $CancelButton.Size = $ButtonSize
    $CancelButton.Text = "Cancel"

    #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
    $SitetextBox = New-Object System.Windows.Forms.TextBox 
    $SitetextBox.Location = New-Object System.Drawing.Point(15,42) 
    $SitetextBox.Size = New-Object System.Drawing.Size(50,20) 

    #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
    $ServertextBox = New-Object System.Windows.Forms.TextBox 
    $ServertextBox.Location = New-Object System.Drawing.Point(15,90) 
    $ServertextBox.Size = New-Object System.Drawing.Size(250,20) 

    #Warrning lable that the script is working but way take some time to run the next section
    $RunningLabel = New-Object System.Windows.Forms.Label
    $RunningLabel.Location = New-Object System.Drawing.Point(10,170)
    $RunningLabel.Size = New-Object System.Drawing.Size(280,20)
    $RunningLabel.ForeColor = "Red"
    $RunningLabel.Text = "Gathering Server Info, This may take some time"
    $RunningLabel.Visible = $false

    #adds all items to the site form 
    $Siteform.Topmost = $True
    $Siteform.Controls.Add($OKButton)
    $Siteform.Controls.Add($CancelButton)
    $Siteform.Controls.Add($Sitelabel)
    $Siteform.Controls.Add($SitetextBox)
    $Siteform.Controls.Add($Serverlabel)
    $Siteform.Controls.Add($ServertextBox)
    $Siteform.Controls.Add($RunningLabel)

    #shows the form
    [void]$Siteform.ShowDialog()
}
#Starts the main form
Function Generate-MainForm
{   
    #loads the SCCM modules based on the paramiters 
    if ($LoadLocal -eq "$True") 
        {
            Set-Location 'C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\'
            Import-Module .\ConfigurationManager.psd1 -verbose:$false   
        }     
        else 
        {
            Import-Module \\$SiteServer\SMS_$SiteCode\AdminConsole\bin\ConfigurationManager.psd1 -verbose:$false
        }
    #Sets teh site code so the script can connect to the site
    $site = $SiteCode + ":"
    Set-Location $site
    $SiteForm.Dispose()
    $SiteForm.Close()
    $ButtonSize = New-Object System.Drawing.Size(75,23)
    $form = New-Object System.Windows.Forms.Form 
    $form.Text = "Get SCCM Device Info - V 2.0.1.2"
    $form.Size = New-Object System.Drawing.Size(400,350) 
    $form.StartPosition = "CenterScreen"
    #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_Results})
    #sets the export button
    $ExportButton = New-Object System.Windows.Forms.Button
    $ExportButton.Location = New-Object System.Drawing.Point(50,280)
    $ExportButton.Size = $ButtonSize
    $ExportButton.Text = "Export"
    $ExportButton.Add_Click({Click_Export})
    #sets the clear Button
    $ClearButton = New-Object System.Windows.Forms.Button
    $ClearButton.Location = New-Object System.Drawing.Point(200,280)
    $ClearButton.Size = $ButtonSize
    $ClearButton.Text = "Clear"
    $ClearButton.Add_Click({Click_Clear})
    #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 Computer entry box
    $ComputerBox = New-Object System.Windows.Forms.TextBox 
    $ComputerBox.Location = New-Object System.Drawing.Point(10,40) 
    $ComputerBox.Size = New-Object System.Drawing.Size(260,20) 
    #sets the area where the computer info will be shown
    $InfoBox = New-Object System.Windows.Forms.ListBox
    $InfoBox.Size = New-Object System.Drawing.Point(365,170)
    $InfoBox.Location = New-Object System.Drawing.Point(10,100)
    $InfoBox.HorizontalScrollbar = $true
    #adds all items to the form
    $form.Controls.Add($ComputerLabel) 
    $form.Controls.Add($ClearButton)
    $form.Controls.Add($GetInfoButton)
    $form.Controls.Add($ComputerBox)
    $form.Controls.Add($ExportButton)
    $form.Controls.Add($InfoBox)
    #make the form show on top of all windows
    $form.Topmost = $True
    #Shows the main form
    [void]$form.ShowDialog() 
}

#action taken when the ok button on the site form is pressed
Function click-okSite
{     
    $RunningLabel.Visible = $true
    $SiteCode = $SitetextBox.text
    $SiteServer = $ServertextBox.text
    Generate-MainForm
}
#action taken then the clear button is pressed
function click_Clear
    {   
        $ComputerBox.text = ""
        [void]$InfoBox.Items.Clear()
    }
#Action taken when the export button is pressed
function click_Export
    {   
        $Comp = $ComputerBox.Text
        $LogFile = $Comp + "_Export.log"
        ForEach ($item in ($InfoBox.Items))
            {
                Add-Content $PSScriptRoot\$LogFile $item
            }
        [void]$InfoBox.Items.Clear()
        [void] $InfoBox.Items.Add("Export Can be found at: ")
        [void] $InfoBox.Items.Add("$PSScriptRoot\$LogFile")
        
    }
#Actions ran when the Get info button is pressed
Function Click_Results
{   
    #Clears teh info box of all old data
    [void]$InfoBox.Items.Clear()
    #Gets teh computer number
    $Comp = $ComputerBox.Text
    #gets the info from the sccm server
    $Active = (Get-CMUserDeviceAffinity -DeviceName $comp).IsActive
    $User = (Get-CMUserDeviceAffinity -DeviceName $comp).UniqueUserName
    $ID = (Get-CMUserDeviceAffinity -DeviceName $comp).ResourceID
    $login = (Get-CMDevice -name $comp).ADLastLogonTime
    $ActiveTime = (Get-CMDevice -name $comp).LastActiveTime
    $Hardwarescan = (Get-CMDevice -name $comp).LastHardwareScan
    $SoftwareScan = (Get-CMDevice -name $comp).LastSoftwareScan
    $PolicyRequest = (Get-CMDevice -name $comp).LastPolicyRequest
    $MPServer = (Get-CMDevice -name $comp).LastMPServerName
    $DeviceOS = (Get-CMDevice -name $comp).DeviceOS
    #Adds all info to the info box
    [void] $InfoBox.Items.Add("Computer Name: $comp")
    [void] $InfoBox.Items.Add("Device Active: $Active")
    [void] $InfoBox.Items.Add("Computer Resorce ID: $ID")
    [void] $InfoBox.Items.Add("OS: $DeviceOS")
    [void] $InfoBox.Items.Add("Management Point: $MPServer")
    [void] $InfoBox.Items.Add("Primary User: $User")
    [void] $InfoBox.Items.Add("Logged in: $login")
    [void] $InfoBox.Items.Add("Hardware Scan: $Hardwarescan")
    [void] $InfoBox.Items.Add("Software Scan: $SoftwareScan")
    [void] $InfoBox.Items.Add("Policy Request: $PolicyRequest")
}
#Runs the correct form based on the paramiters
if ((!$SiteServer) -and (!$SiteCode)) { Generate-SITEform } Else {Generate-MainForm}

Popular Posts

Office 365 Deployment - Office 365 Upgrade Task Sequence

SCCM Task Sequence with GUI - How to install more then one image with a single Task Sequence

Windows 10 Setup Script - V 2.0.0.0