For billing purposes > improve reporting for multitenant Sharefile Servers.

  • 1
  • Idea
  • Updated 1 week ago

Create additional Reports for MTZ with all info about tenants (Storage and licenses used )

The idea is to improve the billing process by having for example a powershell script to get those informations quickly without the need to login on the Sharefile Webportal.

Photo of Aldo Richner

Aldo Richner

  • 6 Posts
  • 1 Reply Like
  • tired, annoyed, frustrated

Posted 11 months ago

  • 1
Photo of Eliezer Encarnacion

Eliezer Encarnacion, Official Rep

  • 732 Posts
  • 102 Reply Likes
Aldo,

What information do you need? Exactly the same as the web application (licenses, storage zone, storage used, and status)? You should be able to get that info via powershell, we can put a script together.

Eli
Photo of Aldo Richner

Aldo Richner

  • 6 Posts
  • 1 Reply Like
Hi Eli!

Yes that would be enough! I created a case and they told me it wouldn't be possible and that i should post this request into this community.. it would be great if you have anything like this :)

Regards!
Aldo
Photo of Eliezer Encarnacion

Eliezer Encarnacion, Official Rep

  • 732 Posts
  • 102 Reply Likes
Aldo,

Good and bad news. The good news is that we can get most of the info via a powershell script, the bad news is that the Tenant Zone usage is not yet available. I will put in a request to open up that information via API. Here's the script: https://eliezeren.sharefile.com/d-s62b6d7ffa1844aea. It accepts one parameter, the location of the file where the credentials are saved (wherever you save the results of the New-SfClient command).

