{"id":2529,"date":"2017-06-21T00:51:55","date_gmt":"2017-06-20T15:51:55","guid":{"rendered":"http:\/\/1bed.allright.life\/?p=2529"},"modified":"2020-04-18T20:34:47","modified_gmt":"2020-04-18T11:34:47","slug":"post-2529","status":"publish","type":"post","link":"https:\/\/1bed.allright.life\/?p=2529","title":{"rendered":"PowerShell CSOM \u5099\u5fd8\u9332"},"content":{"rendered":"<h1>PowerShell CSOM(Client SharePoint Object Model) \u3092\u4f7f\u3063\u305f\u5099\u5fd8\u9332<\/h1>\n<h2>SharePoint Online \u3078\u306e\u30ed\u30b0\u30a4\u30f3<\/h2>\n<pre><code class=\"language-powershell\">[void][System.Reflection.Assembly]::LoadWithPartialName(&quot;Microsoft.SharePoint.Client&quot;)\n[void][System.Reflection.Assembly]::LoadWithPartialName(&quot;Microsoft.SharePoint.Client.Runtime&quot;)\n\n# \u53d6\u5f97\u3059\u308b SharePoint Online \u306e URL\n$url = &#039;https:\/\/&lt;your tenant&gt;\/&lt;your site&gt;&#039;\n\n# \u30e6\u30fc\u30b6\u30fc\u540d\n$user = &#039;&lt;your account&gt;&#039;;\n\n# \u30d1\u30b9\u30ef\u30fc\u30c9\n$secure = Read-Host -Prompt &quot;Enter the password for ${user}(Office365)&quot; -AsSecureString;\n\n# SharePoint Online \u8a8d\u8a3c\u60c5\u5831\n$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($user, $secure);\n\n# SharePoint Client Context \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u751f\u6210\n$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($url)\n$ctx.Credentials = $credentials<\/code><\/pre>\n<h2>\u30ea\u30b9\u30c8\u60c5\u5831\u306e\u53d6\u5f97<\/h2>\n<h3>URL \u3092\u76f4\u63a5\u6307\u5b9a<\/h3>\n<pre><code class=\"language-powershell\">$ctx.Web.GetList(&#039;\u30ea\u30b9\u30c8\u307e\u3067\u306e\u7d76\u5bfe\u30d1\u30b9\u3001\u53c8\u306f\u76f8\u5bfe\u30d1\u30b9&#039;)\n\n# \u4f8b. $ctx.Web.GetList(&#039;https:\/\/example.sharepoint.com\/learn\/Lists\/test&#039;)\n# \u4f8b. $ctx.Web.GetList(&#039;\/learn\/Lists\/test&#039;)<\/code><\/pre>\n<h3>\u30ea\u30b9\u30c8\u30bf\u30a4\u30c8\u30eb\u3092\u6307\u5b9a<\/h3>\n<pre><code class=\"language-powershell\">$ctx.Web.Lists.GetByTitle(&#039;\u30ea\u30b9\u30c8\u306e\u30bf\u30a4\u30c8\u30eb&#039;)\n\n# \u4f8b. $ctx.Web.Lists.GetByTitle(&#039;\u30c6\u30b9\u30c8\u30ea\u30b9\u30c8&#039;)<\/code><\/pre>\n<h3>\u30ea\u30b9\u30c8 ID \u3092\u6307\u5b9a<\/h3>\n<pre><code class=\"language-powershell\">$ctx.Web.Lists.GetById(&#039;\u30ea\u30b9\u30c8\u306e ID&#039;)\n\n# \u4f8b. $ctx.Web.Lists.GetById(&#039;ec173195-aid8-42d6-9ll6-87oie35t0cd3&#039;)<\/code><\/pre>\n<h2>\u5217\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u5909\u66f4<\/h2>\n<h3>\u753b\u9762\u306b\u3088\u3063\u3066\u5217\u306e\u8868\u793a\u30fb\u975e\u8868\u793a\u3092\u5207\u308a\u66ff\u3048\u308b<\/h3>\n<pre><code class=\"language-powershell\"># \u30ea\u30b9\u30c8\u306e\u60c5\u5831\u3092\u53d6\u5f97\n$list = $ctx.Web.GetList(&#039;path&#039;)\n\n# \u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u60c5\u5831\u3092\u53d6\u5f97\n$fields = $list.Fields\n\n# \u30ed\u30fc\u30c9\u3068\u30b5\u30fc\u30d0\u30fc\u3078\u554f\u5408\u305b\n$ctx.Load($fields)\n$ctx.ExecuteQuery()\n\n# \u5909\u66f4\u3059\u308b\u5217\u306e\u53d6\u5f97\n$target = $fields.GetByInternalNameOrTitle(&#039;column name&#039;)\n\n# \u30ed\u30fc\u30c9\u3068\u30b5\u30fc\u30d0\u30fc\u554f\u5408\u305b\n$ctx.Load($target)\n$ctx.ExecuteQuery()\n\n# \u30a2\u30a4\u30c6\u30e0\u306e\u8a73\u7d30\u753b\u9762\u3067\u306f\u8868\u793a\n$target.SetShowInDisplayForm($true)\n\n# \u30a2\u30a4\u30c6\u30e0\u306e\u65b0\u898f\u753b\u9762\u3067\u306f\u8868\u793a\n$target.SetShowInNewForm($true)\n\n# \u30a2\u30a4\u30c6\u30e0\u306e\u7de8\u96c6\u753b\u9762\u3067\u306f\u975e\u8868\u793a\n$target.SetShowInEditForm($false)\n\n# \u5217\u60c5\u5831\u306e\u66f4\u65b0\u4e88\u7d04\u3068\u66f4\u65b0\n$target.Update()\n$ctx.ExecuteQuery()<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>PowerShell CSOM(Client SharePoint Object Model) \u3092\u4f7f\u3063\u305f\u5099\u5fd8\u9332 SharePoint Online \u3078\u306e\u30ed\u30b0\u30a4\u30f3 [void][System.Reflection.Asse [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[111],"tags":[62],"class_list":["post-2529","post","type-post","status-publish","format-standard","hentry","category-sharepoint","tag-powershell"],"_links":{"self":[{"href":"https:\/\/1bed.allright.life\/index.php?rest_route=\/wp\/v2\/posts\/2529","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/1bed.allright.life\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/1bed.allright.life\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2529"}],"version-history":[{"count":7,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=\/wp\/v2\/posts\/2529\/revisions"}],"predecessor-version":[{"id":3124,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=\/wp\/v2\/posts\/2529\/revisions\/3124"}],"wp:attachment":[{"href":"https:\/\/1bed.allright.life\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2529"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}