라벨이 Powershell인 게시물 표시

[Powershell] Sort by date modified and select first 10 and show only name

Below is how to sort by date modified and select first 10 and show only name by using Get-ChildItem, Sort, Select-Object in Powershell, Windows. Get-ChildItem | sort LastAccessTime -Descending | Select-Object -First 10 | Select-Object Name

Powershell for loop

for ($i=1; $i -le 10; $i++){ mkdir $i} : make folders whose name is from 1 to 10 Thanks, JF

Basic commands for Linux/Mac OSX and Windows Powershell

Basic commands for operating systems ( Linux/Mac OSX and Windows ) I would like to introduce basic commands and their brief explanations. If you want detail usage, googling them! 1. Linux/Mac OSX pwd:  print working directory hostname:  my computer's network name mkdir :  make directory cd:  change directory ls:  list directory rmdir:  remove directory pushd:  push directory popd:  pop directory cp:  copy a file or directory mv:  move a file or directory less:  page through a file cat:  print the whole file xargs:  execute arguments find:  find files grep:  find things inside files man:  read a manual page apropos:  find what man page is appropriate env:  look at your environment echo:  print some arguments export:  export/set a new environment variable exit:  exit the shell sudo:  become super user root chmod:  change permission modifiers chown:  change ownership 2. Window

File searching and Remove the searched files in Powershell

This is very useful when you are managing your files in your computer (Windows) 1. Identify files in certain folder >>> Get-ChildItem C:/testfolder/* 2. Identify files in certain folder and remove all of them >>> Get-ChildItem C:/testfolder/* | ForEach ($_) {Remove-Item $_.fullname} 3. Search certain files including '.test' >>> Get-ChildItem C:/* -Include *.test 4. Search certain files including '.test', but excluding the files which begin with 'abc' >>> Get-ChildItem C:/* -Include *.test -Exclude abc*.test 5. Search the files including Sub folders >>> Get-ChildItem C:/* -Include *.test -Recurse 6. Search the files including Sub folders and remove all of them >>> Get-ChildItem C:/* -Include *.test -Recurse | ForEach ($_) {Remove-Item $_.fullname} 7. Search the files, Print them, and then remove all of them >>> Get-ChildItem C:/* -Include *.test -Recurse || ForEach (

The meaning of '$_' in Powershell

이미지
When you are using Powershell, you easily run into this: $_ The meaning is the variable for the current values in the pipe line. For example, >>> 1,2,3 | %{ write-host $}% 1 2 3 Additionally, %{ } block means every value in the array. Thanks Have Fun!

ForEach in Powershell

ForEach - Loop statement Syntax is as below. ForEach (item In collection) {ScriptBlock} item: A variable to hold the current item collection: A collection of objects e.g. filenames, registry keys, servernames ScriptBlock: A block of script to run against each object. Thanks, Have Fun! The source: http://ss64.com/ps/foreach.html

How to open folder in Powershell

There are many ways to open folder in Powershell. 1) Invoke-Item cmdlet: ii >>> ii . >>> ii C:\windows 2) start >>> start . >>> start C:\windows 3) explorer.exe >>> explorer.exe . >>> explorer.exe C:\windows 4) explorer >>> explorer . >>> explorer C:\windows 5) hh >>> hh . >>> hh C:\windows >>> hh http://xxx.xxx.xxx/xxx

'For' statement in Powershell

Fundamental syntax for (initial; condition; repeat)      { command block } Example: >>> for ($i=1, $i -le 10; $i++){      Command block      }