User Tools

Site Tools


program_lang:powershell_misc

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
program_lang:powershell_misc [2021/12/31 20:04]
manu
program_lang:powershell_misc [2022/11/18 17:45] (current)
manu
Line 5: Line 5:
 List all commands, you can add as parameter **-examples** **-full** **-detailed** List all commands, you can add as parameter **-examples** **-full** **-detailed**
 <cli prompt='>'>​ <cli prompt='>'>​
-PS /​home/​manu>​ get-command ​+PS /​home/​manu>​ get-command ​*
 ... ...
 PS /​home/​manu>​ get-command *service* PS /​home/​manu>​ get-command *service*
 +</​cli>​
 +
 +List Get-Command cmdlet with an alias
 +<cli prompt='>'>​
 +PS> Get-Command -Name dir
 +CommandType ​    ​Name ​                                              ​ModuleName
 +----------- ​    ​---- ​                                              ​----------
 +Alias           dir -> Get-ChildItem
 </​cli>​ </​cli>​
  
Line 13: Line 21:
 <cli prompt='>'>​ <cli prompt='>'>​
 PS /​home/​manu>​ get-command -module activedirectory PS /​home/​manu>​ get-command -module activedirectory
 +</​cli>​
 +
 +This command gets all of the cmdlets, sorts them alphabetically by the noun in the cmdlet name, and then displays them in noun-based groups:
 +<cli prompt='>'>​
 +PS > Get-Command -Type Cmdlet | Sort-Object -Property Noun | Format-Table -GroupBy Noun
 +</​cli>​
 +
 +uses the All parameter of the Get-Command cmdlet to show all instances of the Notepad command on the local computer.
 +<cli prompt='>'>​
 +PS> Get-Command Notepad -All | Format-Table CommandType,​ Name, Definition
 +
 +CommandType ​    ​Name ​          ​Definition
 +----------- ​    ​---- ​          ​----------
 +Application ​    ​notepad.exe ​   C:​\WINDOWS\system32\notepad.exe
 +Application ​    ​NOTEPAD.EXE ​   C:​\WINDOWS\NOTEPAD.EXE
 </​cli>​ </​cli>​
  
Line 30: Line 53:
 <cli prompt='>'>​ <cli prompt='>'>​
 PS /​home/​manu>​ get-alias PS /​home/​manu>​ get-alias
 +</​cli>​
 +
 +===== Remove header/​descriptor =====
 +
 +<cli prompt='>'>​
 +PS /root> Get-VM lnx01a | ForEach-Object {$_.Name}
 +lnx01a ​
 </​cli>​ </​cli>​
  
Line 109: Line 139:
 vm4 vm4
 vm5 vm5
 +</​cli>​
 +
 +===== grep in Powershell =====
 +
 +<cli prompt='#'>​
 +PS /​usr/​bin/​fcm/​tmp>​ Get-Content -Path vminfo.txt |  Where-Object { $_ -Match ​ "​^VM_Datastore:"​}
 </​cli>​ </​cli>​
  
Line 193: Line 229:
   -Descending   -Descending
  
-Misc commands+===== Misc commands ​=====
  
-tail: get last 5 lines from file+==== tail ====
  
-PS> Get-Content -path /​root/​toto.py -tail 5                                                                                                                                                                    +get last 5 lines from file 
 +<cli prompt='>'>​ 
 +PS> Get-Content -path /​root/​toto.py -tail 5     ​
  
-head: get first lines from file+PS> ​get-content |select -last 
  
-PS> ​Get-Content ​-path /root/​toto.py -totalcount 5 +PS> ​get-content |select ​-last 5 | Write-Output ​                                                                                                                                                             
 +</cli>
  
 +==== head ====
 +
 +get first 5 lines from file
 +<cli prompt='>'>​
 +PS> Get-Content -path /​root/​toto.py -totalcount 5 
 +</​cli>​
program_lang/powershell_misc.1640977473.txt.gz · Last modified: 2021/12/31 20:04 by manu