PowerShell SystemInfo ++



### TITLE
$Host.UI.RawUI.WindowTitle = "SystemInfo - Developed by RoboticScript (roboticscript.com)"

### DATE AND TIME VARIABLES
# $date1 = Get-Date -UFormat "%d-%m-%Y"
$date2 = Get-Date -UFormat "%d-%m-%Y_%H"
# $date3 = Get-Date -UFormat "Date: %d-%m-%Y, Time: %H-%M-%S"
$date4 = Get-Date -UFormat "Date: %d-%m-%Y, Time: %H-%M-%S IST"

### LOG FILE NAME AND PATH
$hostname002 = Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object Name | ForEach-Object{$_.Name}
$date_log_transcript = Get-Date -UFormat $hostname002"_%d-%m-%Y_%H-%M-%S"
$log_location1 = $date_log_transcript+".txt"

$date_log_transcript2 = Get-Date -UFormat $hostname002"_%d-%m-%Y_%H-%M-%S"
$log_location2 = $date_log_transcript2+".html"

### MENU DISPLAY ON SCREEN
function menu_display_on_screen {
    "========================================================================"
    "| | | | |             SYSTEM INFORMATION - REPORTS               | | | |"
    "========================================================================"
    Write-Host "|           Developed by RoboticScript (roboticscript.com)             |" -ForegroundColor Red
    "========================================================================"
    Write-Host "|                         TABLE OF CONTENTS                            |" -ForegroundColor Green
    "+----------------------------------------------------------------------+"
    "| 01 - GET OPERATING SYSTEM DETAILS                                    |"
    "| 02 - GET PROCESSOR DETAILS                                           |"
    "| 03 - GET RAM DETAILS                                                 |"
    "| 04 - GET DISK SPACE DETAILS                                          |"
    "| 05 - GET VOLUME DETAILS                                              |"
    "| 06 - GET USER DETAILS                                                |"
    "| 07 - GET ALL MEMBERS OF THE ADMINISTRATORS GROUP                     |"
    "| 08 - GET INSTALLED SOFTWARE DETAILS                                  |"
    "| 09 - GET PROCESS DETAILS                                             |"
    "| 10 - GET SERVICE DETAILS                                             |"
    "| 11 - GET NETWORK DETAILS                                             |"
    "| 12 - GET FILE SHARE DETAILS                                          |"
    "+----------------------------------------------------------------------+"
}

### MENU WRITE ON FILE
function menu_write_on_file { 
    ## HEADER (WRITE TO FILE) | (= count is 72)
    "" | Out-File $log_location1 -Append
    "<span style=background-color:powderblue>========================================================================</span>" | Out-File $log_location1 -Append
    "<span style=background-color:powderblue>| | | | |             SYSTEM INFORMATION - REPORTS               | | | |</span>" | Out-File $log_location1 -Append
    "<span style=background-color:powderblue>========================================================================</span>" | Out-File $log_location1 -Append
    "<span style=background-color:powderblue>|           Developed by RoboticScript (roboticscript.com)             |</span>" | Out-File $log_location1 -Append
    "<span style=background-color:powderblue>========================================================================</span>" | Out-File $log_location1 -Append
    "" | Out-File $log_location1 -Append
    ">> START TIME: " | Out-File $log_location1 -Append -NoNewline
    $date4 | Out-File $log_location1 -Append
    "" | Out-File $log_location1 -Append 
    "+----------------------------------------------------------------------+" | Out-File $log_location1 -Append
    "|                         TABLE OF CONTENTS                            |" | Out-File $log_location1 -Append
    "+----------------------------------------------------------------------+" | Out-File $log_location1 -Append
    "| 01 - GET OPERATING SYSTEM DETAILS                                    |" | Out-File $log_location1 -Append
    "| 02 - GET PROCESSOR DETAILS                                           |" | Out-File $log_location1 -Append
    "| 03 - GET RAM DETAILS                                                 |" | Out-File $log_location1 -Append
    "| 04 - GET DISK SPACE DETAILS                                          |" | Out-File $log_location1 -Append
    "| 05 - GET VOLUME DETAILS                                              |" | Out-File $log_location1 -Append
    "| 06 - GET USER DETAILS                                                |" | Out-File $log_location1 -Append
    "| 07 - GET ALL MEMBERS OF THE ADMINISTRATORS GROUP                     |" | Out-File $log_location1 -Append
    "| 08 - GET INSTALLED SOFTWARE DETAILS                                  |" | Out-File $log_location1 -Append
    "| 09 - GET PROCESS DETAILS                                             |" | Out-File $log_location1 -Append
    "| 10 - GET SERVICE DETAILS                                             |" | Out-File $log_location1 -Append
    "| 11 - GET NETWORK DETAILS                                             |" | Out-File $log_location1 -Append
    "| 12 - GET FILE SHARE DETAILS                                          |" | Out-File $log_location1 -Append
    "+----------------------------------------------------------------------+" | Out-File $log_location1 -Append
    "" | Out-File $log_location1 -Append
}

