Get-PC/Private/PCRemoteCleaned.ps1

334 lines
12 KiB
PowerShell
Raw Normal View History

2024-06-11 18:27:55 +00:00
#GetPC w/ Jobs
#CIM Instance Calls
<#
win32_networkadapterconfiguration | MAC Address,
win32_computersystem | Username, Model, RAM,
win32_LogicalDisk | Diskspace,
win32_bios | ServiceTag, Bios Version,
win32_OperatingSystem | Last Restart, OS Version, OS Build, OS Build Number
win32_SystemEnclosure | Asset Tag
win32_processor | CPU Type
PC Release ID
Installed Printers
#>
#WMI Calls
<#
win32_tpm
#>
#PSSessions
<#
Lastuser/Lastuser timestamp
Imprivata Type
Kiosk Role and Type
MBAM GPO Status
#>
<#
function get-PCremoteCleaned {
param (
[string]$comp,
$connection,
$NumberofComputers,
$PCID
)
$ComputerName = $Comp
$i = 0
$i++ | ProgressBar $i $comp 'NetAdapter' $NumberofComputers $PCID
$win32_networkadapterconfiguration = Get-CimInstance -Class win32_networkadapterconfiguration -ComputerName $ComputerName #| MAC Address,
$i++ | ProgressBar $i $comp 'LogicalDisk' $NumberofComputers $PCID
$win32_LogicalDisk = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" -ComputerName $ComputerName #| Diskspace,
$i++ | ProgressBar $i $comp 'Enclosure' $NumberofComputers $PCID
$win32_SystemEnclosure = Get-CimInstance -ClassName Win32_SystemEnclosure -ComputerName $ComputerName #| Asset Tag
$i++ | ProgressBar $i $comp 'Bitlocker' $NumberofComputers $PCID
$bitlocker = manage-bde -cn $ComputerName -status C: # | Bitlocker Status
$i++ | ProgressBar $i $comp 'PCInfo' $NumberofComputers $PCID
$PCInfo = Invoke-Command -ComputerName $ComputerName -SessionOption (New-PSSessionOption -NoMachineProfile) -ScriptBlock {get-computerinfo}
$i++ | ProgressBar $i $comp 'PhysicalDisk' $NumberofComputers $PCID
$physicalDisk = Get-PhysicalDisk -CimSession $ComputerName # | Disk Type
$i++ | ProgressBar $i $comp 'Printers' $NumberofComputers $PCID
$win32_printer = (Get-CimInstance -ClassName win32_printer -ComputerName $ComputerName | Where-Object {$_.PortName -ne 'PORTPROMPT:' -and $_.PortName -ne 'nul:' -and $_.PortName -ne 'SHRFAX:'} | Select-Object -ExpandProperty Name) -join ' || ' # | Printers
$i++ | ProgressBar $i $comp 'Imprivata' $NumberofComputers $PCID
$imprivataRegEntry = Invoke-Command -ComputerName $ComputerName -SessionOption (New-PSSessionOption -NoMachineProfile) -ScriptBlock {Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\SSOProvider\ISXAgent}
$kioskRegEntry = Invoke-Command -ComputerName $ComputerName -SessionOption (New-PSSessionOption -NoMachineProfile) -ScriptBlock {Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\SHSCustom}
$i++ | ProgressBar $i $comp 'TPM' $NumberofComputers $PCID
$win32_tpm = Get-CimInstance -Namespace root\cimv2\security\microsofttpm -Class win32_tpm -ComputerName $ComputerName # | TPM
$i++ | ProgressBar $i $comp 'MBAM GPO' $NumberofComputers $PCID
$gpostatus = Invoke-Command -ComputerName $ComputerName -SessionOption (New-PSSessionOption -NoMachineProfile) -ScriptBlock{
$gpoPath = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\FVE\MDOPBitLockerManagement"
$gpoValue = Get-ItemPropertyValue -Path $gpoPath -Name "KeyRecoveryServiceEndPoint"
Switch($GpoValue -eq "https://shsmbam1.int.samhealth.net/MBAMRecoveryAndHardwareService/CoreService.svc")
{
$true {$gpoStatus = "GPO Applied"}
$false {$gpoStatus = "GPO Not Applied (Check if system is member of group MBAM_Default on ADUC"}
Default {$gpoStatus = "Error...GPOTEST Line PCRemote Line 276"}
}
Return $gpoStatus
}
$i++ | ProgressBar $i $comp 'Pulling Citrix' $NumberofComputers $PCID
$CitrixViewer = "\\$ComputerName\C$\Program Files (X86)\Citrix\ICA Client\CDViewer.exe"
$i++ | ProgressBar $i $comp 'Pulling Last users' $NumberofComputers $PCID
$LastUser = Invoke-Command -ComputerName $ComputerName -SessionOption (New-PSSessionOption -NoMachineProfile) -ScriptBlock {
Get-ChildItem -Path C:\Users -Directory -Force -Exclude Public,Default,'Default User','All Users' |
Sort-Object -Property LastWriteTime -Descending | Select-Object -First 3} # | Last Users
$i++ | ProgressBar $i $comp 'Pulling CPU' $NumberofComputers $PCID
$CPU = (Get-CimInstance -ClassName Win32_processor -ComputerName $ComputerName).Name
#CMDB Location
$i++ | ProgressBar $i $comp 'Pulling CMDB Data' $NumberofComputers $PCID
$location = Get-CMDBLocation $ComputerName
$i++ | ProgressBar $i $comp 'Compiling Data' $NumberofComputers $PCID
#MAC Address
$MAC = ($win32_networkadapterconfiguration | Where-Object {$_.IpEnabled -Match "True"} | Select-Object -Expand macaddress) -join ","
#IP
$ip = $connection.IPV4Address
#UserName
$Username = $PCInfo.CSUserName
if($null -eq $Username){
$Username = (Invoke-Command -SessionOption (New-PSSessionOption -NoMachineProfile) -ComputerName $ComputerName -ScriptBlock {Get-Process Explorer -IncludeUsername | Where-Object { $_.Username -notlike "*SYSTEM" }} ).Username
if($null -ne $Username){
$Username = "$Username (RDP/Inactive)"
}
else{
$Username = '**None**'
}
}
#Last User
if($lastUser.Count -gt 1){
$lastUser1 = ($lastUser[0].Name + " (" + $lastUser[0].LastWriteTime + ")")
$lastUser2 = ($lastUser[1].Name + " (" + $lastUser[1].LastWriteTime + ")")
$lastUser3 = ($lastUser[2].Name + " (" + $lastUser[2].LastWriteTime + ")")
$TotalLastUsers = "$lastUser1 $lastUser2 $lastUser3"
}else{
$TotalLastUsers = $lastUser.Name + " (" + $lastUser.LastWriteTime + ")"
}
#ComputerModel
$compModel = $PCInfo.CsModel
#RAM
$ram = $PCInfo.CsTotalPhysicalMemory
$ram = [math]::Round(($ram / 1GB))
$ram = "$ram" + ' GB'
#Drive Type
$DriveType = $physicalDisk.MediaType
#Free Harddrive Space
$CompFreeSpace = @([math]::Round($win32_LogicalDisk.FreeSpace / 1gb,2),[math]::Round($win32_LogicalDisk.Size / 1gb,2))
$free = $compFreeSpace[0]
$max = $compfreeSpace[1]
$freespace = "$free GB / $max GB"
#Service Tag
#$serviceTag = $win32_bios.SerialNumber
$serviceTag = $PCInfo.BiosSeralNumber
#BIOS
#$biosVersion = $win32_bios.SMBIOSBIOSVersion
$biosVersion = $PCInfo.BiosName
#Last Reboot
$lastbootTime = $PCInfo.OsLastBootUpTime
#Asset Tag
$assetTag = $win32_SystemEnclosure.SMBiosAssetTag
#Bitlocker Status
$PercentageEncrypted = (($bitlocker | Select-String "Percentage Encrypted") -split ': ')[1]
[int]$IntPercentageEncrypted = $PercentageEncrypted.Substring(0,4)
$EncryptionStatus = $null
If($bitlocker -like '*error*')
{
$EncryptionStatus = 'BitLocker - Error - Please investigate'
}
Elseif($IntPercentageEncrypted -eq 100)
{
$EncryptionStatus = "BitLocker - Encrypted ($PercentageEncrypted)"
}
ElseIf($IntPercentageEncrypted -gt 1)
{
$EncryptionStatus = "BitLocker - Encrypting ($PercentageEncrypted)"
}
Else
{
$EncryptionStatus = "BitLocker - Decrypted ($PercentageEncrypted)"
}
#OS
$os = $PCInfo.OSName + " (" + $PCInfo.OSArchitecture + ")"
#OS Build
$osVer = $PCInfo.WindowsVersion
$osBuild = $PCInfo.OSBuildNumber
$osBuild = "Vers $osVer | Build #$osBuild"
#Printers
$printers = $win32_printer# ($win32_printer | Where-Object {$_.PortName -ne 'PORTPROMPT:' -and $_.PortName -ne 'nul:' -and $_.PortName -ne 'SHRFAX:'} | Select-Object -ExpandProperty Name) -join ' || '
if(!$printers){
$printers = "No Local/Networked Printer (Check Printer Mappings)"
}
#Imprivata
$ImprivataType = $imprivataRegEntry | Select-Object -ExpandProperty Type
if(!$imprivataType){
$ImprivataType = "Not Installed"
}
else{
Switch($ImprivataType){
1 {
$ImprivataType = $imprivataRegEntry | Select-Object -ExpandProperty FUS_Enabled
Switch($ImprivataType){
0 {$ImprivataType = "SUD"}
1 {$ImprivataType = "MUD"}
}
}
2 {$ImprivataType = "Kiosk"}
Default {$ImprivataType = "Not Installed"}
}
}
$kioskRole = $kioskRegEntry | Select-Object -ExpandProperty KioskRole
if(!$kioskRole){
$kioskRole = "None"
}
#TPM
$tpmStatus = $win32_tpm | Select-Object -ExpandProperty IsEnabled_InitialValue
if($tpmStatus -eq $true){
$tpmStatus = "On & Activated"
}
elseif($tpmStatus -eq $false){
$tpmStatus = "On & Deactivated"
}
else{
$tpmStatus = "TPM Off"
}
#Chassis Type
$chassisType = Get-ChassisTypeNew -CPU $CPU -Model $compModel
#Citrix Version
if( !(Test-path $CitrixViewer)){
$CitrixVersion = "Not Installed"
}
else{
#Checks this default install path
$CitrixVersion = Get-Command $citrixViewer | select-object -ExpandProperty Version #Grabs Citrix version number
}
#Output
$i++ | ProgressBar $i $comp 'Generating Output' $NumberofComputers $PCID
$props = [Ordered]@{
Hostname = "$comp"
Status = "Online"
'Current User' = "$userName"
'Last User(s)' = "$TotalLastUsers"
'IP | MAC' = "$ip | $mac"
Model = "$compModel ($chassisType)"
'OS' = $os
'OS Build' = $osBuild
'BIOS Ver' = "$biosVersion"
Encryption = "$EncryptionStatus"
'Free Space' = "$freespace | $driveType"
RAM = "$ram"
'SSO Client' = "$imprivataType"
'Kiosk Role' = "$kioskRole"
'Citrix Ver' = "$citrixVersion"
'Asset Tag' = "$assetTag"
'Service Tag' = "$serviceTag"
'Last Reboot' = "$lastbootTime"
'TPM Status' = "$tpmStatus"
'MBAM GPO' = "$gpostatus"
Printers = "$printers"
'CMDB Location' = "$location"
}
$obj = New-Object -TypeName PSObject -Property $props
return $obj
}
#Helper Functions
Function Get-ChassisTypeNew {
[CmdletBinding()]
param (
$CPU,
$Model
)
Switch -Wildcard($Model)
{
"Optiplex*" {
Switch -Wildcard($CPU)
{
"Intel(R) Core(TM) i5-6500 CPU*" {Return "SFF"} #7040
"Intel(R) Core(TM) i5-6500T*" {Return "Micro"} #7040
"Intel(R) Core(TM) i7-6700 CPU*" {Return "SFF"} #7040
"Intel(R) Core(TM) i7-6700T*" {Return "Micro"} #7040
"Intel(R) Core(TM) i5-9500T*" {Return "Micro"} #5070
"Intel(R) Core(TM) i5-8500 CPU*" {Return "SFF"} #5060
"Intel(R) Core(TM) i5-8500T*" {Return "Micro"} #5060
"Intel(R) Core(TM) i5-7500*" {Return "SFF"} #5050
"Intel(R) Core(TM) i5-4670 CPU*" {Return "SFF"} #9020
"Intel(R) Core(TM) i5-4590 CPU*" {Return "SFF"} #9020
"Intel(R) Core(TM) i5-4590T CPU*" {Return "Micro"} #9020M
"Intel(R) Core(TM) i5-4690 CPU*" {Return "SFF"} #9020
"Intel(R) Core(TM) i5-3550 CPU*" {Return "SFF"} #9010
"Intel(R) Core(TM) i5-2400 CPU*" {Return "SFF"} #990
Default {Return "Optiplex - Chassis Type - Unknown"}
}
}
"Latitude*" {
Return "Laptop"
}
"Precision*"{
Return "Laptop"
}
Default {Return "Unknown Model/Chassis"}
}
}
Function Get-CMDBLocation($comp) {
$cmdb = Get-LANDeskCMDBItem -Name $comp
if ($null -eq $cmdb){
$location = "*CMDB Mismatch - check CMDB*"
return $location
}
$location = $cmdb.values._SHSLocation3
if($null -eq $location -or '' -eq $location){
$location = "*No location data - Please update CMDB*"
}
return $location
}
#>