Help us understand the problem. What is going on with this article?

SharePoint2010からSharePoint Onlineに移行してる人の日記

Query

before.ps1
$query = New-Object Microsoft.SharePoint.SPQuery;
$query.ViewAttributes = "Scope='RecursiveAll'";
$query.ExpandUserField = $True;
$query.Query  = "<Where>";
# ~中略~
$query.Query += "</Where>";
$result = $list.GetItems($query);
after.ps1
$caml  = "<View>";
$caml += "<Query>";
$caml += "<Where>";
# ~中略~
$caml += "</Where>";
$caml += "<QueryOptions>"
$caml += "<ViewAttributes Scope='Recursive' />"
$caml += "<ExpandUserField>TRUE</ExpandUserField>"
$caml += "</QueryOptions>"
$caml += "</Query>";
$caml += "</View>";
$query = New-Object Microsoft.SharePoint.Client.CamlQuery;
$query.ViewXml = $caml;
$result = $list.GetItems($query);

The collection has not been initialized ~ のとき

The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.

$Context.Load($hoge);
$Context.ExecuteQuery();

だいたいこれ

Microsoft.SharePoint.SPSite

before.ps1
$ListUri = new-object System.Uri($Info.ListUrl);
$Info.Site = new-object Microsoft.SharePoint.SPSite($Info.ListUrl);
$Info.Web = $Info.Site.OpenWeb($ListUri.LocalPath);
$Info.List = $Info.Web.GetList($ListUri.LocalPath);
after.ps1
$ListUri = new-object System.Uri($Info.ListUrl);

$webs = $Context.Web.Webs
$Context.Load($webs)
$Context.ExecuteQuery()

$url = $Info.ListUrl;
$webUrl = ($url -split '/')[0..5] -join '/';

$Info.Site = $Context.Site;
$Info.Web = $webs | Where-Object {$_.Url -match $webUrl};
$Info.List = $Info.Web.GetList($ListUri.LocalPath);

[Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary

before.ps1
$LibGuid = $Info.Web.Lists.Add($LibName, $LibTitle, [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary);
$Lib = $Info.Web.Lists.GetList($LibGuid, $true);
$Lib.Title = $LibTitle;
$Lib.Update();
after.ps1
$LibInfo = New-Object Microsoft.SharePoint.Client.ListCreationInformation;
$LibInfo.Title = $LibName;
$LibInfo.Description = $LibTitle;
$LibInfo.TemplateType = 101; # DocumentLibrary

$Lib = $Info.Web.Lists.Add($LibInfo);
$Lib.Title = $LibName;
$Lib.Update()
$Context.ExecuteQuery()

RootFolder.SubFolders.Add()

before.ps1
$subFolderHidden = $Lib.RootFolder.SubFolders.Add("private");
after.ps1
$context.Load($appLib.RootFolder);
$context.ExecuteQuery();

$appLib.RootFolder.AddSubFolder("private");

$context.Load($Lib.RootFolder.Folders);
$context.ExecuteQuery();

$Lib.RootFolder.Folders | ForEach-Object {
    if($_.Name -eq "private"){
            $subFolderHidden = $_;
    }
}

RoleAssignments.Add()

before.ps1
$roleReader = $Web.RoleDefinitions["閲覧"];
$LibRoleAssignment = New-Object Microsoft.SharePoint.SPRoleAssignment($ListRoleAssignment.Member);
$LibRoleAssignment.RoleDefinitionBindings.Add($roleReader);
$Lib.RoleAssignments.Add($LibRoleAssignment);
after.ps1
$Context.Load($ListRoleAssignment.Member);
$Context.ExecuteQuery();
Add-Role $Info $Lib "閲覧" $ListRoleAssignment.Member.LoginName;

function Add-Role($Info, $item, $role, $user){
    $account = $Info.Web.EnsureUser($user);

    $roleDefinition = $Info.Web.RoleDefinitions.GetByName($role);

    $assignment = New-Object Microsoft.SharePoint.Client.RoleDefinitionBindingCollection($Context);
    $assignment.Add($roleDefinition);

    $ra = $item.RoleAssignments.Add($account, $assignment);
    $Context.ExecuteQuery()
}

SPWeb

before.ps1
$ListUri = new-object System.Uri($ListUrl);
$Site = new-object Microsoft.SharePoint.SPSite($ListUrl);
$Web = $Site.OpenWeb($ListUri.LocalPath);
$List = $Web.GetList($ListUri.LocalPath);
after.ps1
$ListUri = new-object System.Uri($ListUrl);

$webs = $Context.Web.Webs
$Context.Load($webs)
$Context.ExecuteQuery()

# サブサイトのUrl取得
$url = $_.ListUrl;
$webUrl = ($url -split '/')[0..5] -join '/';

$Site = $Context.Site;
$Web = $webs | Where-Object {$_.Url -match $webUrl};
$List = $Web.GetList($ListUri);

AddItem()

before.ps1
$List.AddItem()
after.ps1
$creation = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
$List.AddItem($creation);

PAGETYPE

あってるのか不明

before.ps1
$List.Forms[([Microsoft.SharePoint.PAGETYPE]::PAGE_DISPLAYFORM)]
after.ps1
$List.Forms[([Microsoft.SharePoint.Client.PageType]::DisplayForm)];

CreateNewField

before.ps1
$ListField = $List.Fields.CreateNewField("TaxonomyFieldType", "hoge");
$ListField.ShowInEditForm = $False;
[void]$List.Fields.Add($appListField);
after.ps1
$schemaXML =  "<Field Name='hoge' DisplayName='hoge' Type='TaxonomyFieldType' />" ;  
$List.Fields.AddFieldAsXml($schemaXML, $true, [Microsoft.SharePoint.Client.AddFieldOptions]::DefaultValue);  
$List.Update();
$List.Fields.Update();
$Context.Load($List);
$Context.Load($List.Fields);
$Context.ExecuteQuery();

HasUniqueRoleAssignments

before.ps1
$Item.HasUniqueRoleAssignments
$List.HasUniqueRoleAssignments
$Folder.HasUniqueRoleAssignments
$File.HasUniqueRoleAssignments
after.ps1
[Helper]::HasUniqueRoleAssignmentsItem($Context, $Item)
[Helper]::HasUniqueRoleAssignmentsItem($Context, $List)
[Helper]::HasUniqueRoleAssignmentsItem($Context, $Folder)
[Helper]::HasUniqueRoleAssignmentsItem($Context, $File)
$Context.ExecuteQuery()
$Item.HasUniqueRoleAssignments
$List.HasUniqueRoleAssignments
$Folder.HasUniqueRoleAssignments
$File.HasUniqueRoleAssignments
after.cs
public static void HasUniqueRoleAssignmentsItem(ClientContext context, ListItem item){
    context.Load(
        item,
        i => i.HasUniqueRoleAssignments);
}
public static void HasUniqueRoleAssignmentsList(ClientContext context, List list){
    context.Load(
        list,
        l => l.HasUniqueRoleAssignments);
}
public static void HasUniqueRoleAssignmentsFolder(ClientContext context, Folder folder){
    context.Load(
        folder,
        f => f.ListItemAllFields.HasUniqueRoleAssignments);
}
public static void HasUniqueRoleAssignmentsFile(ClientContext context, File file){
    context.Load(
        file,
        f => f.ListItemAllFields.HasUniqueRoleAssignments);
}
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away