### VIEW BASIC INFORMATION ABOUT SYSTEM
function basic_information {

    ### CMDLET
    # Windows edition:
    $windows_editions1 = Get-CimInstance Win32_OperatingSystem | Select-Object Caption | ForEach-Object{$_.Caption}
    # Processor:
    $processor1 = Get-CimInstance -ClassName Win32_Processor | Select-Object Name | ForEach-Object{$_.Name}
    # Installed memory (RAM):
    $ram1 = (Get-CimInstance Win32_PhysicalMemory | Measure-Object -Property capacity -Sum).sum /1gb
    # Hard disk:
    $hard_disk1 = (Get-PhysicalDisk | Select-Object @{n="Size";e={[math]::Round($_.Size/1GB,2)}}).Size
    # System type:
    $system_type1 = Get-CimInstance Win32_OperatingSystem | Select-Object OSArchitecture | ForEach-Object{$_.OSArchitecture}
    $system_type2 = Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object SystemType | ForEach-Object{$_.SystemType}
    # Computer name:
    $computer_name1 = Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object Name | ForEach-Object{$_.Name}
    # Domain:
    $domain1 = Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object Domain | ForEach-Object{$_.Domain}
    # Serial Number
    $serial_number1 = Get-CimInstance -ClassName Win32_BIOS | Select-Object SerialNumber | ForEach-Object{$_.SerialNumber}
    # Windows Version
    $version1 = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name ReleaseId).ReleaseId
    # (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ReleaseId


    ### WRITE TO FILE

    "<p><span>| VIEW BASIC INFORMATION ABOUT SYSTEM                                  |</span></p>" | Out-File $log_location1 -Append
    Write-Host ""

    # Windows edition:
    "<span style=background-color:LightGrey> Windows edition        : $windows_editions1 </span>" | Out-File $log_location1 -Append
    "<span style=background-color:LightGrey> Version:               : $version1 </span>" | Out-File $log_location1 -Append
    # Processor:
    "" | Out-File $log_location1 -Append
    "<span style=background-color:LightGrey> Processor              : $processor1 </span>" | Out-File $log_location1 -Append 
    # Installed memory (RAM):
    "<span style=background-color:LightGrey> Installed memory (RAM) : $ram1 GB </span>" | Out-File $log_location1 -Append
    # Hard disk:
    "<span style=background-color:LightGrey> Hard disk              : $hard_disk1 GB </span>" | Out-File $log_location1 -Append
    # System type:
    "<span style=background-color:LightGrey> System type            : $system_type1 Operating System, $system_type2 </span>" | Out-File $log_location1 -Append
    # Computer name:
    "" | Out-File $log_location1 -Append
    "<span style=background-color:LightGrey> Computer name          : $computer_name1 </span>" | Out-File $log_location1 -Append
    # Domain:
    "<span style=background-color:LightGrey> Domain                 : $domain1 </span>" | Out-File $log_location1 -Append
    # Serial Number
    "" | Out-File $log_location1 -Append
    "<span style=background-color:LightGrey> Serial Number          : $serial_number1 </span>" | Out-File $log_location1 -Append
    "" | Out-File $log_location1 -Append
}

