Posts

gather last reboot events

 function Write-Log {     param (         [string]$Message,         [string]$LogFilePath = "C:\Windows\Logs\Software\LastRebootEvent.log"     )     $Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"     $LogMessage = "$Timestamp : $Message"          $LogDir = [System.IO.Path]::GetDirectoryName($LogFilePath)     if (!(Test-Path -Path $LogDir)) {         New-Item -ItemType Directory -Path $LogDir -Force     }          $LogMessage | Out-File -FilePath $LogFilePath -Append -Encoding UTF8 } Write-Log "Starting to gather last reboot events..." # Event IDs to filter: 1074 (user/system initiated restart/shutdown), 6005 (system startup), 6006 (clean shutdown), 6008 (unexpected shutdown) $EventIDs = @(1074, 6005, 6006, 6008) # Get events from the System log within the last 90 days $Events = Get-WinEvent -FilterHashtable @{ ...

Get information about physical disks

 # Get information about physical disks $disks = Get-PhysicalDisk # Output disk details foreach ($disk in $disks) {     Write-Host "Disk Number: $($disk.DeviceID)"     Write-Host "Model: $($disk.Model)"     Write-Host "Manufacturer: $($disk.Manufacturer)"     Write-Host "Serial Number: $($disk.SerialNumber)"     Write-Host "Size: $($disk.Size / 1GB) GB"     Write-Host "MediaType: $($disk.MediaType)"     Write-Host "HealthStatus: $($disk.HealthStatus)"     Write-Host "OperationalStatus: $($disk.OperationalStatus)"     Write-Host "--------------" }

usrclass.dat and IconCache.db User profile clean up

 $ErrorActionPreference = "SilentlyContinue" $Report = $Null $Path = "C:\Users" $ExcludedUsers ="Default", "Public", "Administrator","*$*",".NET *","*MS*","Default." $UserFolders = $Path | GCI -Directory -Exclude $ExcludedUsers ForEach ($UserFolder in $UserFolders) {     $UserName = $UserFolder.Name $dat = Get-Item "$Path\$Username\AppData\Local\Microsoft\Windows\UsrClass.dat" -force         If($dat){ $UserClass = $dat.LastWriteTime $Db = Get-Item "$Path\$Username\AppData\Local\IconCache.db" -force         If($db){ $IconCache = $Db.LastWriteTime if( ($($UserClass.Year) -lt ((Get-Date).AddYears(-1)).year) -and ($($IconCache.Year) -lt ((Get-Date).AddYears(-1)).year))     {         Write-Host "UMCT : Deleting user folder $UserName and its last used by usrclass.dat and IconCache.db date is : $UserClass - $IconCache " -ForegroundColor Cyan     Set-Location C:\Users...

usrclass.dat user profile clean up

 $ErrorActionPreference = "SilentlyContinue" $Report = $Null $Path = "C:\Users" $ExcludedUsers ="Default", "Public", "Administrator","*$*",".NET *","*MS*","Default." $UserFolders = $Path | GCI -Directory -Exclude $ExcludedUsers ForEach ($UserFolder in $UserFolders) {     $UserName = $UserFolder.Name $Db = Get-Item "$Path\$Username\AppData\Local\Microsoft\Windows\UsrClass.dat" -force         If($db){ $UserClass = $Db.LastWriteTime if ($($UserClass.Year) -lt ((Get-Date).AddYears(-1)).year)     {         Write-Host "Going to be delete the user folder $UserName and its last used by usrclass.dat  date is :  $UserClass " -ForegroundColor Cyan     Set-Location C:\Users     Remove-Item -Path $($username) -Recurse -Force -WhatIf                      $profilePath = "C:\Users\$UserName"                 $pro...

User Idle session time

Add-Type @"     using System;     using System.Runtime.InteropServices; "@ # Define the structure for LASTINPUTINFO $StructLASTINPUTINFO = @"     using System;     using System.Runtime.InteropServices;     public struct LASTINPUTINFO {         public uint cbSize;         public uint dwTime;     }     public class UserInput {         [DllImport("user32.dll")]         [return: MarshalAs(UnmanagedType.Bool)]         public static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);         public static uint GetIdleTime() {             LASTINPUTINFO lii = new LASTINPUTINFO();             lii.cbSize = (uint)Marshal.SizeOf(typeof(LASTINPUTINFO));             GetLastInputInfo(ref lii);         ...

Complete List of Windows Update Error Codes

Error Code Dec Error Code String Error Description 0x00000000 -4294967296 Success   0x00000001 -4294967295 ERROR_INVALID_FUNCTION   0x0000007B -4294967173 Error_Invalid_Name The filename, directory name,or volume label syntax is incorrect 0x00000275 -4294966667 Error_cant_enable_Deny_only A group marked use for deny only can not be enabled 0x0000041D -4294966243 ERROR_SERVICE_REQUEST_TIMEOUT The service did not respond to the start or control request in a timely fashion. 0x000004C3 -4294966077 Error_Session_Credential_Conflict Multiple connections to a server or shared resource by the same user,using more than one user name, are not allowed. 0x000004C5 -4294966075 Error_Du...