【问题标题】:Add Copyright As a New Member to Get-Process将版权作为新成员添加到 Get-Process
【发布时间】:2017-01-22 13:13:00
【问题描述】:

我有一个 PowerShell 脚本,其中包含:
1.$GetP:变量是(获取进程命令)
2.$path和$getfile:是两个变量,用于获取$GetP路径中的所有进程路径。
3.foreach语法:是一种获取$getfile中所有路径的方法(合法版权)。
...
现在我想为每个路径添加 版权 作为新成员到 $GetP 或 Get-Process。

她是我的错误语法:

$GetP = Get-Process

$path = $GetP | select -ExpandProperty  Path
$getfile = dir $path -Include *.* -recurse 

foreach ($iffile in $getfile)
{

        $fname = $iffile.FullName
        $vfile = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($fname)
        $Copyright = $vfile.LegalCopyright

        #$Copyright

} 


$FileCopyRight = foreach ($Copyright in $GetP) {
    $fpmvar = $vfile.LegalCopyright
    $Copyright | Add-Member -NotePropertyName CopyRight -NotePropertyValue $fpmvar -PassThru
  }


$GetP | select CopyRight

注意:当您删除$Copyright 中的“#”注释时,它将显示所有版权。

【问题讨论】:

    标签: windows powershell


    【解决方案1】:

    您需要一次执行一个过程或将变量与 ex 链接在一起。哈希表。自动取款机。 $copyright 只会是 $getfile-array 中最后一个文件的值。

    我建议为每个进程运行一个循环,将版权添加到该对象并继续下一个。

    试试:

    Get-Process | ForEach-Object {
        #If path is defined
        if($_.Path) {
            $CopyRight = (Get-Item $_.Path).VersionInfo.LegalCopyright
            Add-Member -InputObject $_ -NotePropertyName "CopyRight" -NotePropertyValue $CopyRight -PassThru
        }
    } | Select Name, CopyRight
    

    样本输出:

    ApMsgFwd              Copyright (C) 2006-2014 Alps Electric Co., Ltd.                   
    ApntEx                Copyright (C) 1998-2014 Alps Electric Co., Ltd.                   
    Apoint                Copyright (C) 1999-2015 Alps Electric Co., Ltd.                   
    ApplicationFrameHost  © Microsoft Corporation. All rights reserved.                     
    AppVClient            © Microsoft Corporation. All rights reserved.                     
    AppVStreamingUX       Copyright (c) Microsoft Corporation. All rights reserved.         
    armsvc                Copyright © 2013 Adobe Systems Incorporated.  All rights reserved.
    ....
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-02
      • 2021-09-10
      • 2021-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多