### GET OPERATING SYSTEM DETAILS
function get_os_details {
    "<p><span>| GET OPERATING SYSTEM DETAILS                                         |</span></p>" | Out-File $log_location1 -Append
    Write-Host ""
    Write-Host ""
    Write-Host "01 - COLLECTING OPERATING SYSTEM DETAILS . . . " -ForegroundColor DarkGreen

    "" | Out-File $log_location1 -Append
    "Host Name: " | Out-File $log_location1 -Append -NoNewline
    Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object Name | ForEach-Object{$_.Name} | Out-File $log_location1 -Append
    "Domain: " | Out-File $log_location1 -Append -NoNewline
    Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object Domain | ForEach-Object{$_.Domain} | Out-File $log_location1 -Append
    "User Name: " | Out-File $log_location1 -Append -NoNewline
    Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object UserName | ForEach-Object{$_.UserName} | Out-File $log_location1 -Append

    "" | Out-File $log_location1 -Append
    "Manufacturer: " | Out-File $log_location1 -Append -NoNewline
    Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object Manufacturer | ForEach-Object{$_.Manufacturer} | Out-File $log_location1 -Append
    "Model: " | Out-File $log_location1 -Append -NoNewline
    Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object Model | ForEach-Object{$_.Model} | Out-File $log_location1 -Append
    "Serial Number: " | Out-File $log_location1 -Append -NoNewline
    Get-CimInstance -ClassName Win32_BIOS | Select-Object SerialNumber | ForEach-Object{$_.SerialNumber} | Out-File $log_location1 -Append
    #"BIOS Date: "
    Get-CimInstance -ClassName Win32_BIOS | Select-Object Name | ForEach-Object{$_.Name} | Out-File $log_location1 -Append

    "" | Out-File $log_location1 -Append
    "OS: " | Out-File $log_location1 -Append -NoNewline
    Get-CimInstance Win32_OperatingSystem | Select-Object Caption | ForEach-Object{$_.Caption} | Out-File $log_location1 -Append
    "Version: " | Out-File $log_location1 -Append -NoNewline
    Get-CimInstance Win32_OperatingSystem | Select-Object Version | ForEach-Object{$_.Version} | Out-File $log_location1 -Append
    "OS Architecture: " | Out-File $log_location1 -Append -NoNewline
    Get-CimInstance Win32_OperatingSystem | Select-Object OSArchitecture | ForEach-Object{$_.OSArchitecture} | Out-File $log_location1 -Append
    "WindowsDirectory: " | Out-File $log_location1 -Append -NoNewline
    Get-CimInstance Win32_OperatingSystem | Select-Object WindowsDirectory | ForEach-Object{$_.WindowsDirectory} | Out-File $log_location1 -Append

    "" | Out-File $log_location1 -Append
    "Windows Install Date: " | Out-File $log_location1 -Append -NoNewline
    Get-CimInstance Win32_OperatingSystem | Select-Object InstallDate | ForEach-Object{$_.InstallDate} | Out-File $log_location1 -Append
    "Windows Last Boot Up Time: " | Out-File $log_location1 -Append -NoNewline
    Get-CimInstance Win32_OperatingSystem | Select-Object LastBootUpTime | ForEach-Object{$_.LastBootUpTime} | Out-File $log_location1 -Append
    "Windows Local Date Time: " | Out-File $log_location1 -Append -NoNewline
    Get-CimInstance Win32_OperatingSystem | Select-Object LocalDateTime | ForEach-Object{$_.LocalDateTime} | Out-File $log_location1 -Append

    "" | Out-File $log_location1 -Append
    "Number Of Processes: " | Out-File $log_location1 -Append -NoNewline
    Get-CimInstance Win32_OperatingSystem | Select-Object NumberOfProcesses | ForEach-Object{$_.NumberOfProcesses} | Out-File $log_location1 -Append
    "Number Of Users: " | Out-File $log_location1 -Append -NoNewline
    Get-CimInstance Win32_OperatingSystem | Select-Object NumberOfUsers | ForEach-Object{$_.NumberOfUsers} | Out-File $log_location1 -Append
    "" | Out-File $log_location1 -Append
    "" | Out-File $log_location1 -Append
}

### 00 - GET PROCESSOR DETAILS
function get_processor_details {
    "<p><span>| 00 - GET PROCESSOR DETAILS                                           |</span></p>" | Out-File $log_location1 -Append

    Write-Host "02 - COLLECTING PROCESSOR DETAILS . . . " -ForegroundColor DarkGreen

    Get-CimInstance -ClassName Win32_Processor | Select-Object Status,Manufacturer,Name,NumberOfCores,NumberOfLogicalProcessors,ThreadCount,Caption,SocketDesignation | Format-List | Out-File $log_location1 -Append
}

### 00 - GET RAM DETAILS
function get_ram_details {
    "<p><span>| 00 - GET RAM DETAILS                                                 |</span></p>" | Out-File $log_location1 -Append

    Write-Host "03 - COLLECTING RAM DETAILS . . . " -ForegroundColor DarkGreen
    
    "" | Out-File $log_location1 -Append
    $ram1 = (Get-CimInstance Win32_PhysicalMemory | Measure-Object -Property capacity -Sum).sum /1gb
    "Total RAM: $ram1 GB" | Out-File $log_location1 -Append


    # Get-CimInstance win32_physicalmemory | Format-Table Manufacturer,Banklabel,Configuredclockspeed,Devicelocator,Capacity,Serialnumber -AutoSize
    Get-CimInstance win32_physicalmemory | Select-Object Manufacturer,Banklabel,Configuredclockspeed,Devicelocator,@{Name="Capacity, GB";Expression={$_.Capacity / 1GB}},Serialnumber | Format-Table -AutoSize | Out-File $log_location1 -Append
}

