相关疑难解决方法(0)

如何测试对象是否具有特定属性?

如何测试对象是否具有特定属性?

欣赏我能做到......

$members = Get-Member -InputObject $myobject 
Run Code Online (Sandbox Code Playgroud)

然后foreach通过$members,但是有一个函数来测试对象是否具有特定的属性?

附加信息: 问题是我正在导入两种不同类型的CSV文件,一种是两列,另一种是三列.我无法使用"Property"进行检查,只能使用"NoteProperty"... 无论差异是什么

if ( ($member.MemberType -eq "NoteProperty" ) -and ($member.Name -eq $propertyName) ) 
Run Code Online (Sandbox Code Playgroud)

powershell powershell-3.0

73
推荐指数
8
解决办法
8万
查看次数

PowerShell计数不适用于单个匹配

我正在运行以下PowerShell代码以在收件箱中检索匹配项,并且想知道为什么对于只有一个匹配项的实例,我的过滤器不起作用。这是查找和过滤匹配项的代码;

 Add-type -assembly "Microsoft.Office.Interop.Outlook" | out-null 
 $olFolders = "Microsoft.Office.Interop.Outlook.olDefaultFolders" -as [type]  
 $outlook = new-object -comobject outlook.application 
 $namespace = $outlook.GetNameSpace("MAPI") 
 $inbox = $namespace.getDefaultFolder($olFolders::olFolderInBox) 
 $filter = (%{$inbox.items | Where {$_.SenderName -match ‘JoeUser’ -and
 $_.UnRead -eq $true}})
Run Code Online (Sandbox Code Playgroud)

...当我通过运行$ filter.count来请求匹配项计数时,只要有多个匹配项,我就会得到正确的答案。因此,对于收件箱中只有一条匹配的消息的情况,$ filter.count不会返回任何内容,并且后续代码也无法对该消息进行处理-我知道该匹配项提取了匹配的消息,因为我可以从$ filter查看

谁能弄清楚为什么这个计数在$ filter的单个匹配中不起作用?

powershell

1
推荐指数
2
解决办法
1460
查看次数

标签 统计

powershell ×2

powershell-3.0 ×1