Jump to content
    x
    Upvote if you also have this question or find it interesting.
    Learn more

    ADC 13.x Nitro powershell how to list files filesystem directory

      Martin de Vries|0 |Members|1 post

      Hi, has someone figured out how to list directory content for e.g. /nsconfig/ssl/ with nitro and powershell? i somehow get only the first file name returned.

      and has someone a example (powershell) how in com.citrix.netscaler.nitro.resource.config.system.systemfile the property filemode is used?

      filemodeRead-only

      file mode.
      Possible values = DIRECTORY

      2 answers to this question

      Recommended Posts

      x
      Mark this reply as best answer, if it answered your question.
      Learn more
      x
      Upvote if you found this answer helpful or interesting.
      Learn more
      Jens Dellner|Aficionado|188 |Members|133 posts

      Good Morning Martin,
      the Nitro command to list the systemfiles always requires the argument filelocation.

      https:/// nitro/v1/config/systemfile?args=filelocation:<地址>

      You always start with the view of your Root (/) and its files and folders.

      List files and folders of your nsconfig folder (/nsconfig/):

      https:/// nitro/v1/config/systemfile?args=filelocation:nsconfig

      If you want to query subfolders or the root directory by itself, you cannot use the filelocation:/ oder filelocation:nsconfig/ssl. You need to encode special characters. Simply change / to %2F.

      List files and folders of your Root (/):

      https:/// nitro/v1/config/systemfile?args=filelocation:2%F

      List files and folders of your ssl folder (/nsconfig/ssl):

      https:/// nitro/v1/config/systemfile?args=filelocation:nsconfig%2Fssl


      So how do you use it with powershell?
      1. Create a NITRO Session (Replace Username, Password, ):

      $body = ConvertTo-JSON @{"login"=@{"username"="Username";"password"="Password"}} Invoke-RestMethod -uri "https:/// nitro/v1/config/login" -body $body -SessionVariable NSSession -Headers @{"Content-Type"="application/vnd.com.citrix.netscaler.login+json"} -Method POST $Script:NSSession = $local:NSSession

      2a. List files and folders of nsconfig folder (/nsconfig/):

      Invoke-RestMethod uri“https:/// nitro/v1/config/systemfile?args=filelocation:nsconfig" -WebSession $NSSession -Headers @{"Content-Type"="application/vnd.com.citrix.netscaler.systemfile+json"} -Method GET

      List_nsconfig.thumb.png.f44578a2131a4c3f7d952f62de81f580.png

      2b. List files and folders of nsconfig folder (/nsconfig/) more readable:

      (Invoke-RestMethod -uri "https:/// nitro/v1/config/systemfile?args=filelocation:nsconfig" -WebSession $NSSession -Headers @{"Content-Type"="application/vnd.com.citrix.netscaler.systemfile+json"} -Method GET).systemfile

      List_nsconfig-Readable.thumb.png.d5632206236f697c5f6d42c1f75ae56d.png

      2c. List only folders of nsconfig folder (/nsconfig/) more readable:

      (Invoke-RestMethod -uri "https:/// nitro/v1/config/systemfile?args=filelocation:nsconfig" -WebSession $NSSession -Headers @{"Content-Type"="application/vnd.com.citrix.netscaler.systemfile+json"} -Method GET).systemfile | Where-Object {$_.filemode -EQ {DIRECTORY}}

      List_nsconfigFolders-Readable.thumb.png.a22b632cd892802bf9af87d3d4543402.png

      3. Quit a NITRO Session:

      $body = ConvertTo-JSON @{"logout"=@{}} Invoke-RestMethod -uri "https:/// nitro/v1/config/logout" -body $body -WebSession $NSSession -Headers @{"Content-Type"="application/vnd.com.citrix.netscaler.logout+json"} -Method POST


      I know your discussion post is a little bit older, but maybe you haven´t found a solution yet or it helps others in the future.

      P.s.: I don´t think that you can use the value "filemode" in any other way. The possible value "Directory" is only an additional value for folders and not files.

      Best regards,

      Jens

      x
      Mark this reply as best answer, if it answered your question.
      Learn more
      x
      Upvote if you found this answer helpful or interesting.
      Learn more
      Marek Jones|0 |Members|1 post

      Hello all,

      do you know please if it's possible to get the list of files and folders by Invoke-WebRequest ? [I proxy my request through ADM Service]

      The goal is to download whole folder from a netscaler and save it locally.

      With an only one file it works [/config/systemfile/ns.log?args=filelocation:%2fvar%2Flog], but not with a folder.

      $strURI = https://adm.cloud.com/massvc/xxx/nitro/v1/config/systemfile/?args=filelocation:%2Fvar%2Flog%2F
      $headers = @{
      _MPS_API_PROXY_MANAGED_INSTANCE_NAME = "adc"
      Authorization = "CwsAuth bearer=$($token.access_token)"
      isCloud = 'true'
      }

      Invoke-WebRequest-UseBasicParsing $strURI -Headers $headers -Method GET

      I am getting only one file from the folder /var/log/

      I tried different folder and I am getting only one folder but not file(s).

      Thank you

      Marek

      Please sign in to comment

      You will be able to leave a comment after signing in



      Sign in now

        Welcome to the Citrix Discussions. Our site does not support outdated browser (or earlier) versions. To use our site, please take one of the following actions:

        • Upgrade your version of Internet Explorer. You can find more informationhere
        • Install the Google browser. You can find more informationhere
        • Install the Firefox browser. You can find more informationhere

        Thank you,
        The Citrix Discussions Team.

        ×
        ×
        • Create New...