ComputerInformation.psm1

New-Module -Name ComputerInformation -ScriptBlock {
Function Get-Info {
Do {
$AllInfo = "1"
$PasswordLastChanged = "2"
$Message = "3"
$Password = "4"
$Programs = "5"
$CleanTemp = "6"
$DeleteHistory = "7"
$DISM = "8"
$RunningTasks = "9"
$KillTask = "10"
$SFC = "11"
$Close = "00"
$Exit = "0"
        Write-Output " "
    $Choice = Read-Host -Prompt "Please select from the list below:
 
        1. Get information about a computer
 
        2. Computer cleanup commands
 
        0. Exit script
 
        "


Start-Sleep -Milliseconds 200
    If ($Choice -eq "1") {
        Do  {
        $Command01 = Read-Host -Prompt "Enter a Number from the list below:
        1. Computer Info
 
        2. Last password change
 
        3. Prompt Message on remote computer
 
        4. Set Password and enable local Admin
 
        5. View installed Programs
         
        0. Main Menu
 
        00. Exit Script
         
        "

            Switch ($Command01) {
                    $AllInfo {
                         Write-Output " "
        $Computer = Read-Host -Prompt "Enter Computer name"
            Write-Output " "

        Invoke-Command -ComputerName $Computer -ScriptBlock {
            $Model = Get-WmiObject -Class Win32_ComputerSystem 
            $Memory = [Math]::Round($Model.TotalPhysicalMemory/1GB)
            $User = Query User
            #((Get-WMIObject -class Win32_ComputerSystem | Select-Object -ExpandProperty username))
            $Ram = [Math]::Round((Get-WmiObject -Class Win32_ComputerSystem).TotalPhysicalMemory/1GB)
            $SerialNum = Get-WmiObject -Class Win32_bios
            $Up =(Get-Date) - (gcim Win32_OperatingSystem).LastBootUpTime
            $UpSelect = $Up | Select-Object -Property Days,Hours,Minutes 
            $UpTime = $UpSelect |  Format-Table -AutoSize
            $HDType = Get-PSDrive | Where-Object -Property Name -EQ C
            $HDUsed = $HDType | Select-Object -ExpandProperty Used
            $Size = [Math]::Round($HDUsed/1GB)
            $HDFree = $HDType | Select-Object -ExpandProperty Free
            $Free = [Math]::Round($HDFree/1GB)

                    
            "Computer Number: " + $Model.Name 
            Write-Output ""
            $IPAddress = Get-NetIPAddress
            $IP = $IPAddress | Where-Object {$_.IpAddress -like "10.*"}
            "IP Address: " + $IP.IPAddress
            Write-Output ""
            $User
            Write-Output ""
            "Computer Model: " + $Model.Model
            Write-Output ""
            $Version = (Get-WMIObject win32_operatingsystem).Name
            "Operating System: " + $Version                          
            Write-Output ""
            "Serial Number: " + $SerialNum.SerialNumber 
            Write-Output ""
            "Total RAM: " + $Ram + "GB"
            Write-Output ""
            "Hard Drive Size: " + ($Size + $Free)
            "Free Space: " + $Free 
                Write-Output ""
                Write-Output "Time since last reboot"
            $UpTime
                Write-Output ""

            }
                    }
                    $Programs {
                            Write-Output " "
                        $Computer = Read-Host -Prompt "Enter computer number"
                            Write-Output " "
                        Invoke-Command -ComputerName $Computer -ScriptBlock {
                        $Programs = Get-WmiObject -Class Win32_Product 
                        $AllPrograms = $Programs | Sort-Object -Property Name,InstallDate
                        $Name = $AllPrograms | Select-Object -Property Name,Version
                        $Name 
                            Read-Host -Prompt "Press any key to go back to Selection Menu."
                            Write-Output " "
                            Write-Output " "
                        }
                        }
                    $Message {
                                Write-Output " "
                            $Computer = Read-Host -Prompt "Enter computer number"
                                Write-Output " "
                            Invoke-Command -ComputerName $Computer -ScriptBlock {
                                }
                            Function remote_message{
                                $message = Read-Host -Prompt 'Enter Message';
                                Invoke-WmiMethod -Class win32_process -ComputerName $Computer -Name create -ArgumentList  "c:\windows\system32\msg.exe * $message"}
                            remote_message 

                            Read-Host -Prompt "Press any key to go back to Selection Menu."
                                Write-Output " "
                                Write-Output " "
                            }
                    
                    $ChangePass {
                                Write-Output " "
                            $All = Read-Host -Prompt "Do you want to run on 1 or All computers?"
                                If ($All -eq 1) {
                                        Write-Output " "
                                    $Computer = Read-Host -Prompt "Enter computer number"
                                        Write-Output " "
                                        Write-Output " "
                                    Invoke-Command -ComputerName $Computer -ScriptBlock { 
                                        Enable-LocalUser -Name "Administrator"
                                        $NewPass = Read-Host -Prompt "New password"
                                        Write-Output " "
                                            Write-Output "INFO: Admin password successfully changed."
                                            Write-Output " "
                                            Write-Output " "
                                        Net User Administrator $NewPass
                                            
                                        }
                                }
                                Else {
                                        Write-Output " "
                                    $AllComputers = Get-Content -Path "\\FileSaveLocation\AllComputers.txt" -Force -Wait
                                    Invoke-Command -ComputerName $AllComputers -ScriptBlock {
                                        Enable-LocalUser -Name "Administrator"
                                        $NewPass = Read-Host -Prompt "New password"
                                        Net User Administrator $NewPass
                                            Write-Output " "
                                            Write-Output "INFO: Admin password successfully changed."
                                            Write-Output " "
                                            Write-Output " "
                                    }
                                }
                                    Read-Host -Prompt "Press any key to go back to Selection Menu."
                                    Write-Output " "
                                    Write-Output " "
                        }
                    $PasswordLastChanged {
                                Write-Output " "
                            $ADUser = Read-Host -Prompt 'Enter Username'
                            Get-ADUser -Identity $ADUser -Properties PasswordLastSet | Select -Property PasswordLastSet
                                Write-Output " "
                                Write-Output " "
                    }
                    $Close {
                        exit
                        "INFO: Thank you, you have now exited the command."
                    }
                }
        }
        Until ($Command01 -eq $Exit) {
           
        }
    }
    ElseIf ($Choice -eq "2") {
        Do {
        $Command03 = Read-Host -Prompt "Please select from the list below:
             
            6. Clean Temp files
 
            7. Delete Internet History
 
            8. DISM file check
 
            9. View Running Tasks
 
            10. Kill running tasks
 
            11. SFC scan
         
            0. Main Menu
 
            00. Exit Script
            
            "


            Switch ($Command03) {
                $CleanTemp {
                                Write-Output " "
                            $Computer = Read-Host -Prompt "Enter computer number"
                                Write-Output " "
                            Invoke-Command -ComputerName $Computer -ScriptBlock {
                                Write-Output "INFO: Removing Temp files from User profiles."
                                Write-Output " "
                            Get-ChildItem "C:\users" -Force | Foreach { 
                            Get-ChildItem "$($_.FullName)\AppData\Local\Temp" -ErrorAction Ignore | Remove-Item -Force -Recurse -ErrorAction Ignore
                            }
                                Write-Output "INFO: User Temp files have been deleted."
                                Write-Output " "
                                Write-Output "INFO: Removing Temp files from Windows folder."
                                Write-Output " "
                            Remove-Item -Path "C:\Windows\Temp" -Force -Recurse -ErrorAction Ignore
                                Write-Output "INFO: Windows Temp files have been deleted."
                                Write-Output " "  }
                            Read-Host -Prompt "Press any key to go back to Selection Menu."
                                Write-Output " "
                                Write-Output " "
                        }
                $DeleteHistory {
                                Write-Output " "
                            $Computer = Read-Host -Prompt "Enter computer number"
                                Write-Output " "
                            Invoke-Command -ComputerName $Computer -ScriptBlock {
                                RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1
                                RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2
                                RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8
                                rd /S c:\$Recycle.Bin  }
                            Read-Host -Prompt "Press any key to go back to Selection Menu."
                                Write-Output " "
                                Write-Output " "
                        }
                $DISM {
                                Write-Output " "
                            $Computer = Read-Host -Prompt "Enter computer number"
                                Write-Output " "
                            Invoke-Command -ComputerName $Computer -ScriptBlock {
                                dism.exe /online /cleanup-image /restorehealth  }
                            Read-Host -Prompt "Press any key to go back to Selection Menu."
                                Write-Output " "
                                Write-Output " "
                        }
                $RunningTasks {
                            Write-Output " "
                        $Computer = Read-Host -Prompt "Enter computer number"
                            Write-Output " "
                        Invoke-Command -ComputerName $Computer -ScriptBlock {
                        Get-Process | Select-Object -Property Name }
                            Read-Host -Prompt "Press any key to go back to Selection Menu."
                            Write-Output " "
                            Write-Output " "
                        }
                $KillTask {
                                Write-Output " "
                            $Computer = Read-Host -Prompt "Enter computer number"
                                Write-Output " "
                            Invoke-Command -ComputerName $Computer -ScriptBlock {
                                Try {
                                        Write-Output " "
                                    $Task = Read-Host -Prompt 'What Task do you want to Kill'
                                    Stop-Process -Name "*$Task*" -Force -PassThru
                                    $More = Read-Host -Prompt "Do you want to kill another Task Yes/No"
                                While ($More -like "yes") {
                                        Write-Output " "
                                    $Task = Read-Host -Prompt 'What Task do you want to Kill'
                                    Stop-Process -Name "*$Task*" -Force -PassThru
                                    $More = Read-Host -Prompt "Do you want to kill another Task Yes/No"
                                    }
                                }
                                Catch {

                                }        
                            }
                            Read-Host -Prompt "Press any key to go back to Selection Menu."
                                Write-Output " "
                                Write-Output " "
                            }
                $SFC {
                            Write-Output " "
                            $Computer = Read-Host -Prompt "Enter computer number"
                                Write-Output " "
                            Invoke-Command -ComputerName $Computer -ScriptBlock {
                                
                                sfc /scannow 
                                }
                        }
                $Close {
                        Exit 
                    }
                }
        }
        Until ($Command03 -eq $Exit) {
        
        }
    }
    ElseIf ($Choice -eq "0") {
        
    }
    Else {
        Read-Host -Prompt "Invalid selection please try again."
    }
    }  

 Until ($Choice -eq $Exit) {
"INFO: Thank you, you have now exited the command."
} 
}
} | Import-Module