Showing posts with label Powershell. Show all posts
Showing posts with label Powershell. Show all posts

Wednesday, September 2, 2026

Powershell select query for windows with tables

 Get-CimInstance -Query "select * from Win32_OperatingSystem "

Get-CimInstance -Query "SELECT * FROM Win32_SystemDriver WHERE Name='ntfs'"


Get-CimInstance -Query "select * from win32_baseService where Name='Themes'"


tables


Win32_Service

Win32_SystemDriver


⚙️ Operating System Core & Drivers
  • Win32_Service: Standard Windows background services (the counterpart to system drivers).
  • Win32_PnPSignedDriver: Digital signature and version details for Plug-and-Play drivers (great for checking if a driver is outdated).
  • Win32_Bus: Physical and logical expansion buses (like PCI, USB).
  • Win32_DeviceChangeEvent: Monitors when devices/drivers are added or removed from the system.
🔌 Physical Hardware & Devices
  • Win32_PnPEntity: Every Plug-and-Play device recognized by Device Manager (cameras, mice, keyboards, etc.).
  • Win32_DiskDrive: Physical hard drives and SSDs (shows model, serial number, and size).
  • Win32_VideoController: Graphics cards/GPUs and active video drivers.
  • Win32_NetworkAdapter: Physical and virtual network cards.
🖥️ System Management & Memory
  • Win32_Processor: CPU details (cores, clock speed, current load).
  • Win32_PhysicalMemory: Physical RAM sticks (shows capacity, speed, and manufacturer).
  • Win32_BIOS: Motherboard BIOS/UEFI version, serial number, and manufacturer.
  • Win32_OperatingSystem: General Windows details (build version, boot time, registered user).


Friday, January 23, 2026

a to z alphabets copy and paste in Notepad Chrome

   #Note This first line is mandatory [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

# Start WinWord (if not already running)

Start-Process -FilePath "chrome.exe"

# Wait for WinWord to open and become active

Start-Sleep -Seconds 3

# Activate the WinWord window (adjust the title if necessary)

$wshell = New-Object -ComObject wscript.shell

#$wshell.AppActivate("Document1 - Word") # Or the actual document title

 (New-Object -ComObject "wscript.shell").SendKeys('data:text/html, <title>Notepad</title><body contenteditable style="font-size:18px;line-height:1.6;font-family:sans-serif;">')


  (New-Object -ComObject "wscript.shell").SendKeys("{ENTER}")


Start-Sleep -Seconds 1


  (New-Object -ComObject "wscript.shell").SendKeys("{TAB}")


  for ($k = 1; $k -le 10; $k++) {

 for ($i = 1; $i -le 50; $i++) {

 $j = [char](65 + $i)

   (New-Object -ComObject "wscript.shell").SendKeys("$j")

  }

  [System.Windows.Forms.SendKeys]::SendWait("^{a}")


[System.Windows.Forms.SendKeys]::SendWait("^{c}")


[System.Windows.Forms.SendKeys]::SendWait("{RIGHT}")

[System.Windows.Forms.SendKeys]::SendWait("^{v}")

  (New-Object -ComObject "wscript.shell").SendKeys("{Enter}")





}

Wednesday, January 21, 2026

A to Z alphabets in chrome with notepad with powershell

  #Note This first line is mandatory [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

# Start WinWord (if not already running)

Start-Process -FilePath "chrome.exe"

# Wait for WinWord to open and become active

Start-Sleep -Seconds 3

# Activate the WinWord window (adjust the title if necessary)

$wshell = New-Object -ComObject wscript.shell

#$wshell.AppActivate("Document1 - Word") # Or the actual document title

 (New-Object -ComObject "wscript.shell").SendKeys('data:text/html, <title>Notepad</title><body contenteditable style="font-size:18px;line-height:1.6;font-family:sans-serif;">')

  (New-Object -ComObject "wscript.shell").SendKeys("{ENTER}")

