πŸ“œ ⬆️ ⬇️

First steps for pauershelshikov

Come to my brother in the console!
- Admin Dolgoruky.

Many shortcuts have flown into the basket since the release of Windows 2008. People simply marveled at the new blue window, which the guys from Microsoft for some reason inserted into their new products. People who are sitting on blogs and know programming have begun to study this window.



As a result, people began to realize that Microsoft really developed something new and interesting.
And so, why do you need it? Basically, a program called PowerShell (hereinafter PS) is intended for administrators and programmers. It allows you to automate about 99% of all actions in the system. Using it, you can configure remote computers, start and restart services, and perform maintenance of most server applications. As it turned out, the possibilities of the program are amazing.
')
Of course, advanced users will find many ways to use this amazing blue window.

The purpose of this article is simple - to show you a small fraction of the PS capabilities and give you a conceptual understanding of the subject. In fact, there are a myriad of documentation on the subject, so I don’t want to cover everything. I will also acquaint you with a set of utilities that will allow you not to get out of PS in principle.


What is a PS? This is a command line interpreter. You enter the necessary commands, the result of their execution is displayed on the screen. It's simple. Everything has been like this since the days of the dos and the good old Unix.

There are two main differences from the predecessors, which qualitatively distinguish PS from other interpreters.



Getting started


Windows 7 2008 PS . Windows β€” .

, . .
, .

dir

.
,

ls

, dir. PS . , β€” ( PS , PS) Get-ChildItem. Get-ChildItem , . ,

ls Alias:\

, - . - . .

. PS β€” -. , . ,

Get-Process #
Remove-Item # -
Get-Help # -
Set-Alias #
New-Item # ( , , )


, PS . , , ,

Get-PSDrive

, , Β« Β»

Name           Used (GB)     Free (GB) Provider      Root
----           ---------     --------- --------      ----
Alias                                  Alias
C                  16.56         63.44 FileSystem    C:\
cert                                   Certificate   \
D                    .11         53.92 FileSystem    D:\
Env                                    Environment
Function                               Function
HKCU                                   Registry      HKEY_CURRENT_USER
HKLM                                   Registry      HKEY_LOCAL_MACHINE
Variable                               Variable
WSMan                                  WSMan


Alias . Variable: , . Env β€” . HKCU HKLM .
.

Set-Location HKLM: # ,     ,  cd HKLM:


? ls «», cd SYSTEM.

SKC  VC Name                           Property
---  -- ----                           --------
  2   0 BCD00000000                    {}
  4   0 HARDWARE                       {}
  1   0 SAM                            {}
Get-ChildItem : Requested registry access is not allowed.
At line:1 char:3
+ ls <<<<  -force
    + CategoryInfo          : PermissionDenied: (HKEY_LOCAL_MACHINE\SECURITY:St
   ring) [Get-ChildItem], SecurityException
    + FullyQualifiedErrorId : System.Security.SecurityException,Microsoft.Power
   Shell.Commands.GetChildItemCommand

 35   0 SOFTWARE                       {}
  8   0 SYSTEM                         {}


(, , ).

New-Item Remove-Item . ( , , )

, . , . - , . , , PS β€” , .

, - PowerShell


. . , . man. ( β€” β€” man man man)
PS ,

Get-Help #       ,   help


, . ( Windows XP 2003)
, help. ,

get-help New-Item -Examples


-Examples , .
, -, PS, .
- , , , ,

get-help files


, :

PS C:\> get-help Files

Name                              Category  Synopsis
----                              --------  --------
FileSystem                        Provider  Provides access to files and dire...
about_profiles                    HelpFile  Describes how to create and use a...


, , ,

get-help Registry


, , PS.
, . , , , .

,    ,     

, , β€” . . , , .

, ,


  1. , .
  2. , , .

,


  1. Ctrl+Home β€” ,
  2. Ctrl+End β€”
  3. F7 β€” , .
  4. , - , Enter.
  5. , β€” .
β€” , , . , .


, .
- , . , . , . |, .
, , bat . , ,

PS C:\> ls -filter "*.bat" | Get-Content
REM Dummy file for NTVDM


ls -filter "*.bat" , Get-Content ( , , , , )
. , Β« Β».

