zoukankan      html  css  js  c++  java
  • PowerTip of the DayGetting Installed Updates

    原文地址:http://app.en25.com/e/es.aspx?s=1403&e=4914&elq=a3fdfdb4961d4feabec6e309570c5e33

    原文:

    PowerShell is great for parsing log files. Here is a function that extracts all installed Windows updates from an internal log file and returns the information as pure PowerShell objects. Have a look as this code uses a number of powerful parsing and wrapping techniques:

    function Get-Updates {
         
    Get-Content $env:windir\windowsupdate.log -encoding utf8 |
        
    Where-Object { $_ -like '*successfully installed*'} |
        
    ForEach-Object {
              
    $info = $_.Split("`t")
              
    $hash = @{}
              
    $hash.InstallDate = [DateTime]$info[6].Remove($info[6].LastIndexOf(":"))
             
    $hash.Product = $info[-1].Split(":")[-1].Trim()
              
    New-Object PSobject -property $hash  
        }
    }

    Get-Updates

     

    翻译:

    Powershell在转换日志文件上很有威力。下面的函数会从一个日志文件提取所有已经安装的windows updates并且把信息用PowerShell对象的方式更纯净的显示出来。下面代码用到了一些非常强大的转换和包装技巧:

    function Get-Updates {
         
    Get-Content $env:windir\windowsupdate.log -encoding utf8 |
        
    Where-Object { $_ -like '*successfully installed*'} |
        
    ForEach-Object {
              
    $info = $_.Split("`t")
              
    $hash = @{}
              
    $hash.InstallDate = [DateTime]$info[6].Remove($info[6].LastIndexOf(":"))
             
    $hash.Product = $info[-1].Split(":")[-1].Trim()
              
    New-Object PSobject -property $hash  
        }
    }

    Get-Updates

     

     

    笔记:

    如果直接用Get-Content $env:windir\windowsupdate.log输出的话信息会很长很乱,利用where过滤后并且只取某些关键列并把数据经过一定的转化,看上去更清晰了。

  • 相关阅读:
    第0次作业
    第4次作业
    第3次作业
    第2次作业
    C#浮点数保留位数
    第0次作业
    软件工程第4次作业
    软件工程第3次作业
    软件工程第2次作业
    软件工程第1次作业
  • 原文地址:https://www.cnblogs.com/aspnetx/p/1765104.html
Copyright © 2011-2022 走看看