echo '' ;

Microsoft Windows PowerShell

What is windows PowerShell?

Windows PoweShell is tool from Microsoft. Used for task automation and configuration management framework.

PowerShell Examples

How to Open “Powershell.exe” in Windows 7,8,10,11?

How to Open “Powershell.exe” using RUN prompt in Windows 7,8,10,11?

  • Method 1: Windows + R  and type powershell  and hit “enter”
  • Method 2 : Click Start, type PowerShell, and then click Windows PowerShell.
  • Method 3 : From the Start menu, click Start, click All Programs, click Accessories, click the Windows PowerShell folder, and then click Windows PowerShell.

How to Open PowerShell in a Folder in Windows Explorer?

  • Go to folder PATH or Address bar. (Shortcut CNTL + L)
  • Type “powershell.exe” or “powershell
  • Hit enter to open the PowerShell in a folder.

How to open PowerShell for File?

  • Select the file wanna open with PowerShell and click
  • Open windows PowerShell: ALT + F + S + R (Shortcut)
  • Open windows PowerShell as Administrator: ALT + F + S + A (Shortcut)

How to get Date and Time using Windows Powershell?

@echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"set "datestamp=%YYYY%%MM%%DD%" & set "timestamp=%HH%%Min%%Sec%"

set "fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%"
echo datestamp: "%datestamp%"
echo timestamp: "%timestamp%"
echo fullstamp: "%fullstamp%"
pause

How to create a new folder based on files Created data and move to respective folder using PowerShell?

$rootpath = 'C:\Users\Arunprakash.m\Desktop\Test'
$files = Get-ChildItem $rootpath -File
foreach($file in $files) {
    $foldername = $file.CreationTime.ToString('yyyyMMdd')
    $topath = "$rootpath\$foldername"
    if(-not(Test-Path $topath -PathType Container)){
        New-Item $topath -ItemType Directory
    }
    Move-Item $file.FullName $topath
}

How to create a new folder based on files Last Saved data and move to respective folder using PowerShell?

$rootpath = 'C:\Users\Arunprakash.m\Desktop\Test'
$files = Get-ChildItem $rootpath -File
foreach($file in $files) {
    $foldername = $file.LastWriteTime.ToString('yyyyMMdd')
    $topath = "$rootpath\$foldername"
    if(-not(Test-Path $topath -PathType Container)){
        New-Item $topath -ItemType Directory
    }
    Move-Item $file.FullName $topath
}

How to remove the particular character in multiple folder name using PowerShell?

  • Step-1: Navigate to the respective folder
  • Step-2: Open the “cmd” prompt
  • Step-3: Enter into “Powershell”
  • Step-4: Type the command get-childitem * | foreach { rename-item $_ $_.Name.Replace("_","") }
  • Step-5: Hit enter to change the folders name

Before folder structure

  • Folder-1 : 2020-01-01
  • Folder-2 : 2020-01-02

After folder structure

  • Folder-1 : 20200101
  • Folder-2 : 20200102

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.