Get-Help Registry | Set-Content reg.txt


, .

, , PS , IQ 100% - .

ps | ls


, ! , , get-childitem!
, :

PS C:\> ps wordpad | ls

    Directory: C:\Program Files\Windows NT\Accessories

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---         6/28/2010   9:57 PM    4247040 wordpad.exe


.


, , . , ps , .
, ?
Get-Member, . , , ps.

ps wordpad | Get-Member


, , System.Diagnostics.Process. , , ps Process !
.

PS C:\> notepad                                                        
PS C:\> ps notepad                                                                                                                            Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName  -------  ------    -----      ----- -----   ------     -- -----------       70       4     1148       5376    56     0.30   3900 notepad                                                                                                                                                    PS C:\> ps notepad | get-member -type method


   TypeName: System.Diagnostics.Process

Name                      MemberType Definition
----                      ---------- ----------
BeginErrorReadLine        Method     System.Void BeginErrorReadLine()
BeginOutputReadLine       Method     System.Void BeginOutputReadLine()
CancelErrorRead           Method     System.Void CancelErrorRead()
CancelOutputRead          Method     System.Void CancelOutputRead()
Close                     Method     System.Void Close()
CloseMainWindow           Method     bool CloseMainWindow()
CreateObjRef              Method     System.Runtime.Remoting.ObjRef CreateObj...
Dispose                   Method     System.Void Dispose()
Equals                    Method     bool Equals(System.Object obj)
GetHashCode               Method     int GetHashCode()
GetLifetimeService        Method     System.Object GetLifetimeService()
GetType                   Method     type GetType()
InitializeLifetimeService Method     System.Object InitializeLifetimeService()
Kill                      Method     System.Void Kill()
Refresh                   Method     System.Void Refresh()
Start                     Method     bool Start()
ToString                  Method     string ToString()
WaitForExit               Method     bool WaitForExit(int milliseconds), Syst...
WaitForInputIdle          Method     bool WaitForInputIdle(int milliseconds),...


, , . , ? .

(ps notepad).WaitForExit()


, , , .
. Enter. . , . , .
, . , get-member ls , .
, - , Get-Member

(ps notepad).StartTime | Get-Member


.

. , . PS? , .


, , , , . , , , .


, . PS :

$processList = ps




PS C:\> [DateTime]$x = "febbrrr"
Cannot convert value "febbrrr" to type "System.DateTime". Error: "The string was
 not recognized as a valid DateTime. There is a unknown word starting at index 0."
At line:1 char:13
+ [DateTime]$x <<<<  = "febbrrr"
    + CategoryInfo          : MetadataError: (:) [], ArgumentTransformationMetadataException
    + FullyQualifiedErrorId : RuntimeException
PS C:\> [DateTime]$x = "02/14/11"
PS C:\> $x
Monday, February 14, 2011 12:00:00 AM


, , . , , , . , PS , .NET .
, , PS , β€” ? , , . , CLR. , .
,

$x = new-object System.Object


-, , β€” . . , ?

C:\> $client = New-Object System.Net.WebClient
C:\> $client.DownloadString("http://google.com")


. wget . ?
, MSDN , , . .

,


PS . ! . . PS , . ( help about_signing) , ,

set-executionpolicy remotesigned


. SDK . , , , ---.
, . , :

New-Item -type file $PROFILE


$PROFILE PS. , PS. , , .
:

vim $PROFILE


(, , , PS, , vim. - , , - , . . , , .)
, , :

notepad $PROFILE


, , , ,

$webClient =  New-Object System.Net.WebClient
$cred = New-Object System.Net.NetworkCredential("login", "Pass")
$webClient.Proxy = New-Object System.Net.WebProxy("www.proxy.adrress", $true, $null, $cred)


, , , .
?
. , . …

, . - . , β€” , . , .
, , , , :
, , ( , )
, Where-Object Foreach-Object.

NMAP
, ? , . -le -ge , .

.
, , . , PS .

$host !

? COM , , new-object -comObject. , .

, Microsoft PowerShell. , SQL PowerShell, 2008 ls . .

, , PS . , , β€” , ITunes PowerShell Google Desktop Search PS.

, , , - , , . , . , , .

Source: https://habr.com/ru/post/113913/


All Articles