<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Powershell on HiDa</title><link>https://www.0niu.cn/tags/powershell/</link><description>Recent content in Powershell on HiDa</description><generator>Hugo -- gohugo.io</generator><language>zh</language><lastBuildDate>Mon, 29 Mar 2021 14:18:54 +0800</lastBuildDate><atom:link href="https://www.0niu.cn/tags/powershell/index.xml" rel="self" type="application/rss+xml"/><item><title>通过powershell查看谁重启了服务器</title><link>https://www.0niu.cn/posts/find-who-restarted-the-server-by-powershell/</link><pubDate>Mon, 29 Mar 2021 14:18:54 +0800</pubDate><guid>https://www.0niu.cn/posts/find-who-restarted-the-server-by-powershell/</guid><description>&lt;p>通过powershell可以很方便的查询谁重启过服务器，对于Server Core尤其方便。服务器重启的事件ID为1074.查询命令为&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-powershell" data-lang="powershell">&lt;span style="display:flex;">&lt;span>Get-WinEvent -LogName system | Where-Object ID &lt;span style="color:#f92672">-eq&lt;/span> &lt;span style="color:#ae81ff">1074&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description><content>&lt;p>通过powershell可以很方便的查询谁重启过服务器，对于Server Core尤其方便。服务器重启的事件ID为1074.查询命令为&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-powershell" data-lang="powershell">&lt;span style="display:flex;">&lt;span>Get-WinEvent -LogName system | Where-Object ID &lt;span style="color:#f92672">-eq&lt;/span> &lt;span style="color:#ae81ff">1074&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;img loading='lazy' src="who-restart-computer.png" alt="Get-WinEvent" />
&lt;/p></content></item><item><title>Powershell 重命名网卡名称</title><link>https://www.0niu.cn/posts/powershell-rename-adapter-name/</link><pubDate>Thu, 07 May 2020 23:26:38 +0800</pubDate><guid>https://www.0niu.cn/posts/powershell-rename-adapter-name/</guid><description>&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-powershell" data-lang="powershell">&lt;span style="display:flex;">&lt;span>Get-NetAdapter -ifIndex &lt;span style="color:#ae81ff">18&lt;/span> | Rename-NetAdapter -NewName SangforSSLVPN
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description><content>&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-powershell" data-lang="powershell">&lt;span style="display:flex;">&lt;span>Get-NetAdapter -ifIndex &lt;span style="color:#ae81ff">18&lt;/span> | Rename-NetAdapter -NewName SangforSSLVPN
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></content></item><item><title>删除Windows用户Profile</title><link>https://www.0niu.cn/posts/remove-user-profile/</link><pubDate>Sat, 09 Mar 2019 15:56:00 +0800</pubDate><guid>https://www.0niu.cn/posts/remove-user-profile/</guid><description>&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-powershell" data-lang="powershell">&lt;span style="display:flex;">&lt;span>Get-WMIObject -class Win32_UserProfile | Where {!$_.Special &lt;span style="color:#f92672">-and&lt;/span> !$_.Loaded } | Remove-WmiObject
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description><content>&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-powershell" data-lang="powershell">&lt;span style="display:flex;">&lt;span>Get-WMIObject -class Win32_UserProfile | Where {!$_.Special &lt;span style="color:#f92672">-and&lt;/span> !$_.Loaded } | Remove-WmiObject
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></content></item><item><title>Powershell只输出值</title><link>https://www.0niu.cn/posts/powershell%E5%8F%AA%E8%BE%93%E5%87%BA%E5%80%BC/</link><pubDate>Thu, 29 Dec 2016 21:33:49 +0800</pubDate><guid>https://www.0niu.cn/posts/powershell%E5%8F%AA%E8%BE%93%E5%87%BA%E5%80%BC/</guid><description>&lt;p>经常需要把运行powershell的结果保存到文本文档中，可是每次都会保存标题头，跟我想要的不一样。目前找到两种方法：&lt;/p>
&lt;p>一种是使用format table&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-powershell" data-lang="powershell">&lt;span style="display:flex;">&lt;span>PS C:\Users\user&amp;gt;Get-CimInstance Win32_BIOS | select SerialNumber | ft -HideTableHeaders
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ae81ff">9553&lt;/span>-&lt;span style="color:#ae81ff">8062&lt;/span>-&lt;span style="color:#ae81ff">1090&lt;/span>-&lt;span style="color:#ae81ff">9335&lt;/span>-&lt;span style="color:#ae81ff">3297&lt;/span>-&lt;span style="color:#ae81ff">8274&lt;/span>-&lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>但是中间会有一行空行，用foreach则没有&lt;/p></description><content>&lt;p>经常需要把运行powershell的结果保存到文本文档中，可是每次都会保存标题头，跟我想要的不一样。目前找到两种方法：&lt;/p>
&lt;p>一种是使用format table&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-powershell" data-lang="powershell">&lt;span style="display:flex;">&lt;span>PS C:\Users\user&amp;gt;Get-CimInstance Win32_BIOS | select SerialNumber | ft -HideTableHeaders
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ae81ff">9553&lt;/span>-&lt;span style="color:#ae81ff">8062&lt;/span>-&lt;span style="color:#ae81ff">1090&lt;/span>-&lt;span style="color:#ae81ff">9335&lt;/span>-&lt;span style="color:#ae81ff">3297&lt;/span>-&lt;span style="color:#ae81ff">8274&lt;/span>-&lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>但是中间会有一行空行，用foreach则没有&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-powershell" data-lang="powershell">&lt;span style="display:flex;">&lt;span>PS C:\Users\user&amp;gt;Get-CimInstance Win32_BIOS |% SerialNumber
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ae81ff">9553&lt;/span>-&lt;span style="color:#ae81ff">8062&lt;/span>-&lt;span style="color:#ae81ff">1090&lt;/span>-&lt;span style="color:#ae81ff">9335&lt;/span>-&lt;span style="color:#ae81ff">3297&lt;/span>-&lt;span style="color:#ae81ff">8274&lt;/span>-&lt;span style="color:#ae81ff">10&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></content></item></channel></rss>