{"id":351,"date":"2022-02-09T10:18:22","date_gmt":"2022-02-09T02:18:22","guid":{"rendered":"https:\/\/benson.ml\/?p=351"},"modified":"2022-03-23T13:13:31","modified_gmt":"2022-03-23T05:13:31","slug":"25%e4%b8%aa%e5%b8%b8%e7%94%a8powershell%e5%91%bd%e4%bb%a4%e6%80%bb%e7%bb%93","status":"publish","type":"post","link":"https:\/\/benson80.eu.org\/?p=351","title":{"rendered":"25\u4e2a\u5e38\u7528PowerShell\u547d\u4ee4\u603b\u7ed3"},"content":{"rendered":"\n<p>\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e8625\u4e2a\u5e38\u7528\u7684PowerShell\u547d\u4ee4\u603b\u7ed3,\u672c\u6587\u5206\u4e3a\u5165\u95e8\u7ea7\u522b\u3001\u6536\u96c6\u4fe1\u606f\u3001\u8f6f\u4ef6\u7ba1\u7406\u4e09\u5927\u7c7b\u5e38\u7528\u7684PowerShell\u547d\u4ee4\u3002<\/p>\n\n\n\n<p>\u5c3d\u7ba1Windows PowerShell\u5df2\u7ecf\u51fa\u73b0\u4e00\u6bb5\u65f6\u95f4\u4e86\uff0c\u4e60\u60ef\u547d\u4ee4\u884c\u7684\u7ba1\u7406\u5458\u53ef\u80fd\u5bf9\u4e86\u89e3PowerShell\u529f\u80fd\u7684\u57fa\u7840\u5f88\u611f\u5174\u8da3\u3002<\/p>\n\n\n\n<p>\u4e0b\u9762\u6211\u4eec\u770b\u770b\u80fd\u7531Windows PowerShell\u5b8c\u6210\u7684\u6700\u5e38\u89c1\u768425\u4e2a\u4efb\u52a1\u3002\u4e0d\u6b62\u662f\u8fd9\u4e9b\u4efb\u52a1\u5f88\u7b80\u5355\uff0c\u663e\u793a\u8bed\u53e5\u7684\u547d\u4ee4\u67b6\u6784\u548c\u5176\u4ed6PowerShell\u547d\u4ee4\u4e5f\u5f88\u7b80\u5355\u3002\u638c\u63e1\u597d\u8fd9\u4e9b\u57fa\u672c\u547d\u4ee4\u662f\u6210\u4e3aPowerShell\u4e13\u5bb6\u7684\u5fc5\u7ecf\u4e4b\u8def\u3002<\/p>\n\n\n\n<p><strong>\u3000\u3000\u5165\u95e8\u7ea7\u522b<\/strong><\/p>\n\n\n\n<p>\u3000\u30001. \u50cf\u6587\u4ef6\u7cfb\u7edf\u90a3\u6837\u64cd\u4f5cWindows Registry\u2014\u2014cd hkcu:<br>\u3000\u30002. \u5728\u6587\u4ef6\u91cc\u9012\u56de\u5730\u641c\u7d22\u67d0\u4e2a\u5b57\u7b26\u4e32\u2014\u2014dir \u2013r | select string &#8220;searchforthis&#8221;<br>\u3000\u3000<br>\u3000\u30003. \u4f7f\u7528\u5185\u5b58\u627e\u5230\u4e94\u4e2a\u8fdb\u7a0b\u2014\u2014ps | sort \u2013p ws | select \u2013last 5<br>\u3000\u30004. \u5faa\u73af\uff08\u505c\u6b62\uff0c\u7136\u540e\u91cd\u542f\uff09\u4e00\u4e2a\u670d\u52a1\uff0c\u5982DHCP\u2014\u2014Restart-Service DHCP<br>\u3000\u30005. \u5728\u6587\u4ef6\u5939\u91cc\u5217\u51fa\u6240\u6709\u6761\u76ee\u2014\u2014Get-ChildItem \u2013 Force<br>\u3000\u30006. \u9012\u5f52\u4e00\u7cfb\u5217\u7684\u76ee\u5f55\u6216\u6587\u4ef6\u5939\u2014\u2014Get-ChildItem \u2013Force c:\\directory \u2013Recurse<br>\u3000\u30007. \u5728\u76ee\u5f55\u91cc\u79fb\u9664\u6240\u6709\u6587\u4ef6\u800c\u4e0d\u9700\u8981\u5355\u4e2a\u79fb\u9664\u2014\u2014Remove-Item C:\\tobedeleted \u2013Recurse<br>\u3000\u30008. \u91cd\u542f\u5f53\u524d\u8ba1\u7b97\u673a\u2014\u2014(Get-WmiObject -Class Win32_OperatingSystem -ComputerName .).Win32Shutdown(2)<\/p>\n\n\n\n<p><strong>\u3000\u3000\u6536\u96c6\u4fe1\u606f<\/strong><\/p>\n\n\n\n<p>\u3000\u30009. \u83b7\u53d6\u8ba1\u7b97\u673a\u7ec4\u6210\u6216\u6a21\u578b\u4fe1\u606f\u2014\u2014Get-WmiObject -Class Win32_ComputerSystem<br>\u3000\u300010. \u83b7\u53d6\u5f53\u524d\u8ba1\u7b97\u673a\u7684BIOS\u4fe1\u606f\u2014\u2014Get-WmiObject -Class Win32_BIOS -ComputerName .<br>\u3000\u300011. \u5217\u51fa\u6240\u5b89\u88c5\u7684\u4fee\u590d\u7a0b\u5e8f\uff08\u5982QFE\u6216Windows Update\u6587\u4ef6\uff09\u2014\u2014Get-WmiObject -Class Win32_QuickFixEngineering -ComputerName .<br>\u3000\u300012. \u83b7\u53d6\u5f53\u524d\u767b\u5f55\u8ba1\u7b97\u673a\u7684\u7528\u6237\u7684\u7528\u6237\u540d\u2014\u2014 Get-WmiObject -Class Win32_ComputerSystem -Property UserName -ComputerName .<br>\u3000\u300013. \u83b7\u53d6\u5f53\u524d\u8ba1\u7b97\u673a\u6240\u5b89\u88c5\u7684\u5e94\u7528\u7684\u540d\u5b57\u2014\u2014Get-WmiObject -Class Win32_Product -ComputerName . | Format-Wide -Column 1<br>\u3000\u300014. \u83b7\u53d6\u5206\u914d\u7ed9\u5f53\u524d\u8ba1\u7b97\u673a\u7684IP\u5730\u5740\u2014\u2014Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName . | Format-Table -Property IPAddress<br>\u3000\u300015. \u83b7\u53d6\u5f53\u524d\u673a\u5668\u8be6\u7ec6\u7684IP\u914d\u7f6e\u62a5\u9053\u2014\u2014Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName . | Select-Object -Property [a-z]* -ExcludeProperty IPX*,WINS*<br>\u3000\u300016. \u627e\u5230\u5f53\u524d\u8ba1\u7b97\u673a\u4e0a\u4f7f\u7528DHCP\u542f\u7528\u7684\u7f51\u7edc\u5361\u2014\u2014Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter &#8220;DHCPEnabled=true&#8221; -ComputerName .<br>\u3000\u300017. \u5728\u5f53\u524d\u8ba1\u7b97\u673a\u4e0a\u7684\u6240\u6709\u7f51\u7edc\u9002\u914d\u5668\u4e0a\u542f\u7528DHCP\u2014\u2014Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=true -ComputerName . | ForEach-Object -Process {$_.EnableDHCP()}<\/p>\n\n\n\n<p><strong>\u3000\u3000\u8f6f\u4ef6\u7ba1\u7406<\/strong><\/p>\n\n\n\n<p>\u3000\u300018. \u5728\u8fdc\u7a0b\u8ba1\u7b97\u673a\u4e0a\u5b89\u88c5MSI\u5305\u2014\u2014(Get-WMIObject -ComputerName TARGETMACHINE -List | Where-Object -FilterScript {$_.Name -eq &#8220;Win32_Product&#8221;}).Install(\\\\MACHINEWHEREMSIRESIDES\\path\\package.msi)<br>\u3000\u300019. \u4f7f\u7528\u57fa\u4e8eMSI\u7684\u5e94\u7528\u5347\u7ea7\u5305\u5347\u7ea7\u6240\u5b89\u88c5\u7684\u5e94\u7528\u2014\u2014(Get-WmiObject -Class Win32_Product -ComputerName . -Filter &#8220;Name=&#8217;name_of_app_to_be_upgraded'&#8221;).Upgrade(\\\\MACHINEWHEREMSIRESIDES\\path\\upgrade_package.msi)<br>\u3000\u300020. \u4ece\u5f53\u524d\u8ba1\u7b97\u673a\u79fb\u9664MSI\u5305\u2014\u2014(Get-WmiObject -Class Win32_Product -Filter &#8220;Name=&#8217;product_to_remove'&#8221; -ComputerName . ).Uninstall()<br>\u3000\u3000\u673a\u5668\u7ba1\u7406<br>\u3000\u300021. \u4e00\u5206\u949f\u540e\u8fdc\u7a0b\u5173\u95ed\u53e6\u4e00\u53f0\u673a\u5668\u2014\u2014Start-Sleep 60; Restart-Computer \u2013Force \u2013ComputerName TARGETMACHINE<br>\u3000\u300022. \u6dfb\u52a0\u6253\u5370\u673a\u2014\u2014(New-Object -ComObject WScript.Network).AddWindowsPrinterConnection(\\\\printerserver\\hplaser3)<br>\u3000\u300023. \u79fb\u9664\u6253\u5370\u673a\u2014\u2014(New-Object -ComObject WScript.Network).RemovePrinterConnection(&#8220;\\\\printerserver\\hplaser3 &#8220;)<br>\u3000\u300024. \u8fdb\u5165PowerShell\u4f1a\u8bdd\u2014\u2014invoke-command -computername machine1, machine2 -filepath c:\\Script\\script.ps1<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e8625\u4e2a\u5e38\u7528\u7684PowerShell &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-351","post","type-post","status-publish","format-standard","hentry","category-windows"],"_links":{"self":[{"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/351","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=351"}],"version-history":[{"count":1,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/351\/revisions"}],"predecessor-version":[{"id":352,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/351\/revisions\/352"}],"wp:attachment":[{"href":"https:\/\/benson80.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/benson80.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}