Powershelshikovの最初のステップ

コンソールで弟に来てください!

-管理者ドルゴルキー。



2008 Windowsのリリース以降、多くのショートカットがゴミ箱に飛んできました。 人々は単に新しい青いウィンドウに疑問を抱きました。それは、何らかの理由でマイクロソフトの人々が新しい製品に挿入したものです。 ブログを書いてプログラミングを知っている人々は、このウィンドウを研究し始めました。







その結果、人々はマイクロソフトが本当に新しく興味深いものを開発したことに気づき始めました。

それで、なぜこれが必要なのですか? 基本的に、PowerShell(以降PS)と呼ばれるプログラムは、管理者とプログラマーを対象としています。 システム内のすべてのアクションの約99%を自動化できます。 これにより、リモートコンピューターを構成し、サービスを開始および再起動し、ほとんどのサーバーアプリケーションでメンテナンスを実行できます。 結局のところ、プログラムの可能性は驚くべきものです。



もちろん、上級ユーザーはこの驚くべき青いウィンドウを使用する多くの方法を見つけるでしょう。



この記事のタスクは簡単です。PSの可能性のほんの一部を示し、主題の概念を理解することです。 実際、この件に関しては無数のドキュメントが書かれているので、すべてを網羅しようとはしていません。 また、原則としてPSから抜け出せないようにするユーティリティのセットも紹介します。





PSとは何ですか? これはコマンドラインインタープリターです。 必要なコマンドを入力すると、画面にその実行結果が表示されます。 すべてがシンプルです。 dosと古き良きUnixの時代からすべてがこのようになっています。



PSを他のインタープリターと定性的に区別する、前任者との主な違いは2つあります。







はじめに



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.



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



All Articles