Start-Sleep -Seconds 1

  (New-Object -ComObject "wscript.shell").SendKeys("{TAB}")

 for ($k = 1; $k -le 50; $k++) {

 for ($i = 1; $i -le 77; $i++) {

 $j = [char](45 + $i)

   (New-Object -ComObject "wscript.shell").SendKeys("$j")

  }

  (New-Object -ComObject "wscript.shell").SendKeys("{Enter}")

}



Thursday, January 15, 2026

How to copy and paste in Powershell from one notepad to another notepad - CTRL + C and CTRL + V in Powershell - CTRL C in Powershell and CTRL V in Powershell

 #Note This first line is mandatory 


[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")


# Start WinWord (if not already running)

Start-Process -FilePath "notepad.exe"

# Wait for WinWord to open and become active


Start-Sleep -Seconds 3

Start-Process -FilePath "notepad.exe"


Start-Sleep -Seconds 3

# Activate the WinWord window (adjust the title if necessary)

[System.Windows.Forms.SendKeys]::SendWait("123")

Start-Sleep -Seconds 3

[System.Windows.Forms.SendKeys]::SendWait("^{a}")

Start-Sleep -Seconds 3

[System.Windows.Forms.SendKeys]::SendWait("^{C}")

Start-Sleep -Seconds 3

[System.Windows.Forms.SendKeys]::SendWait("%{TAB}")


Start-Sleep -Seconds 3

[System.Windows.Forms.SendKeys]::SendWait("^{v}")


ref:- https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.sendkeys.send?view=windowsdesktop-10.0

Note: ctrl C and Ctrl v , c and v are in small letters.

Friday, January 2, 2026

Powershell a to z alphabets 50 times in notepad and 1 to 9 digits

 #Note This first line is mandatory [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

# Start WinWord (if not already running)

Start-Process -FilePath "notepad.exe"

# Wait for WinWord to open and become active

Start-Sleep -Seconds 3

# Activate the WinWord window (adjust the title if necessary)

$wshell = New-Object -ComObject wscript.shell

#$wshell.AppActivate("Document1 - Word") # Or the actual document title

Start-Sleep -Seconds 1

 for ($k = 1; $k -le 25; $k++) {

 for ($i = 1; $i -le 75; $i++) {

 $j = [char](40 + $i)

   (New-Object -ComObject "wscript.shell").SendKeys("$j")

  }

  (New-Object -ComObject "wscript.shell").SendKeys("{Enter}")

}


Wednesday, December 31, 2025

Right click in powershell 50 times

 #Context menu with Powershell


 for ($i = 1; $i -le 50; $i++) {


  [System.Windows.Forms.SendKeys]::SendWait("+{F10}") 

    Write-Host "Iteration: $i"


}



Monday, December 22, 2025

Refresh With powershell

 Start-Sleep -Seconds 3

 [System.Windows.Forms.SendKeys]::SendWait("^+{F10}") 

 [System.Windows.Forms.SendKeys]::SendWait("e") 

Right Click in powershell - Context menu in Powershell

 #Context menu with Powershell

 [System.Windows.Forms.SendKeys]::SendWait("+{F10}") 


Shift + F10

how to create Folder in Powershell - How to open explorer and create folder in powershell

 Add-Type -AssemblyName System.Windows.Forms

Add-Type -AssemblyName Microsoft.VisualBasic


Start-Process -FilePath "explorer.exe"


# Wait for WinWord to open and become active


Start-Sleep -Seconds 1


(New-Object -ComObject "wscript.shell").SendKeys("^{l}")

Start-Sleep -Seconds 1

(New-Object -ComObject "wscript.shell").SendKeys("D:\")

Start-Sleep -Seconds 1

(New-Object -ComObject "wscript.shell").SendKeys("{Enter}")

#Context menu with Powershell

 [System.Windows.Forms.SendKeys]::SendWait("^+{F10}") 


 Start-Sleep -Seconds 1

 [System.Windows.Forms.SendKeys]::SendWait("^+n") 

 Start-Sleep -Seconds 1

 (New-Object -ComObject "wscript.shell").SendKeys("{Enter}")

 


 

Friday, December 19, 2025

how to send A to Z in Powershell - How to send alphabets in Powershell


#Note This first line is mandatory 

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")


# Start WinWord (if not already running)

Start-Process -FilePath "excel.exe"

# Wait for WinWord to open and become active

Start-Sleep -Seconds 3


# Activate the WinWord window (adjust the title if necessary)

$wshell = New-Object -ComObject wscript.shell

#$wshell.AppActivate("Document1 - Word") # Or the actual document title

Start-Sleep -Seconds 1


 for ($i = 1; $i -le 77; $i++) {

 $j = [char](45 + $i)


[System.Windows.Forms.SendKeys]::SendWait("$j")

}


or

#  lt is less than and le is less than or equal to 

for ($test = 0; $test -lt 26; $test++)

{

    [char](65 + $test)

}

Monday, December 15, 2025

How to get x axis and y axis position of Mouse cursor in Powershell

 # Load the necessary assemblies for accessing mouse position information

Add-Type -AssemblyName System.Drawing

Add-Type -AssemblyName System.Windows.Forms


Write-Host "Move your mouse. Press Ctrl+C to stop."


while ($true) {

    # Get the current mouse position

    $cursorPosition = [System.Windows.Forms.Cursor]::Position

    $x = $cursorPosition.X

    $y = $cursorPosition.Y

    

    # Print the coordinates. Using Write-Host with -NoNewline and carriage return `r` 

    # overwrites the previous line in the console for a cleaner continuous update.

    Write-Host "`rX: $x | Y: $y" -NoNewline

    

    # Wait for a short period to prevent the loop from consuming too much CPU

    Start-Sleep -Milliseconds 100

}



or for single position



Add-Type -AssemblyName System.Windows.Forms

$mousePosition = [System.Windows.Forms.Cursor]::Position

Write-Host "Current mouse position is X: $($mousePosition.X), Y: $($mousePosition.Y)"

How to move mouse position with powershell - Inverse for loop in Powershell

 for ($i = 100; $i -ge 10; $i--) {

   Start-Sleep -Milliseconds 1


   Write-Host "Iteration: $i"

 [System.Windows.Forms.Cursor]::Position =  "$i, $i "

}


or with 10 decrement

 for ($i = 1000; $i -ge 10; $i -= 10) {

   Start-Sleep -Milliseconds 1

   Write-Host "Iteration: $i"

 [System.Windows.Forms.Cursor]::Position =  "$i, $i "

}

How to change the Cursor position with Powershell - How to change the mouse position with Powershell

 [System.Windows.Forms.Cursor]::Position = "700,700"


How to open and send keys in Calculator and Add operation in Powershell

 Add-Type –AssemblyName UIAutomationClient

Add-Type –AssemblyName UIAutomationTypes

$calc = [Diagnostics.Process]::Start('calc')

#wait for the UI to appear

$null = $calc.WaitForInputIdle(5000)

sleep –s 2

$calcWindowId = ((Get-Process).where{$_.MainWindowTitle -eq 'Calculator'})[0].Id

$root = [Windows.Automation.AutomationElement]::RootElement

$condition = New-Object Windows.Automation.PropertyCondition([Windows.Automation.AutomationElement]::ProcessIdProperty, $calcWindowId)

$calcUI = $root.FindFirst([Windows.Automation.TreeScope]::Children, $condition)


function FindAndClickButton($name){

$condition1 = New-Object Windows.Automation.PropertyCondition([Windows.Automation.AutomationElement]::ClassNameProperty, "Button")

$condition2 = New-Object Windows.Automation.PropertyCondition([Windows.Automation.AutomationElement]::NameProperty, $name)

$condition = New-Object Windows.Automation.AndCondition($condition1, $condition2)

$button = $calcUI.FindFirst([Windows.Automation.TreeScope]::Descendants, $condition)

$button.GetCurrentPattern([Windows.Automation.InvokePattern]::Pattern).Invoke()

}


#get and click the buttons for the calculation


FindAndClickButton Five

FindAndClickButton Plus

FindAndClickButton Nine

FindAndClickButton Equals


#get the result

$condition = New-Object Windows.Automation.PropertyCondition([Windows.Automation.AutomationElement]::AutomationIdProperty, "CalculatorResults")

$result = $calcUI.FindFirst([Windows.Automation.TreeScope]::Descendants, $condition)

$result.current.name

Wednesday, December 10, 2025

How to send Ctrl + F4 key in Powershell - How to send CTRL ALT Shift keys in Powershell - How to open Application in Powershell - How to open File Explorer in Powershell

 Start-Sleep -Seconds 5


$wshell = New-Object -ComObject WScript.Shell

$wshell.SendKeys("^{F4}")



or

#Note This first line is mandatory 


[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

# Start WinWord (if not already running)

Start-Process -FilePath "explorer.exe"

# Wait for WinWord to open and become active

Start-Sleep -Seconds 3

(New-Object -ComObject "wscript.shell").SendKeys("^{ESC}")

# Activate the WinWord window (adjust the title if necessary)

[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")


ref:- https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.sendkeys.send?view=windowsdesktop-10.0


https://stackoverflow.com/questions/19824799/how-can-i-send-ctrl-or-alt-any-other-key

Thursday, November 27, 2025

How to send one thousand time window keys with powershell

 for ($i = 0; $i -lt 1000; $i++) {


    (New-Object -ComObject "wscript.shell").SendKeys("^{ESC}")

    # Optional: Add a small delay (e.g., 10 milliseconds) to prevent overwhelming the system

    Start-Sleep -Milliseconds 10

}


Note:-     Start-Sleep -Milliseconds 10 // Fastest

    Start-Sleep -Milliseconds 100  //More Fast

    Start-Sleep -Milliseconds 1000  //Slow

How to click window button and open file explorer with powershell

 (New-Object -ComObject "wscript.shell").SendKeys("^{ESC}")


Start-Sleep -Seconds 3

[System.Windows.Forms.SendKeys]::SendWait("file explorere")


[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")

One thousand times left click in PowerShell

 Add-Type -AssemblyName System.Windows.Forms

Add-Type -AssemblyName System.Drawing


function Send-MouseClick {

    # Define the necessary Win32 API function for mouse events

    $signature = @'

    [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]

    public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);

'@


    $mouseEvents = Add-Type -MemberDefinition $signature -Name "Win32MouseEvents" -Namespace "Windows" -PassThru


    # Mouse event flags

    $MOUSEEVENTF_LEFTDOWN = 0x0002

    $MOUSEEVENTF_LEFTUP = 0x0004


    # Get current cursor position

    $cursorPos = [System.Windows.Forms.Cursor]::Position

    $x = $cursorPos.X

    $y = $cursorPos.Y


    # Perform the left mouse button down and up events

    $mouseEvents::mouse_event($MOUSEEVENTF_LEFTDOWN, $x, $y, 0, 0)

    $mouseEvents::mouse_event($MOUSEEVENTF_LEFTUP, $x, $y, 0, 0)

}


# Loop 1000 times to perform 1000 clicks

for ($i = 0; $i -lt 1000; $i++) {

    Send-MouseClick

    # Optional: Add a small delay (e.g., 10 milliseconds) to prevent overwhelming the system

    Start-Sleep -Milliseconds 10

}


Write-Host "1000 clicks performed."


Friday, November 21, 2025

For loop in powershell

 for ($i = 1; $i -le 5; $i++) {

    Write-Host "Iteration: $i"

}


with 10 increments

 for ($i = 1; $i -le 50; $i += 10) {

    Write-Host "Iteration: $i"

}