none
SharePoint Online(Office365)の、ゴミ箱の中身を全件削除。 RRS feed

  • 質問

  • PowerShellを使い、SharePoint Onlineのゴミ箱を一括で削除したいです。

    【作成したコード】

    # .NET CSOM モジュールの読み込み
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")         | Out-Null
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime") | Out-Null
    
    # 変数宣言
    $siteUrl         = "対象サイト"
    $accountName     = "アカウントID"
    $passWord        = ConvertTo-SecureString -AsPlainText -Force "パスワード"
    
    # ログイン情報入力
    $ctx             = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
    $credentials     = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($accountName, $passWord)
    $ctx.Credentials = $credentials
    $siteUrl         = $ctx.Web
    $ctx.Load($siteUrl)
    
    # ゴミ箱の中身、完全削除
    Connect-SPOService -Url $siteUrl -Credential "管理者ID"
    Remove-SPODeletedSite -Identity $siteUrl


    【参考にしたサイト】

    参考1

    参考2

    管理者IDで実行してもエラーが出てしまいます。

    【エラー内容】

    Cannot bind parameter 'Url'. Cannot convert the "Microsoft.SharePoint.Client.Web" value of type "Microsoft.SharePoint.Client.Web" to type "Microsoft.Online.SharePoint.PowerShell.UrlCmdletPipeBind".

    翻訳 → 

    パラメータ 'Url'をバインドできません。 型 "Microsoft.SharePoint.Client.Web"の "Microsoft.SharePoint.Client.Web"値を型に変換できません。  "Microsoft.Online.SharePoint.PowerShell.UrlCmdletPipeBind"

    Remove-SPODeletedSite : Cannot bind parameter 'Identity'. Cannot convert the "Microsoft.SharePoint.Client.Web" value of type "Microsoft.SharePoint.Client.Web" 
    to type "Microsoft.Online.SharePoint.PowerShell.SpoSitePipeBind".

    翻訳 → 

    Remove-SPODeletedSite:パラメータ 'Identity'をバインドできません。 "Microsoft.SharePoint.Client.Web"型の値 "Microsoft.SharePoint.Client.Web"を変換できません。
    「Microsoft.Online.SharePoint.PowerShell.SpoSitePipeBind」と入力します。

    >「Connect-SPOService」と「Remove-SPODeletedSite」の関数が使用出来ないのでしょうか。

    自分の関数の使い方、宣言の仕方が悪いのでしょうか?

    どなたか分かる方がいれば、よろしくお願い致します。

    ----

    ・PowerShell ver5.0

    • 編集済み mie.8 2017年6月26日 5:37 本文追記。
    2017年6月26日 5:30

回答

  • $siteUrl 変数を $ctx.Webで上書きしてしまっているのがまずい気がします。

    変数を分けてみてはいかがでしょうか。

    • 回答としてマーク mie.8 2017年6月26日 6:41
    2017年6月26日 6:19
    モデレータ
  • Remove-SPODeletedSite

    >  このコマンドレットを実行するには、SharePoint Online 全体管理者およびサイト コレクション管理者のアクセス許可が必要です。

    と明記されていますので、無理だと思います。

    • 回答としてマーク mie.8 2017年6月26日 6:49
    2017年6月26日 6:34
    モデレータ

すべての返信

  • $siteUrl 変数を $ctx.Webで上書きしてしまっているのがまずい気がします。

    変数を分けてみてはいかがでしょうか。

    • 回答としてマーク mie.8 2017年6月26日 6:41
    2017年6月26日 6:19
    モデレータ
  • ご回答ありがとうございます。

    変数を分けて実行してみたいと思います。

    また、ゴミ箱の中身削除は「管理者アカウント」でなくては実行出来ないでしょうか?

    一般ユーザーで、上記のプログラムを実行するにはどうすればよろしいでしょうか?


    • 編集済み mie.8 2017年6月26日 6:42 誤字
    2017年6月26日 6:29
  • Remove-SPODeletedSite

    >  このコマンドレットを実行するには、SharePoint Online 全体管理者およびサイト コレクション管理者のアクセス許可が必要です。

    と明記されていますので、無理だと思います。

    • 回答としてマーク mie.8 2017年6月26日 6:49
    2017年6月26日 6:34
    モデレータ
  • やはりそうですか・・・。

    いつもお助け頂き、ありがとうございます。

    2017年6月26日 6:41