IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

SharePoint .NET Discussion :

(SPO) Powershell pour lister les collections sur lesquelles une App est installée


Sujet :

SharePoint .NET

  1. #1
    Membre éclairé
    Homme Profil pro
    Formateur en informatique
    Inscrit en
    Mai 2007
    Messages
    724
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loire (Rhône Alpes)

    Informations professionnelles :
    Activité : Formateur en informatique

    Informations forums :
    Inscription : Mai 2007
    Messages : 724
    Points : 787
    Points
    787
    Par défaut (SPO) Powershell pour lister les collections sur lesquelles une App est installée
    Bonjour,
    Sur un environnement SP online, une app est installée dans certaines collections, et nécessite une mise à jour. Je cherche un powershell pour
    - lister les collections de mon tenant sur lesquelles l'app est installée ;
    - si possible exécuter la mise à jour d'un coup sur les collections concernées.
    Merci.
    Jean-François Fustec - Consultant Formateur - SharePoint - Office 365 - Infopath Lotus

  2. #2
    Membre chevronné
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    1 486
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations forums :
    Inscription : Mai 2004
    Messages : 1 486
    Points : 2 082
    Points
    2 082
    Par défaut
    Bonjour,

    Voici un petit exemple de script pour lister les apps. Je n'ai pas trouve mieux dans les api ou les cmdlet.
    Par contre pour les upgrades... aucune idee.

    Necessite le SharePoint Online Management Shell.

    Appel :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    PS C:\Users\xxx\Desktop> . .\Get-SPAppInstances.ps1 -tenantName "abc" -username "user.name@abc.onmicrosoft.com" -appName "Myapp"
    Script:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    #-------------------------------------------------------------------
    #
    # Get-SPAppInstances
    #
    #-------------------------------------------------------------------
     
    Param(
        # Ex: https://abc.sharpeoint.com -> abc
        [string]$tenantName,
        # Ex : user.name@abc.onmicrosoft.com
        [string]$username,
        # Ex: MyApp
        [string]$appName
    )
     
    #
    # INCLUDES
    #
     
    Import-Module "Microsoft.Online.SharePoint.PowerShell"
     
    #
    # CONST
    #
    [bool]$ROOTWEBONLY = $false
    [string]$APPTEMPLATENAME = "APP"
     
    #
    # FUNCTIONS
    #
     
    # Safe execution with incremental backoff
    function ExecuteQueryRetry($ctx){
     
        if($ctx -eq $null){
            throw "ctx null"
        }
        $maxRetries = 10
        $delay = 500
        $currentRetry = 0
     
        while($currentRetry -lt $maxRetries){
            try
            {
                $ctx.ExecuteQuery()
                return;
            }
            catch [Net.WebException] 
            {            
                [Net.HttpWebResponse]$ex = $_.Exception -as [Net.HttpWebResponse]
                if($ex -and ([int]($ex.StatusCode) -eq 429 -or [int]($ex.StatusCode) -eq 503)){
                    Write-Host "ExecuteQuery CSOM request frequency exceeded usage limits."
                    sleep -Milliseconds $delay     
                    $currentRetry += 1
                    $delay = $delay * 2
                }
                else{
                    Write-Host "ExecuteQuery Fatal Error : " $_.Exception.ToString() -ForegroundColor Red
                }
            }        
        }
        throw "ExecuteQueryRetry FAILED : Too many attempts."
    }
     
     
    function Get-SPOSiteCollections()
    {    
        param(
            [string]$tenantAdminUrl= $(throw "Please provide a Tenant admin Url"),
            [System.Management.Automation.PSCredential]$adminCredential = $(throw "Please provide a  System PSCredential")
        )
        Write-Host "Retrieving all site collections for tenant: $tenantAdminUrl "
     
        Connect-SPOService -Url $tenantAdminUrl -Credential $adminCredential
        $numSites = 0
     
        Get-SPOSite | %{
            $numSites += 1
            $_.Url
        }
     
        Write-Host "Site collections found: $numSites" -ForegroundColor Green
    }
     
    function Get-SPOWebs(){
        param(
           $Url = $(throw "Please provide a Site Collection Url"),
           $Credential = $(throw "Please provide a Credentials"),
           [Microsoft.SharePoint.Client.SubwebQuery] $query = $null
        )
        Write-Host "Reading Web: $Url"
     
        $context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
        $context.Credentials = $Credential 
        [Microsoft.SharePoint.Client.Web]$web = $context.Web
        $webCollection = $web.GetSubwebsForCurrentUser($query)
        $context.Load($webCollection)
     
        ExecuteQueryRetry($context)
     
        Write-Host "Found webs : " $webCollection.Count
        return $webCollection
     
    }
     
    function Get-SPOAppWebs(){
        param(
           [string]$Url = $(throw "Please provide a Site Collection Url"),
           [Microsoft.SharePoint.Client.SharePointOnlineCredentials]$Credential = $(throw "Please provide a Credentials"),
           [System.Guid]$productId = $(throw "Please provide an app ProductId")
        )
        Write-Host "Reading app in Web: $Url"
     
        $context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)  
        $context.Credentials = $Credential 
        [Microsoft.SharePoint.Client.Web]$web = $context.Web
        $appinstances = $web.GetAppInstancesByProductId($productId)
        $context.Load($appinstances)
     
        ExecuteQueryRetry($context)
        Write-Host "Found instances : " $appinstances.Count
        return $appinstances    
    }
     
    function Get-SPOAppProductId()
    {
        param(
            [string]$Url = $(throw "Please provide a Tenant admin url"),
            [System.Management.Automation.PSCredential]$Credential = $(throw "Please provide a System PSCredential"),
            [string]$applicationName = $(throw "Please provide an application name")
        )
        Connect-SPOService -Url $Url -Credential $Credential
     
        $app = (Get-SPOAppInfo -Name $applicationName | Select -First 1)
        if(-not $app){
            return $null
        }
        Write-Host "App found : " ($app | Select *) -ForegroundColor Green
     
        $appProductId = $app.ProductId
        return $appProductId
    }
     
    #
    #
    # SCRIPT START
    #
    #
     
     
    # The password for the tenant administration
    $AdminPassword = Read-Host -Prompt "Enter password" -AsSecureString
     
    # The main tenant admin url
    $Url = "https://" + $tenantName + "-admin.sharepoint.com/"
     
    # We need two sets of credential object, but it is the same user/pwd
    $credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $AdminPassword
    $spocredential = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $AdminPassword)
     
    # Product id retrieval. If the appli is not installed in the farm, should be null
    $productId = Get-SPOAppProductId -Url $Url -Credential $credential -applicationName $appName
    if(-not $productId){
        Write-Host "ProductId null, appname invalid or not installed ???" -ForegroundColor Red
        return
    }
     
    # Set in the CONST section for what type of search you want
    if($ROOTWEBONLY){
     
        # Searches only the main site of the site collection.
        # This can return a lot more information, but consumes more ExecuteQuery calls
     
        # All site collections
        (Get-SPOSiteCollections -tenantAdminUrl $Url -adminCredential $credential) | %{
     
            # Instanciate each Root Web and find in its app sites
            $siteUrl = $_
            Get-SPOAppWebs -Url $siteUrl -Credential $spocredential -productId $productId | %{
                $appWeb = $_
                # Returns the site url containing the app instance
                $siteUrl
            }
     
        }
     
    }
    else{
     
        # Searches all the sites of the site collection.
        # This scope is broader, but in order not to consume ExecuteQuery calls, only works with the site url
     
        # All site collections
        (Get-SPOSiteCollections -tenantAdminUrl $Url -adminCredential $credential) | %{
     
            # Instanciate each Root Web and find in its app sites
            $siteUrl = $_
            Get-SPOWebs -Url $siteUrl -Credential $spocredential | %{
                [Microsoft.SharePoint.Client.Web]$undefinedWeb = $_
     
                # Installed apps sites check
                if($undefinedWeb.WebTemplate -eq $APPTEMPLATENAME){
                    Write-Host $undefinedWeb.Url -ForegroundColor Gray
                    $appWeb = $undefinedWeb
     
                    # Check url ends with appname
                    if($appWeb.Url -like ("*/" + $appName) ){
     
                        $parentWebUrl = ($appWeb.Url -replace "((.+($tenantName))(-.+)(\.sharepoint.com/.+)(/$appName))",'$2$5')
     
                        # Returns the site url containing the app instance into the pipeline
                        $parentWebUrl
                    }
                }
            }
        }
    }

  3. #3
    Membre éclairé
    Homme Profil pro
    Formateur en informatique
    Inscrit en
    Mai 2007
    Messages
    724
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loire (Rhône Alpes)

    Informations professionnelles :
    Activité : Formateur en informatique

    Informations forums :
    Inscription : Mai 2007
    Messages : 724
    Points : 787
    Points
    787
    Par défaut
    Merci, ça m'ouvre des pistes.
    Jean-François Fustec - Consultant Formateur - SharePoint - Office 365 - Infopath Lotus

  4. #4
    Membre chevronné
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    1 486
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations forums :
    Inscription : Mai 2004
    Messages : 1 486
    Points : 2 082
    Points
    2 082
    Par défaut
    J'aurai tendance a dire que la fonction d'update des apps est reservee a une interface utilisateur et on ne trouvera pas d'API pour ca.

    La raison est que l'utilisateur doit pouvoir prendre connaissance et accepter la concession de permissions que l'app requiert (le fameux ecran "Trust it").

    Cela vaut peut etre le coup de faire une UI Automation genre Selenium ou bien CodedUI sous Visual studio.

  5. #5
    Membre éclairé
    Homme Profil pro
    Formateur en informatique
    Inscrit en
    Mai 2007
    Messages
    724
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loire (Rhône Alpes)

    Informations professionnelles :
    Activité : Formateur en informatique

    Informations forums :
    Inscription : Mai 2007
    Messages : 724
    Points : 787
    Points
    787
    Par défaut
    La ligne suivante concernait un exemple inapproprié :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    (Get-SPOSiteCollections -tenantAdminUrl $Url -adminCredential $credential) | ?{ $_ -match "dev_apps"} | %{
    mais celle-ci ne fonctionne pas
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    (Get-SPOSiteCollections -tenantAdminUrl $Url -adminCredential $credential) | where-object {$_.Title -eq $Appname} | %{
    Une idée ?
    Jean-François Fustec - Consultant Formateur - SharePoint - Office 365 - Infopath Lotus

  6. #6
    Membre chevronné
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    1 486
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations forums :
    Inscription : Mai 2004
    Messages : 1 486
    Points : 2 082
    Points
    2 082
    Par défaut
    Pardon, j'avais laisse trainer un filtre qui etait mon site de test.

    J'ai corrige le post precedent de facon a ce qu'il n'y ait plus de filtre (on veut que toutes les collections de sites soient interrogees).

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    (Get-SPOSiteCollections -tenantAdminUrl $Url -adminCredential $credential) | %{

Discussions similaires

  1. Réponses: 3
    Dernier message: 11/06/2012, 22h38
  2. Req pour lister les index d'une table ?
    Par nanou9999 dans le forum MS SQL Server
    Réponses: 3
    Dernier message: 04/05/2009, 11h08
  3. Req pour lister les vues d'une base ?
    Par nanou9999 dans le forum MS SQL Server
    Réponses: 6
    Dernier message: 05/07/2006, 08h12
  4. [VB.NET 2.0] Comment lister les processus sur PPC ?
    Par catzguy dans le forum Windows Mobile
    Réponses: 6
    Dernier message: 16/04/2006, 00h38
  5. [reseaux] Lister les processus sur une machine donnée
    Par BEAUJAULT dans le forum Programmation et administration système
    Réponses: 2
    Dernier message: 29/07/2004, 15h55

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo