我有一个PowerShell脚本,其中包含:
1. [-1,y+w]
:变量是(Get-Process Command)
2. $GetP
和$path
:是两个变量,用于获取$getfile
路径中的所有流程路径。
3. $GetP
语法:是一种获取$ getfile(LegalCopyright)中所有路径的方法
...
现在,我想为每条路径添加版权作为foreach
或$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
中发表评论,它会显示所有CopyRights。
答案 0 :(得分:3)
您需要一次执行一个过程或将变量与ex链接在一起。哈希表。自动取款机。 $copyright
只会是$getfile
- 数组中最后一个文件的值。
我建议为每个进程运行一个循环,将版权添加到该对象并继续下一个。
尝试:
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.
....