{"id":2607,"date":"2017-11-02T19:08:15","date_gmt":"2017-11-02T10:08:15","guid":{"rendered":"http:\/\/1bed.allright.life\/?p=2607"},"modified":"2020-04-18T20:22:04","modified_gmt":"2020-04-18T11:22:04","slug":"post-2607","status":"publish","type":"post","link":"https:\/\/1bed.allright.life\/?p=2607","title":{"rendered":"SharePoint \u3067\u9078\u629e\u80a2\u5217\u3068\u53c2\u7167\u5217\u3092 PowerShell \u3067\u4ed8\u3051\u66ff\u3048\u308b(2\/3)"},"content":{"rendered":"<p>\u524d\u56de\u306e\u7d9a\u304d\u3067\u3059<\/p>\n<p>\u4e0b\u8a18\u624b\u9806\u306e 2 \u756a\u76ee\u3001\u53c2\u7167\u5217\u306e\u4f5c\u6210\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n<ol>\n<li>\u9078\u629e\u80a2\u5217\u306e\u5024\u3092\u4f7f\u3044\u3001\u53c2\u7167\u5217\u5143\u306e\u30ea\u30b9\u30c8\u3092\u4f5c\u6210\u3059\u308b<\/li>\n<li>\u624b\u9806 1 \u3067\u4f5c\u6210\u3057\u305f\u30ea\u30b9\u30c8\u3092\u4f7f\u3044\u3001\u53c2\u7167\u5217\u3092\u4f5c\u6210\u3059\u308b<\/li>\n<li>\u9078\u629e\u80a2\u5217\u306e\u5024\u3092\u53c2\u7167\u5217\u306b\u79fb\u884c<\/li>\n<li>\u9078\u629e\u80a2\u5217\u306e\u524a\u9664<\/li>\n<\/ol>\n<h2>\u74b0\u5883<\/h2>\n<p>\u3053\u306e\u30ea\u30b9\u30c8\u306f\u6700\u521d\u306b\u4f5c\u3063\u3066\u3044\u305f<\/p>\n<ul>\n<li>\u30ea\u30b9\u30c8\u540d: \u9078\u629e\u80a2\u5217\u3068\u53c2\u7167\u5217\u3092\u4ed8\u3051\u66ff\u3048\u308b<\/li>\n<\/ul>\n<table>\n<thead>\n<tr>\n<th>\u5217\u540d<\/th>\n<th>\u5185\u90e8\u5217\u540d<\/th>\n<th>\u7a2e\u985e<\/th>\n<th>\u5024<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u76ee\u7684\u5730<\/td>\n<td>Title<\/td>\n<td>1 \u884c\u30c6\u30ad\u30b9\u30c8<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>\u4e57\u308a\u7269<\/td>\n<td>vehicle<\/td>\n<td>\u9078\u629e\u80a2<\/td>\n<td>\u8eca , \u30d0\u30a4\u30af , \u81ea\u8ee2\u8eca , \u8239 , \u98db\u884c\u6a5f<\/td>\n<\/tr>\n<tr>\n<td>\u304a\u3084\u3064<\/td>\n<td>snack<\/td>\n<td>\u9078\u629e\u80a2(\u8907\u6570\u9078\u629e\u53ef\u80fd)<\/td>\n<td>\u30dd\u30c6\u30c8\u30c1\u30c3\u30d7\u30b9 , \u30a2\u30dd\u30ed , \u3058\u3083\u304c\u308a\u3053 , \u30c1\u30c3\u30d7\u30b9\u30bf\u30fc , \u30cf\u30a4\u30ec\u30e2\u30f3 , \u304b\u3063\u3071\u3048\u3073\u305b\u3093<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u3053\u306e\u30ea\u30b9\u30c8\u3092\u524d\u56de\u4f5c\u3063\u305f<\/p>\n<ul>\n<li>\u9078\u629e\u80a2\u5217\u304b\u3089\u4f5c\u6210\u3055\u308c\u308b\u53c2\u7167\u5143\u30ea\u30b9\u30c8(\u30de\u30b9\u30bf\u30ea\u30b9\u30c8)<\/li>\n<\/ul>\n<table>\n<thead>\n<tr>\n<th>\u5217\u540d<\/th>\n<th>\u751f\u6210\u3055\u308c\u308b\u30ea\u30b9\u30c8\u540d<\/th>\n<th>\u30ea\u30b9\u30c8\u306e\u30bf\u30a4\u30c8\u30eb<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u4e57\u308a\u7269<\/td>\n<td>\u4e57\u308a\u7269\u30de\u30b9\u30bf<\/td>\n<td>vehicleMst<\/td>\n<\/tr>\n<tr>\n<td>\u304a\u3084\u3064<\/td>\n<td>\u304a\u3084\u3064\u30de\u30b9\u30bf<\/td>\n<td>snackMst<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4eca\u56de\u306f\u3053\u306e\u5217\u3092\u4f5c\u6210\u3059\u308b<\/p>\n<ul>\n<li>\u30ea\u30b9\u30c8\u300c\u9078\u629e\u80a2\u5217\u3068\u53c2\u7167\u5217\u3092\u4ed8\u3051\u66ff\u3048\u308b\u300d\u306b\u8ffd\u52a0\u3055\u308c\u308b\u53c2\u7167\u5217\u540d<\/li>\n<\/ul>\n<table>\n<thead>\n<tr>\n<th>\u5217\u540d<\/th>\n<th>\u5185\u90e8\u5217\u540d<\/th>\n<th>\u53c2\u7167\u30ea\u30b9\u30c8\u540d<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u4e57\u308a\u7269<\/td>\n<td>relVehicle<\/td>\n<td>\u4e57\u308a\u7269\u30de\u30b9\u30bf<\/td>\n<\/tr>\n<tr>\n<td>\u304a\u3084\u3064<\/td>\n<td>relSnack<\/td>\n<td>\u304a\u3084\u3064\u30de\u30b9\u30bf<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>1. \u9078\u629e\u80a2\u5217\u306e\u5024\u3092\u4f7f\u3044\u3001\u53c2\u7167\u5217\u5143\u306e\u30ea\u30b9\u30c8\u3092\u4f5c\u6210\u3059\u308b<\/h2>\n<p>\u3053\u3061\u3089\u306f\u6e08\u3067\u3059<\/p>\n<ul>\n<li><a href=\"http:\/\/1bed.allright.life\/?p=2592\">SharePoint \u3067\u9078\u629e\u80a2\u5217\u3068\u53c2\u7167\u5217\u3092 PowerShell \u3067\u4ed8\u3051\u66ff\u3048\u308b(1\/3)<\/a><\/li>\n<\/ul>\n<h2>2. \u300c\u9078\u629e\u80a2\u5217\u3068\u53c2\u7167\u5217\u3092\u4ed8\u3051\u66ff\u3048\u308b\u300d\u306b\u53c2\u7167\u5217\u3092\u4f5c\u6210<\/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# SharePoint Online \u306e URL\n$url = &#039;https:\/\/&lt;tenant&gt;.sharepoint.com\/sites\/example&#039;\n# \u30e6\u30fc\u30b6\u30fc\u540d\n$user = &#039;miyamiya@example.com&#039;;\n# \u30d1\u30b9\u30ef\u30fc\u30c9\n$secure = Read-Host -Prompt &quot;Enter the password for ${user}(Office365)&quot; -AsSecureString;\n# SharePoint Online \u8a8d\u8a3c\u60c5\u5831\n$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($user, $secure);\n# SharePoint Client Context \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u751f\u6210\n$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)\n$ctx.Credentials = $credentials\n\n## \u3053\u3053\u307e\u3067\u306f\u3044\u3064\u3082\u306e\u304a\u307e\u3058\u306a\u3044\u7684\u306a\u30b3\u30fc\u30c9\u3002\n## \u30ed\u30b0\u30a4\u30f3\u3057\u3066 SharePoint Client Context \u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u4f5c\u6210\u3057\u3066\u3044\u307e\u3059\u3002\n\n## \u5fc5\u8981\u306a\u5909\u6570\u5b9a\u7fa9\n\n# \u9078\u629e\u80a2\u5217\u3092\u53c2\u7167\u5217\u306b\u7f6e\u304d\u63db\u3048\u308b\u30ea\u30b9\u30c8\u306e\u30ea\u30b9\u30c8\u540d\n$baseListName = &quot;\u9078\u629e\u80a2\u5217\u3068\u53c2\u7167\u5217\u3092\u4ed8\u3051\u66ff\u3048\u308b&quot;\n\n# \u53c2\u7167\u5217\u5316\u3059\u308b\u5217\u540d\n$baseFieldName = &quot;\u4e57\u308a\u7269&quot;\n#$baseFieldName = &quot;\u304a\u3084\u3064&quot;\n\n# \u4f5c\u6210\u3059\u308b\u53c2\u7167\u5217\u306e\u5185\u90e8\u5217\u540d\n$makeFieldInternalName = &quot;relVehicle&quot;\n#$makeFieldInternalName = &quot;relSnack&quot;\n\n# \u4f5c\u6210\u3059\u308b\u53c2\u7167\u5217\u306e\u5217\u540d\n$makeFieldDisplayName = &quot;\u4e57\u308a\u7269&quot;\n#$makeFieldDisplayName = &quot;\u304a\u3084\u3064&quot;\n\n# \u30de\u30b9\u30bf\u30ea\u30b9\u30c8\u306e\u540d\u524d\n$mstListName = &quot;\u4e57\u308a\u7269\u30de\u30b9\u30bf&quot;\n#$mstListName = &quot;\u304a\u3084\u3064\u30de\u30b9\u30bf&quot;\n\n## \u30b5\u30fc\u30d0\u30fc\u304b\u3089\u5024\u306e\u53d6\u5f97\n\n# \u5217\u3092\u8ffd\u52a0\u3059\u308b\u30ea\u30b9\u30c8\n$baseList = $ctx.Web.Lists.GetByTitle($baseListName)\n# \u53c2\u7167\u5217\u5316\u3059\u308b\u5217\n$baseField = $baseList.Fields.GetByInternalNameOrTitle($baseFieldName)\n# \u30de\u30b9\u30bf\u30ea\u30b9\u30c8\n$mstList = $ctx.Web.Lists.GetByTitle($mstListName)\n\n# \u5024\u306e\u30ed\u30fc\u30c9\u4e88\u7d04\n$ctx.Load($baseList)\n$ctx.Load($baseField)\n$ctx.Load($mstList)\n$ctx.ExecuteQuery()\n\n## \u53c2\u7167\u5217\u306e\u5b9a\u7fa9\u751f\u6210\n\n# \u53c2\u7167\u5217\u306e XML \u30d5\u30a9\u30fc\u30de\u30c3\u30c8\n$fieldXmlFormat = @&quot;\n    &lt;Field Type=&#039;{0}&#039; DisplayName=&#039;{1}&#039; StaticName=&#039;{2}&#039; Name=&#039;{2}&#039;\n        List=&#039;{3}&#039;\n        Mult=&#039;{4}&#039;\n        Required=&#039;FALSE&#039; EnforceUniqueValues=&#039;FALSE&#039;\n        ShowField=&#039;Title&#039; UnlimitedLengthInDocumentLibrary=&#039;FALSE&#039; \n        RelationshipDeleteBehavior=&#039;None&#039;\n    \/&gt;\n&quot;@\n\nswitch ($baseField.TypeAsString.ToUpper()) {\n    &#039;CHOICE&#039; {\n        $fieldXml = ($fieldXmlFormat -f &#039;Lookup&#039;, $makeFieldDisplayName, $makeFieldInternalName, $mstList.Id, &#039;FALSE&#039;)\n    }\n    &#039;MULTICHOICE&#039; {\n        $fieldXml = ($fieldXmlFormat -f &#039;LookupMulti&#039;, $makeFieldDisplayName, $makeFieldInternalName, $mstList.Id, &#039;TRUE&#039;)\n    }\n    default {\n        # \u53c2\u7167\u5217\u5316\u3059\u308b\u4e88\u5b9a\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u304c\u9078\u629e\u80a2\u5217\u3067\u306a\u3044\u6642\u306f\u51e6\u7406\u3092\u505c\u6b62\n        Write-Host (&quot;{0} is not &#039;Choice&#039; or &#039;MultiChoice&#039;&quot; -f $baseFieldName)\n        exit\n    }\n}\n\n# \u53c2\u7167\u5217\u306e\u8ffd\u52a0\n$result = $baseList.Fields.AddFieldAsXml($fieldXml, $true, ([Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldToDefaultView -bor [Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldInternalNameHint))\n$result.Title = $makeFieldDisplayName\n$result.Update()\n$ctx.ExecuteQuery()\n\n# \u30b3\u30f3\u30c6\u30ad\u30b9\u30c8 \u306e\u7834\u68c4\n$ctx.Dispose()<\/code><\/pre>\n<p>\u624b\u9806\u7684\u306b\u306f\u3001\u3053\u306e\u8fba\u308a\u3092\u6ce8\u610f\u3057\u3066\u53c2\u7167\u5217\u3092\u4f5c\u308a\u307e\u3057\u305f<\/p>\n<ol>\n<li>\n<p>\u5217\u5b9a\u7fa9 XML \u3092\u4f5c\u6210<br \/>\n\u65e2\u5b58\u306e\u9078\u629e\u80a2\u5217\u3092\u53d6\u5f97\u3057\u3001\u8907\u6570\u9078\u629e\u304c\u8a31\u53ef\u3055\u308c\u3066\u3044\u305f\u3089 Type \u3092 LookupMulti \u306b\u3057\u3066\u3001 Mult \u3092 TRUE \u306b\u3059\u308b<\/p>\n<\/li>\n<li>\n<p>\u53c2\u7167\u5217\u306e\u8ffd\u52a0<br \/>\n\u5185\u90e8\u5217\u540d\u3092\u5f37\u5236\u3059\u308b\u3088\u3046\u306b\u3001AddFieldInternalNameHint \u3092\u4ed8\u3051\u308b<\/p>\n<\/li>\n<\/ol>\n<p>\u3064\u304e\u306f\u30c7\u30fc\u30bf\u30fc\u306e\u79fb\u884c\u3060\u306a\u30fc<br \/>\n\u697d\u3057\u307f\u3060\u306a\u30fc<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u56de\u306e\u7d9a\u304d\u3067\u3059 \u4e0b\u8a18\u624b\u9806\u306e 2 \u756a\u76ee\u3001\u53c2\u7167\u5217\u306e\u4f5c\u6210\u3092\u884c\u3044\u307e\u3059\u3002 \u9078\u629e\u80a2\u5217\u306e\u5024\u3092\u4f7f\u3044\u3001\u53c2\u7167\u5217\u5143\u306e\u30ea\u30b9\u30c8\u3092\u4f5c\u6210\u3059\u308b \u624b\u9806 1 \u3067\u4f5c\u6210\u3057\u305f\u30ea\u30b9\u30c8\u3092\u4f7f\u3044\u3001\u53c2\u7167\u5217\u3092\u4f5c\u6210\u3059\u308b \u9078\u629e\u80a2\u5217\u306e\u5024\u3092\u53c2\u7167\u5217\u306b\u79fb\u884c \u9078\u629e\u80a2\u5217\u306e\u524a\u9664 \u74b0\u5883 \u3053\u306e\u30ea [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,111],"tags":[62],"class_list":["post-2607","post","type-post","status-publish","format-standard","hentry","category-program","category-sharepoint","tag-powershell"],"_links":{"self":[{"href":"https:\/\/1bed.allright.life\/index.php?rest_route=\/wp\/v2\/posts\/2607","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=2607"}],"version-history":[{"count":10,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=\/wp\/v2\/posts\/2607\/revisions"}],"predecessor-version":[{"id":3118,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=\/wp\/v2\/posts\/2607\/revisions\/3118"}],"wp:attachment":[{"href":"https:\/\/1bed.allright.life\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2607"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2607"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2607"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}