简体   繁体   English

通过PowerShell在Sharepoint Online中获取任务列表中的更改

[英]Get changes in a Task List in Sharepoint Online through PowerShell

I am trying to find out the changes that are made to a task list in sharepoint online with the help of CSOM. 我试图在CSOM的帮助下找出在sharepoint中对任务列表所做的更改。 (Microsoft.SharePoint.Client.dll) I was able to query for changes through the GetChanges method of the List class but not sure what to do further. (Microsoft.SharePoint.Client.dll)我能够通过List类的GetChanges方法查询更改,但不知道该怎么做。 I am specifically looking for how to get information related to list changes in specific columns, the old values, the new values, the user who made the change and etc. Is this even possible? 我特别想知道如何获取与特定列中的列表更改相关的信息,旧值,新值,进行更改的用户等。这是否可能? I am aware of the Change.ChangeToken property but I am not sure how to implement it in PowerShell. 我知道Change.ChangeToken属性,但我不知道如何在PowerShell中实现它。 Here is my incomplete code: 这是我不完整的代码:

[Reflection.Assembly]::LoadFrom("$scriptdir\Microsoft.SharePoint.Client.dll")
$context = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL)
$context.RequestTimeOut = 1000 * 60 * 10;
$context.AuthenticationMode = [Microsoft.SharePoint.Client.ClientAuthenticationMode]::Default
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)
$context.Credentials = $credentials
$web = $context.Web  
$site = $context.Site
$context.Load($web)  
$context.Load($site) 
$context.ExecuteQuery()
Set-Variable -Name "clientContext" -Value $context -Scope Global
Set-Variable -Name "rootSiteUrl" -Value $siteURL -Scope Global
Function Get-ListChanges {   
    $listName = "Tasks"
    $list = $clientContext.Web.Lists.GetByTitle($listName)
    $cq = new-object Microsoft.Sharepoint.Client.ChangeQuery($true,$true)
    $changes = $list.GetChanges($cq)
    $clientContext.Load($changes)
    $clientContext.ExecuteQuery()
    $changes.count
    foreach ($item in $changes) {   
        # get data here from specific column name/old values/newvalues
    }   
}

Thank you for looking in to this! 感谢您关注此事!

UPDATE: As requested, result of $item.GetType() for a single Change item... 更新:根据要求,$ item.GetType()的结果为单个更改项目...

Module                     : System.Management.Automation.dll
Assembly                   : System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
TypeHandle                 : System.RuntimeTypeHandle
DeclaringMethod            :
BaseType                   : System.Object
UnderlyingSystemType       : System.Management.Automation.PSCustomObject
FullName                   : System.Management.Automation.PSCustomObject
AssemblyQualifiedName      : System.Management.Automation.PSCustomObject, System.Management.Automation, Version=3.0.0.0, Culture=neutral
                             PublicKeyToken=31bf3856ad364e35
Namespace                  : System.Management.Automation
GUID                       : 5f6aa156-8585-35c9-a6ae-2aefd06aaa4a
IsEnum                     : False
GenericParameterAttributes :
IsSecurityCritical         : True
IsSecuritySafeCritical     : False
IsSecurityTransparent      : False
IsGenericTypeDefinition    : False
IsGenericParameter         : False
GenericParameterPosition   :
IsGenericType              : False
IsConstructedGenericType   : False
ContainsGenericParameters  : False
StructLayoutAttribute      : System.Runtime.InteropServices.StructLayoutAttribute
Name                       : PSCustomObject
MemberType                 : TypeInfo
DeclaringType              :
ReflectedType              :
MetadataToken              : 33554762
GenericTypeParameters      : {}
DeclaredConstructors       : {Void .cctor(), Void .ctor()}
DeclaredEvents             : {}
DeclaredFields             : {SelfInstance}
DeclaredMembers            : {System.String ToString(), Void .cctor(), Void .ctor(), SelfInstance}
DeclaredMethods            : {System.String ToString()}
DeclaredNestedTypes        : {}
DeclaredProperties         : {}
ImplementedInterfaces      : {}
TypeInitializer            : Void .cctor()
IsNested                   : False
Attributes                 : AutoLayout, AnsiClass, Class, Public, BeforeFieldInit
IsVisible                  : True
IsNotPublic                : False
IsPublic                   : True
IsNestedPublic             : False
IsNestedPrivate            : False
IsNestedFamily             : False
IsNestedAssembly           : False
IsNestedFamANDAssem        : False
IsNestedFamORAssem         : False
IsAutoLayout               : True
IsLayoutSequential         : False
IsExplicitLayout           : False
IsClass                    : True
IsInterface                : False
IsValueType                : False
IsAbstract                 : False
IsSealed                   : False
IsSpecialName              : False
IsImport                   : False
IsSerializable             : False
IsAnsiClass                : True
IsUnicodeClass             : False
IsAutoClass                : False
IsArray                    : False
IsByRef                    : False
IsPointer                  : False
IsPrimitive                : False
IsCOMObject                : False
HasElementType             : False
IsContextful               : False
IsMarshalByRef             : False
GenericTypeArguments       : {}
CustomAttributes           : {}

Tank, it's possible to get the change type and the change time: Tank,可以获得更改类型和更改时间:

$item | Select ChangeType,Time

I may be taking a stab in the dark but you might want to investigate the ChangeLogItemQuery class. 我可能会在黑暗中进行攻击,但您可能想要研究ChangeLogItemQuery类。 It might be able to give you more information about the actual change itself (Old/New etc). 它可能能够为您提供有关实际更改本身的更多信息(旧/新等)。 Please correct me if I'm wrong. 如果我错了,请纠正我。

More info on ChangeLogItemQuery class here: https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.changelogitemquery_members(v=office.15).aspx 有关ChangeLogItemQuery类的更多信息,请访问: https ://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.changelogitemquery_members( v= office.15).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM