我无法在对象字段PowerShell& SharePoint中更改值 [英] I can't change value in object field PowerShell&SharePoint
问题描述
我无法更改对象字段中的值.
可能是什么原因?
$ Timerjob = Get-SPTimerJob
$ Results = $ Timerjob.HistoryEntries
$Timerjob = Get-SPTimerJob
$Results = $Timerjob.HistoryEntries
最初没有"lastrun",在其中,所以我添加它...
$结果| Add-MemberType –MemberType NoteProperty –Name LastRunTime -value([datetime])
initially there is no "lastrun" in it, so I add it ...
$Results | Add-Member –MemberType NoteProperty –Name LastRunTime -value ([datetime])
然后,我按名称在循环中搜索另一个对象中的数据,当我发现我尝试分配一个值时:
foreach($ Timerjob中的$ varname)
{
foreach($ Results中的$ names)
{
if($ names.JobDefinitionTitle -eq $ varname.displayname){$ Results.LastRunTime = $ varname.LastRunTime}
}
}
Then I search for the data in another object in a loop by name, and when I find I try to assign a value:
foreach ( $varname in $Timerjob)
{
foreach ( $names in $Results)
{
if($names.JobDefinitionTitle -eq $varname.displayname) {$Results.LastRunTime=$varname.LastRunTime }
}
}
$ PSVersionTable
名称 b 价值 nbsp; b nbsp; bsp nbsp; bsp
---- nbsp; ----- b ; nbsp; b ; nbsp; b ;
PSVersion 3.0
$PSVersionTable
Name Value
---- -----
PSVersion 3.0
PS C:\ WINDOWS \ system32> $ Results.LastRunTime.gettype()
IsPublic IsSerial Name(公共公共序列名称) BaseType
-------- -------- ---- -
真实 真实 对象[] b ;系统数组
PS C:\WINDOWS\system32> $Results.LastRunTime.gettype()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array
PS C:\ WINDOWS \ system32> $ varname.LastRunTime.GetType()
IsPublic IsSerial Name(公共公共序列名称) BaseType
-------- -------- ---- --------
真实 真实 DateTime System.ValueType
PS C:\WINDOWS\system32> $varname.LastRunTime.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True DateTime System.ValueType
我收到错误消息:
在此对象上找不到属性"LastRunTime".确保它存在并且可设置.
在第5行char:59
+ if($ names.JobDefinitionTitle -eq $ varname.displayname){$ Results.LastRunTime = $ ...
+ nbsp; bsp ; nbsp; b ;
~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo :InvalidOperation:(:) [],RuntimeException
+ FullyQualifiedErrorId:PropertyAssignmentException
在此对象上找不到属性"LastRunTime".确保它存在并且可设置.
在第5行char:59
+ if($ names.JobDefinitionTitle -eq $ varname.displayname){$ Results.LastRunTime = $ ...
+ nbsp; bsp ; nbsp; b ;
~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo :InvalidOperation:(:) [],RuntimeException
+ FullyQualifiedErrorId:PropertyAssignmentException
在此对象上找不到属性"LastRunTime".确保它存在并且可设置.
在第5行char:59
+ if($ names.JobDefinitionTitle -eq $ varname.displayname){$ Results.LastRunTime = $ ...
+ nbsp; bsp ; nbsp; b ;
~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo :InvalidOperation:(:) [],RuntimeException
+ FullyQualifiedErrorId:PropertyAssignmentException
I get error:
Property 'LastRunTime' cannot be found on this object; make sure it exists and is settable.
At line:5 char:59
+ if($names.JobDefinitionTitle -eq $varname.displayname) {$Results.LastRunTime=$ ...
+
~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
Property 'LastRunTime' cannot be found on this object; make sure it exists and is settable.
At line:5 char:59
+ if($names.JobDefinitionTitle -eq $varname.displayname) {$Results.LastRunTime=$ ...
+
~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
Property 'LastRunTime' cannot be found on this object; make sure it exists and is settable.
At line:5 char:59
+ if($names.JobDefinitionTitle -eq $varname.displayname) {$Results.LastRunTime=$ ...
+
~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
推荐答案
此问题的原因是
The reason for this problem is that
Results.LastRunTime将返回一个集合,您不能直接设置Results.LastRunTime will return a collection and you can’t set value of
Results.LastRunTime的值.Results.LastRunTime directly.这是我的代码供您参考:
这篇关于我无法在对象字段PowerShell& SharePoint中更改值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!