Showing posts with label PowerShell. Show all posts
Showing posts with label PowerShell. Show all posts

2023-04-05

Count files in a folder from Command Prompt / PowerShell

  • Command prompt 
    • dir *.* /a-d | find "File(s)"
    • dir *.* /b /a-d | find /c /v ""
  • PowerShell
    • (Get-ChildItem C:\csv -filter "*.*").Count
    • (Get-ChildItem C:\csv -recurse -filter "*.*").Count recursive search
    • (Get-ChildItem C:\csv -filter "*.*").Count
    • [System.IO.Directory]::GetFiles("c:\Path").Count

2021-01-02

List installed printers from command line / PowerShell

Open a command prompt and run:

wmic printer list brief

Open PowerShell and run:

Get-Printer | Format-List list printers with details

Get-Printer | Format-List Name list printers names

2019-08-13

remove IMG_ from files / rename file from command prompt or PowerShell

Open command prompt and enter:

ren "img_*.jpg" "////*.jpg"

Open PowerShell and run:

get-childitem *.jpg | foreach { rename-item $_ $_.Name.Replace("IMG_", "") }

2019-04-12

Get powershell version

Open PowerShell and run the following command:

$PSVersionTable.PSVersion

Find last password change of specified user

Open powershell and run the following command:

Get-ADUser username -properties passwordlastset

2019-01-30

Open PowerShell transcripts folder

explorer split-path -path $profile

Run Start-Transcript every time you start PowerShell


  • open PowerShell with admin rights
  • display the path to the Windows PowerShell profile
    • $profile
  • check if Windows PowerShell profile has been created on the system
    • test-path $profile
  • to create a profile
    • new-item -path $profile -itemtype file -force
  • open your profile
    • notepad $profile
  • enable the transcript
    • Start-Transcript
  • if you get this error "File c:\Users\YourUserName\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 cannot be loaded because running scripts is disabled on this system", fix it with this:
    • Set-ExecutionPolicy -ExecutionPolicy RemoteSigned