### 00 - GET DISK SPACE
function get_disk_space {
    "" | Out-File $log_location1 -Append
    "<p><span>| 00 - GET DISK SPACE                                                  |</span></p>" | Out-File $log_location1 -Append

    Write-Host "04 - COLLECTING DISK SPACE DETAILS . . . " -ForegroundColor DarkGreen

    Get-PhysicalDisk  | Format-Table -AutoSize | Out-File $log_location1 -Append
    "" | Out-File $log_location1 -Append
    Get-Disk | Format-Table -AutoSize | Out-File $log_location1 -Append

    ## 00 - GET VOLUME
    "<p><span>| 00 - GET VOLUME                                                      |</span></p>" | Out-File $log_location1 -Append

    Write-Host "05 - COLLECTING VOLUME DETAILS . . . " -ForegroundColor DarkGreen

    Get-Volume | Format-Table -AutoSize | Out-File $log_location1 -Append

}

## 00 - GET USER DETAILS
function get_user_details {
    "<p><span>| 00 - GET USER DETAILS                                                |</span></p>" | Out-File $log_location1 -Append

    Write-Host "06 - COLLECTING USER DETAILS . . . "-ForegroundColor DarkGreen

    Get-LocalUser | Select-Object Name,Enabled,LastLogon,Description | Out-File $log_location1 -Append


    ## 00 - GET ALL MEMBERS OF THE ADMINISTRATORS GROUP
    "<p><span>| 00 - GET ALL MEMBERS OF THE ADMINISTRATORS GROUP                     |</span></p>" | Out-File $log_location1 -Append

    "" | Out-File $log_location1 -Append
    Write-Host "07 - COLLECTING ALL MEMBERS OF THE ADMINISTRATORS GROUP . . . " -ForegroundColor DarkGreen

    # Get-LocalGroupMember -Group "Administrators" | Format-Table # Not Working
    net localgroup administrators | Out-File $log_location1 -Append -width 1024
    "" | Out-File $log_location1 -Append
}

### 00 - INSTALLED SOFTWARE DETAILS
function installed_software_details {
    "<p><span>| 00 - INSTALLED SOFTWARE DETAILS                                      |</span></p>" | Out-File $log_location1 -Append

    Write-Host "08 - COLLECTING INSTALLED SOFTWARE DETAILS  . . . " -ForegroundColor DarkGreen

    #Get-CimInstance -ClassName Win32_Product | Select-Object -Property Name,Vendor,Version | Sort-Object -Property Vendor | Format-Table -AutoSize | Out-File $log_location1 -Append
    Get-CimInstance -ClassName Win32_Product | Select-Object Name,Vendor,Version,InstallDate | Sort-Object Name | Format-Table -AutoSize | Out-File $log_location1 -Append -width 1024
}

### 00 - GET PROCESS DETAILS
function get_process_details {
    "<p><span>| 00 - GET PROCESS DETAILS                                             |</span></p>" | Out-File $log_location1 -Append

    Write-Host "09 - COLLECTING PROCESS DETAILS  . . . " -ForegroundColor DarkGreen

    #Get-Process | Select-Object Name,Company,ProductVersion | Format-Table -AutoSize | Out-File $log_location1 -Append
    #Get-Process -IncludeUserName | Where-Object {$_.Company -notlike '*Microsoft*'} | Select-Object Name,UserName,Company | Format-Table -AutoSize
    #Get-Process | Select-Object Name,Company | Format-Table -AutoSize | Out-File $log_location1 -Append
    # The 'IncludeUserName' parameter requires elevated user rights.
    # Get-Process -IncludeUserName | Where-Object {$_.Company -notlike '*Microsoft*'} | Select-Object Name,UserName,Company | Format-Table -AutoSize | Out-File $log_location1 -Append
    "Excluded: Microsoft Process" | Out-File $log_location1 -Append
    "" | Out-File $log_location1 -Append
    Get-Process | Where-Object {$_.Company -notlike '*Microsoft*'} | Select-Object Name,Company | Format-Table -AutoSize | Out-File $log_location1 -Append
}

