문제

I have the following command:

$startDate='01/02/2013'
$endDate='26/03/2014'
Search-AdminAuditLog -Cmdlets set-mailboxsearch -StartDate $startDate -EndDate $endDate | where {$_.cmdletparameters.name -notcontains "inplaceholdenabled"}|Add-Member -Name "SearchName" -MemberType ScriptProperty -PassThru -Value {Get-MailboxSearch -Identity $this.objectmodified} | select "objectmodified","Caller","Rundate","cmdletname",@{Name="SearchName";Expression={$_.searchname.Name}}  

It returns:

ObjectModified : XXXXXXXX
Caller         : Administrator
RunDate        : 25/03/2014 4:33:17 PM
CmdletName     : Set-MailboxSearch
SearchName     : 

ObjectModified : AAMkADQyZDMxY2UwL 
Caller         : Administrator
RunDate        : 25/03/2014 9:35:02 AM
CmdletName     : Set-MailboxSearch
SearchName     : 

The SearchName field is always an empty string when I run in PowerShell ISE, but if I copy and run the same command in shell, it returns SearchName as "test search 2 to 7" which is the required value.

Why is the behaviour different in both places? What am I doing wrong here?

도움이 되었습니까?

해결책

The answer is maybe in this duplicate thread, basically ISE is not the same as the console and has many caveats for you to learn.

Difference between PowerShell Console and PowerShell ISE

In other words, probably nothing wrong with your script, ISE is known to have issues.

http://blogs.msdn.com/b/powershell/archive/2009/04/17/differences-between-the-ise-and-powershell-console.aspx

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top