当只有一个对象剩下一个对象时,如何获得psobject的计数 我有以下代码产生psobject: $ installs = foreach($ cvafiles中的$ cvafile) { $ cvafilecontents = get -content $($ cvafile).fullname -raw $ cvafilecontents -match'(?s)。*?\ [gener ...

问题描述 投票:0回答:1

然后使用以下内容将其写出以进行恢复(使用其他代码成功地删除安装时,请按照完成的方式进行恢复):

$Installs | export-csv $ResumeHPImagingAssistantInstallsCSVFile -notypeinformation

以稍后使用此功能对CSV进行IMPORT:

$Installs = import-csv $ResumeHPImagingAssistantInstallsCSVFile
csv中有2个以上的数据行:

PSC:> Get -Member -InputObject $installs

TypeName: System.Object[] Name MemberType Definition ---- ---------- ---------- Count AliasProperty Count = Length Add Method int IList.Add(System.Object value) Address Method System.Object&, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Address(int ) Clear Method void IList.Clear() Clone Method System.Object Clone(), System.Object ICloneable.Clone() CompareTo Method int IStructuralComparable.CompareTo(System.Object other, System.Collections.IComparer comparer) Contains Method bool IList.Contains(System.Object value) CopyTo Method void CopyTo(array array, int index), void CopyTo(array array, long index), void ICollection.CopyTo(array array, int index) Equals Method bool Equals(System.Object obj), bool IStructuralEquatable.Equals(System.Object other, System.Collections.IEqualityComparer comparer) Get Method System.Object Get(int ) GetEnumerator Method System.Collections.IEnumerator GetEnumerator(), System.Collections.IEnumerator IEnumerable.GetEnumerator() GetHashCode Method int GetHashCode(), int IStructuralEquatable.GetHashCode(System.Collections.IEqualityComparer comparer) GetLength Method int GetLength(int dimension) GetLongLength Method long GetLongLength(int dimension) GetLowerBound Method int GetLowerBound(int dimension) GetType Method type GetType() GetUpperBound Method int GetUpperBound(int dimension) GetValue Method System.Object GetValue(Params int[] indices), System.Object GetValue(int index), System.Object GetValue(int index1, int index2), ... IndexOf Method int IList.IndexOf(System.Object value) Initialize Method void Initialize() Insert Method void IList.Insert(int index, System.Object value) Remove Method void IList.Remove(System.Object value) RemoveAt Method void IList.RemoveAt(int index) Set Method void Set(int , System.Object ) SetValue Method void SetValue(System.Object value, int index), void SetValue(System.Object value, int index1, int index2), void SetValue(System.O... ToString Method string ToString() Item ParameterizedProperty System.Object IList.Item(int index) {get;set;} IsFixedSize Property bool IsFixedSize {get;} IsReadOnly Property bool IsReadOnly {get;} IsSynchronized Property bool IsSynchronized {get;} Length Property int Length {get;} LongLength Property long LongLength {get;} Rank Property int Rank {get;} SyncRoot Property System.Object SyncRoot {get;}

当剩下一条数据线时,以下内容。所有方法和属性都发生了什么!

PSC:> Get -Member -InputObject $installs
TypeName: System.Management.Automation.PSCustomObject

Name          MemberType   Definition                       
----          ----------   ----------                       
Equals        Method       bool Equals(System.Object obj)   
GetHashCode   Method       int GetHashCode()                
GetType       Method       type GetType()                   
ToString      Method       string ToString()                
NeedsRestart  NoteProperty string NeedsRestart=0            
SilentInstall NoteProperty string SilentInstall="HPUP.exe...
SP            NoteProperty string SP=sp155005

我需要能够使用计数(或长度),而不管我在$安装变量中是否有0、1或2+ PSOBjects。怎么样?

似乎一种解决此问题的方法是强迫
$Installs

成为一个数组,即使仅包含一个元素。

使用
powershell-5.0 psobject
1个回答
0
投票

	

© www.soinside.com 2019 - 2024. All rights reserved.