.\tenantInfo.ps1 <location of credentials file>
That will output a table with the same info the web portal shows. If you get any errors, try downloading the newest Powershell SDK version (https://github.com/citrix/ShareFile-PowerShell/releases)

Thanks!
Eli
Photo of Giuseppe Marchese

Giuseppe Marchese

  • 9 Posts
  • 0 Reply Likes
Hi Eli

i've downloaded your powershell script and it looks fine. Thanks a lot.
The only thing, that i need is the used storage per tenant. 

Regards
Giuseppe
Photo of Giuseppe Marchese

Giuseppe Marchese

  • 9 Posts
  • 0 Reply Likes
Any Ideas?
Photo of Eliezer Encarnacion

Eliezer Encarnacion, Official Rep

  • 732 Posts
  • 102 Reply Likes
Hi Giuseppe,

Still no updates to the SDK to obtain the storage per tenant, but you can actually get the information by making a "raw" http request to the relevant endpoint, like this:

$zoneUsageUri = "$($sfClient.PrimaryDomain.Uri)/Accounts/Tenants/ZoneUsage"$zoneUsageResponse = Invoke-WebRequest -Uri $zoneUsageUri -Headers @{"Authorization"="Bearer $($sfClient.PrimaryDomain.OAuthToken)"}$zoneUsage = $zoneUsageResponse.Content | ConvertFrom-Json

The $zoneUsage variable is a dictionary that maps each account to a list of zones and the respective usage of each zone.  Here's the structure of the JSON object:

I update the script, feel free to download from the link above. I didn't have an account with usage to test, but I believe it should work.

Thanks,
Eli
Photo of Giuseppe Marchese

Giuseppe Marchese

  • 9 Posts
  • 0 Reply Likes
Hi Eli

The Link actually does not work.
Could please share it again?

Thanks.

Giuseppe 
Photo of Biagio Nicoli

Biagio Nicoli

  • 2 Posts
  • 0 Reply Likes
Hi Eli

We have the exact same request. Can you please reshare your script?

Thanks 
Biagio
Photo of Eliezer Encarnacion

Eliezer Encarnacion, Official Rep

  • 732 Posts
  • 102 Reply Likes
Here's a refreshed link to the script: https://eliezeren.sharefile.com/d-s2eedb4e023b4bb2a

Thanks,
Eli
Photo of Biagio Nicoli

Biagio Nicoli

  • 2 Posts
  • 0 Reply Likes
great, many thanks!
Photo of Olivier Patiny

Olivier Patiny

  • 6 Posts
  • 1 Reply Like
Hello

The "Invoke-WebRequest" command returns an error "The client does not have the requested scopes the endpoint requires..." and therefore, I don't get the "Zone Usage".
Can you please help ?
Thank you
Photo of Eliezer Encarnacion

Eliezer Encarnacion, Official Rep

  • 732 Posts
  • 102 Reply Likes
I'll look into that

Thanks,
Eli
Photo of Eliezer Encarnacion

Eliezer Encarnacion, Official Rep

  • 732 Posts
  • 102 Reply Likes
Oliver and all,

There was a security update that inadvertently locked out the Zone Usage endpoint a bit too much. I'll make a change to open the endpoint again for use within the SDK, which should be released within the next two weeks. I apologize for this inconvenience, and thank you for your patience while we resolve this matter.

Thanks,
Eli 
Photo of Olivier Patiny

Olivier Patiny

  • 6 Posts
  • 1 Reply Like

OK.

I wait for the correction to be released.

Thank you

Olivier

(Edited)
Photo of Eliezer Encarnacion

Eliezer Encarnacion, Official Rep

  • 732 Posts
  • 102 Reply Likes
Hi Olivier,

The correction has been approved and staged for release, it should be working again within the next week. Thank you for your patience.

Eli
Photo of Olivier Patiny

Olivier Patiny

  • 6 Posts
  • 1 Reply Like

Hello

Thank you very much.

I tested today but still not working. I will test again by the end of this week.

Olivier
Photo of Olivier Patiny

Olivier Patiny

  • 6 Posts
  • 1 Reply Like

Hello

I tested this morning and it is now working.

Thank you very much for your help

Olivier
Photo of Giuseppe Marchese

Giuseppe Marchese

  • 9 Posts
  • 0 Reply Likes
Hi Eli

it is again not working :-(  >>>>

At line:9 char:12
+ $tenants = Send-SfRequest -Client $sfClient -Method GET -Entity Accou ...
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Accounts:String) [Send-SfRequest], Exception
    + FullyQualifiedErrorId : InternalServerError,ShareFile.Api.Powershell.SendSfRequest

Please check...

Regards
Giuseppe
Photo of Eliezer Encarnacion

Eliezer Encarnacion, Official Rep

  • 732 Posts
  • 102 Reply Likes
Hi Giuseppe,

Could you create a new post reporting this error? I am no longer working on the ShareFile team, but any of the current ShareFile API team members will be able to assist with this one. Just provide the entire script and the error message as you did here.

Thanks!
Eli
Photo of Olivier Patiny

Olivier Patiny

  • 6 Posts
  • 1 Reply Like
Hi Giuseppe,
Can you insert a link to this new post that Eli asked you to create ?
Thanks in advance
Photo of Giuseppe Marchese

Giuseppe Marchese

  • 9 Posts
  • 0 Reply Likes
Hi all

sometimes it works and sometimes it doesn't work...
The first time when i start the script it does not load the Zone Usage and i get this error message:

ConvertPSObjectToHashtable : The term 'ConvertPSObjectToHashtable' is not recognized as the name of a 
cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was 
included, verify that the path is correct and try again.
At C:\DTC_Scripts\Verrechnung\AD_und_Server_Datenvolumen\04_Sharefile\tenantInfo.ps1:17 char:42
+ $usageHash = $zoneUsage.TenantsToZones | ConvertPSObjectToHashtable
+                                          ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (ConvertPSObjectToHashtable:String) [], CommandNotFound 
   Exception
    + FullyQualifiedErrorId : CommandNotFoundException

but the second time it loads the zone usage.

see below the script:

Param([string]$credentialsFile)

Add-PSSnapin ShareFile

#Anmelden mit gespeicherten Anmeldedaten
$sfClient = Get-SfClient –Name "C:\DTC_Scripts\Verrechnung\AD_und_Server_Datenvolumen\04_Sharefile\multitenant.sfps"

#Get Tenant License info
$tenants = Send-SfRequest -Client $sfClient -Method GET -Entity Accounts -Navigation Tenants -Expand "Preferences,Preferences/DefaultZone,UserUsage"

#Get Zone usage
$zoneUsageUri = "$($sfClient.PrimaryDomain.Uri)/Accounts/Tenants/ZoneUsage"
$zoneUsageResponse = Invoke-WebRequest -Uri $zoneUsageUri -Headers @{"Authorization"="Bearer $($sfClient.PrimaryDomain.OAuthToken)"}

$zoneUsage = $zoneUsageResponse.Content | ConvertFrom-Json

$usageHash = $zoneUsage.TenantsToZones | ConvertPSObjectToHashtable

#Output values
$tenantInfo = $tenants | Select-Object @{N="Account Name";E={$_.CompanyName}}, @{N="Licenses Used";E={$_.UserUsage.EmployeeCount}},@{N="Storage Zone";E={$_.Preferences.DefaultZone.Name}}, @{N="Zone Usage (Bytes)";E={$usageHash[$_.Id]['ZonesToUsage'][$_.Preferences.DefaultZone.Id].TotalFileSizeBytes}}, @{N="Status";E={If ($_.IsFreeTrial) {"Trial"} Else {"Paid"}}}

Write-Output($tenantInfo)

function ConvertPSObjectToHashtable
{
    param (
        [Parameter(ValueFromPipeline)]
        $InputObject
    )

    process
    {
        if ($null -eq $InputObject) { return $null }

        if ($InputObject -is [System.Collections.IEnumerable] -and $InputObject -isnot [string])
        {
            $collection = @(
                foreach ($object in $InputObject) { ConvertPSObjectToHashtable $object }
            )

            Write-Output -NoEnumerate $collection
        }
        elseif ($InputObject -is [psobject])
        {
            $hash = @{}

            foreach ($property in $InputObject.PSObject.Properties)
            {
                $hash[$property.Name] = ConvertPSObjectToHashtable $property.Value
            }

            $hash
        }
        else
        {
            $InputObject
        }
    }
}


Best Regards
Giuseppe
Photo of Mr. C.

Mr. C.

  • 1 Post
  • 0 Reply Likes
Hello team, What is the format of the requested credential file?

Photo of Olivier Patiny

Olivier Patiny

  • 6 Posts
  • 1 Reply Like
Hello
This file is created using the powershell command :
New-SfClient –Name <filename>

For example :
New-SfClient –Name "c:\tmp\sflogin.sfps"
Best regards
Olivier

(Edited)