### 00 - GET SERVICE DETAILS
function get_services_details {
    "<p><span>| 00 - GET SERVICE DETAILS                                             |</span></p>" | Out-File $log_location1 -Append

    Write-Host "10 - COLLECTING SERVICE DETAILS . . . " -ForegroundColor DarkGreen

    #Get-Service | Format-Table -AutoSize | Out-File $log_location1 -Append
    Get-Service | Select-Object Name,Status, StartType,DisplayName | Format-Table -AutoSize | Out-File $log_location1 -Append
}

### 00 - GET NETWORK DETAILS
function get_network_details {

    "<p><span>| 00 - GET NETWORK DETAILS                                             |</span></p>" | Out-File $log_location1 -Append

    Write-Host "11 - COLLECTING NETWORK DETAILS . . . " -ForegroundColor DarkGreen

    #Get-Process | Select-Object Name,Company,ProductVersion | Format-Table -AutoSize | Out-File $log_location1 -Append
    ipconfig /all | Out-File $log_location1 -Append
}

### Get_WindowsOptionalFeature
function Get_WindowsOptionalFeature {
    "<p><span>| 00 - GET WINDOWS OPTIONAL FEATURE                                |</span></p>" | Out-File $log_location1 -Append
    Write-Host "12 - COLLECTING WINDOWS OPTIONAL FEATURE . . . " -ForegroundColor DarkGreen
    $isadmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
    if ($isadmin -eq $true) {
    Get-WindowsOptionalFeature -Online | Where-Object {$_.State -eq "Enabled"} | Format-Table -AutoSize | Out-File $log_location1 -Append
    }
    else {
    Write-Host "NOTE: RESULT WILL NOT DISPLAY - RUN WITH ELEVATED PERMISSIONS . . . " -ForegroundColor Red
    "NOTE: RESULT WILL NOT DISPLAY - RUN WITH ELEVATED PERMISSIONS . . . "  | Out-File $log_location1 -Append
    }
    #Get-WindowsOptionalFeature -Online | Where-Object {$_.State -eq "Enabled"} | Format-Table -AutoSize | Out-File $log_location1 -Append
}

### Get_GroupPolicy
function Get_GroupPolicy {
    "<p><span>| 00 - GET GROUP POLICY                                                |</span></p>" | Out-File $log_location1 -Append
    Write-Host "13 - COLLECTING GROUP POLICY . . . " -ForegroundColor DarkGreen
    gpresult /r | Out-File $log_location1 -Append
}

#"+----------------+" | Out-File $log_location1 -Append
#"| GET FILE SHARE |" | Out-File $log_location1 -Append
#"+----------------+" | Out-File $log_location1 -Append
#Get-FileShare | Format-Table -AutoSize | Out-File $log_location1 -Append

### END WRITE ON FILE
function end_write_on_file {
    "" | Out-File $log_location1 -Append
    "" | Out-File $log_location1 -Append
    $date5 = Get-Date -UFormat "Date: %d-%m-%Y, Time: %H-%M-%S IST"
    ">> END TIME: " | Out-File $log_location1 -Append -NoNewline
    $date5 | Out-File $log_location1 -Append
    "" | Out-File $log_location1 -Append
    "<span style=background-color:powderblue>========================================================================</span>" | Out-File $log_location1 -Append
    "<span style=background-color:powderblue>| | | | |                        E  N  D                       | | | | |</span>" | Out-File $log_location1 -Append
    "<span style=background-color:powderblue>========================================================================</span>" | Out-File $log_location1 -Append
    "" | Out-File $log_location1 -Append
}

### CONVERT TXT 2 HTML
function convert_txt_2_html {
$content = Get-Content $log_location1 -Raw
$title = 'RoboticScript (roboticscript.com)'
$html = @"
<html>
    <head>
    <title>$title</title>
    <style>
    span {
    background-color: GreenYellow;
    }
    </style>
    </head>
<body>
    <pre>$content</pre>
</body>
</html>
"@
$html | Out-File $log_location2
}


menu_display_on_screen
menu_write_on_file
basic_information
get_os_details
get_processor_details
get_ram_details
get_disk_space
get_user_details
installed_software_details
get_process_details
get_services_details
get_network_details
Get_WindowsOptionalFeature
Get_GroupPolicy


end_write_on_file

convert_txt_2_html

### END OF DISPLAY SCREEN
Write-Host ""
Write-Host "SYSTEM DATA COLLECTED SUCCESSFULLY ! ! !" -BackgroundColor Green -ForegroundColor Black
Write-Host ""

Write-Host "Console will close in 5 sec . . . " -ForegroundColor Green
Write-Host "Opening the Result . . . " -ForegroundColor Green

Invoke-Item ".\$log_location2"

Start-Sleep -Seconds 5

### END


Post a Comment

0 Comments