{"id":2102,"date":"2012-05-06T23:31:55","date_gmt":"2012-05-06T23:31:55","guid":{"rendered":"http:\/\/enjoyasp.net\/?p=2102"},"modified":"2012-05-07T00:25:55","modified_gmt":"2012-05-07T00:25:55","slug":"powershell%e7%ac%94%e8%ae%b0","status":"publish","type":"post","link":"https:\/\/enjoyasp.net\/index.php\/2012\/05\/06\/powershell%e7%ac%94%e8%ae%b0\/","title":{"rendered":"PowerShell\u7b14\u8bb0"},"content":{"rendered":"<p>1\uff0c\u56fe\u5f62\u5316\u754c\u9762\uff1apowershell -ise<br \/>\n2,\u547d\u4ee4\u7f13\u5b58\uff1aF7<br \/>\n3\uff0c\u83b7\u53d6\u5e2e\u52a9\uff1aget-help \u5982\uff1aget-help get-service [-detail|-full]<br \/>\n4,\u6267\u884cps1\u6587\u4ef6\uff1a\u9ed8\u8ba4\u662f\u4e0d\u6267\u884c\u7684\uff0c\u5b89\u5168\u9650\u5236\u7ea7\u522b\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\n\t\tRestricetd:\u53d7\u9650\u5236\uff0c\u4e0d\u6267\u884c\u4efb\u4f55\u914d\u7f6e\u6587\u4ef6\u548c\u811a\u672c\u3002<\/li>\n<li>\n\t\tAllSigned:\u5fc5\u987b\u7b7e\u540d\u7684\u624d\u6267\u884c\u3002<\/li>\n<li>\n\t\tRemoteSigned:\u8fdc\u7a0b\u6587\u4ef6\u9700\u8981\u7b7e\u540d\u624d\u80fd\u6267\u884c\uff0c\u672c\u5730\u6587\u4ef6\u53ef\u6267\u884c<\/li>\n<li>\n\t\tUnrestricted:\u4e0d\u53d7\u9650\u5236\uff0c\u4efb\u610f\u6267\u884c\u3002<\/li>\n<\/ul>\n<p>\u663e\u793a\u5f53\u524d\u7ea7\u522b\uff1a get-executionpolicy<br \/>\n\u8bbe\u7f6e\u65b9\u6cd5\uff1aset-executionpolicy remotesigned .<br \/>\n5\uff0cpowershell\u4f20\u53c2\uff1a<\/p>\n<ul>\n<li>\n\t\tpowershell -nologo -noexit -command get-process #\u4e0d\u9000\u51fa\u65e0logo\u65b9\u5f0f\u663e\u793a\u8fdb\u7a0b\u4fe1\u606f\u3002<\/li>\n<li>\n\t\tpowershell -noexit -file run.ps1 #\u6267\u884crun.ps1\u6587\u4ef6<\/li>\n<\/ul>\n<p>\n6\uff0c\u53d8\u91cf\u5b9a\u4e49\u4ee5$\u5f00\u5934\uff0c\u6267\u884c\u5b57\u7b26\u4e32\u547d\u4ee4\u7528&amp;,\u82e5\u5b57\u7b26\u4e32\u547d\u4ee4\u5e26\u53c2\u6570\uff0c\u90a3\u9700\u8981\u7528\u5927\u62ec\u53f7\u62ec\u8d77\u3002\u6216\u8005\u7528Invoke-Expression<br \/>\n7.\u683c\u5f0f\u5316\u8f93\u51fa\u7ed3\u679c<br \/>\n&nbsp; Format-list:\u5217\u8868\u5f62\u5f0f<br \/>\n&nbsp; Format-table:\u8868<br \/>\n&nbsp; Format-wide:\u6307\u5b9a\u5bbd\u5ea6<br \/>\n&nbsp; Group-Object:\u5206\u7ec4<br \/>\n&nbsp; Sort-Object:\u6392\u5e8f<br \/>\n&nbsp; where-object:\u7b5b\u9009<br \/>\n&nbsp;get-process|sort-object Handles<br \/>\nget-process|sort-object Handles|format-table handles,id,processname<br \/>\n&nbsp;get-process|where-object {$_.processname -eq &quot;powershell&quot;}<br \/>\nget-alias|where-object {$._Definition -eq &quot;get-service&quot;}<br \/>\n8\uff0c\u8f93\u51fa\u5230\u5c4f\u5e55\uff1awrite-host \u5f55\u5165\uff1aread-host<br \/>\n9\uff0c\u8f93\u51fa\u5230\u6587\u4ef6\uff1a -file &#8230;\u6216\u8005 &gt; \u5355&gt;\u8868\u793a\u65b0\u5efa\u6216\u8986\u76d6\uff0c&gt;&gt;\u8868\u793a\u8ffd\u52a0<br \/>\n10\uff0c\u522b\u540d\uff1aget-alias .\u5982get-process = gps<br \/>\n11,\u5e38\u7528\uff1aget-process,get-service,get-eventlog<br \/>\n12,\u903b\u8f91\uff1a -eq = -ne \u4e0d=&nbsp;&nbsp; -lt \u5c0f\u4e8e -gt \u5927\u4e8e&nbsp; -le:\u5c0f\u4e8e\u7b49\u4e8e -ge:\u5927\u4e8e\u7b49\u4e8e -contails \u5305\u542b -like \u7c7b\u4f3c\u4e8e -replace \u66ff\u6362 -match \u5339\u914d<br \/>\n13\uff0c$args:\u63a5\u6536\u53c2\u6570\u3002 $args[0], $args.count<br \/>\n14,\u5355\u5f15\u53f7\uff1a\u76f4\u63a5\u8f93\u51fa\u3002 \u53cc\u5f15\u53f7\uff0c\u9664\u76f4\u63a5\u8f93\u51fa\u5916\uff0c\u82e5\u6709\u53d8\u91cf\uff0c\u5219\u5c06\u53d8\u91cf\u8f6c\u6362\u6210\u503c\u518d\u8f93\u51fa\uff0c\u53cd\u5355\u5f15\u53f7\u6267\u884c\u8f6c\u4e49\u3002<br \/>\n15\uff0c\u6570\u7ec4\uff1a<br \/>\n&nbsp; \u5355\u6570\u7ec4 1)\u7528\u9017\u53f7\u5206\u9694\u3002$arr=1,2,3 \u4f7f\u7528$arr[0],$arr[-1] \u6700\u540e\u4e00\u4f4d\u3002<br \/>\n&nbsp;&nbsp; &nbsp; 2)\u591a\u79cd\u7c7b\u578b\uff0c\u7528\u5c0f\u62ec\u53f7\u53ca\u5206\u53f7\u9694\u5f00\u3002$myArray=@(14;&quot;this&quot;;get-process)<br \/>\n&nbsp; \u591a\u7ef4\u6570\u7ec4<br \/>\n3\u884c4\u52175\u5c42\u6570\u7ec4<br \/>\n&nbsp;$arr = new-object &#39;object[,,]&#39; 3,4,5<br \/>\n16\uff0c\u4f7f\u7528.net\u5bf9\u8c61<br \/>\n1\uff09\u9759\u6001\u6210\u5458\u53d8\u91cf&nbsp; [\u7c7b\u540d]::\u9759\u6001\u65b9\u6cd5\u540d<br \/>\n[system.environment]::ProcessorCount . \u8f93\u5165::\u540e\u6309tab\u952e\u53ef\u9009\u62e9\u3002<br \/>\n2\uff09\u5b9e\u4f8b\u5316<br \/>\nnew-object -type \u7c7b\u540d -argumentlist application<br \/>\n3)\u52a0\u8f7d\u7a0b\u5e8f\u96c6<br \/>\n\u5982\uff1a<br \/>\n[Reflection.Assemble]::LoadWithPartialName(&quot;System.Windows.Forms&quot;)<br \/>\n17\uff0c\u6ce8\u91ca#\uff0c\u591a\u884c\u6ce8\u91ca&lt;#&#8230;#&gt;<br \/>\n18,\u56fa\u6709\u53d8\u91cf<br \/>\n$env:computername<br \/>\n$env:username<br \/>\n$env:userdomain<br \/>\n19,\u7cfb\u7edf\u65e5\u5fd7\u64cd\u4f5c<br \/>\n\u6700\u8fd120\u6761\u5e94\u7528\u7a0b\u5e8f\u65e5\u5fd7<br \/>\n&nbsp;get-eventlog &quot;Application&quot; -newest 20<br \/>\n\u65e5\u5fd7\u7c7b\u578b\uff1aApplication, System, Ddirectory Service,&quot;security&quot;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1\uff0c\u56fe\u5f62\u5316\u754c\u9762\uff1apowershell -ise 2,\u547d\u4ee4\u7f13\u5b58\uff1aF7 3\uff0c\u83b7\u53d6\u5e2e\u52a9\uff1aget-help \u5982\uff1aget [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-2102","post","type-post","status-publish","format-standard","hentry","category-sql-server"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/2102","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/comments?post=2102"}],"version-history":[{"count":0,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/2102\/revisions"}],"wp:attachment":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/media?parent=2102"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/categories?post=2102"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/tags?post=2102"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}