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