• Hi Rui

    Two things here - first, this is a problem when people just copy code without understanding what they actually need. You don't need the useragent parameter or even the usebasicparsing parameter. The URL is a requirement but you don't have to declare it, so the response can be simply

      $resp = Invoke-WebRequest $url -Body $body -Method Post

    On the same subject, $orgid is not used in this script either, but set at the top.

     

    Next the 'Underlying connection' issue - this is an SSL problem. It looks like you have reduced the SSL versions you accept (quite right too!). I'm somewhat surprised that no one else has hit this and yelled. there is simple fix however without needing to compromise your security - just add this line of code into the top of your script:

    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

    This will force the connection to use TLS 1.2.

     

    Cheers

    Richard

  • Hi Nick, thanks for this script. I was trying to use it but I keep getting the error:

    Caught exception: The underlying connection was closed: An unexpected error occurred on a send. The underlying connection was closed: An unexpected error occurred on a send.

    The underlying connection was closed: An unexpected error occurred on a send.

    Error signing off

     

    This happens when I try the line:

    $resp = Invoke-WebRequest -Uri $url -Body $body -Method Post -UserAgent $useragent -UseBasicParsing 

     

    This one has a little issue since the variable $useragent is not assigned before.

     

    When I use the swagger interface with the token API, it works fine (just filled the username and password).

     

    I also tried to use the script locally on the server using the localhost server.

     

    Any idea?

  • Hi Nick

     

    Perfect, thank you for your help, i have only changed the following line,

     

    from:

    # new user information in json format

       $payloadjson = @"

       {

           "fullName": "$FullName",

    To:

       # new user information in json format

       $payloadjson = @"

       {

           "realName": "$FullName",

     

    best regards and again many thanks

    Ugur :-)

           

  • Ugur,

     

    That was a great suggestion! I have updated the script to revoke the token (sign out) after the user creation is complete.

     

    Nick

  • Dear Nick

     

    I thank you for this script with which i can finally import users from a csv file,

     

    but now I have only one small question remaining.

     

    After i executed this script, the login session of the administartor account remains activated, so i can not login using a brwoser with my administrator account, until the session is automatically deleted after 5 or 10min or I must restart all service on my MoveIT Server.

     

    Therefore i would like to ask you if it is possible to specify a logoff at the end of this script to close the administrator session.

     

    i am a REST beginner and could not find this command in swagger.

     

    thanks in advance for your help and support

     

    regards

    Ugur

     

    • Tito Gamarra (Customer)

      I implemented this function on the code to revoke token, take in count that there are some variables that should be defined before

       

      1. function revoke-token($hostname, $bearer){
      2. try {
      3. $userAgent = [Microsoft.PowerShell.Commands.PSUserAgent]::Chrome
      4. #end the session by revoking the token
      5. $url = "https://$hostname/api/v1/token/revoke"
      6. $resp = Invoke-WebRequest -Uri $url -Body "token=$bearer" -Method Post -UserAgent $useragent -UseBasicParsing
      7. Write-Host "Signed Off"
      8. Write-Output "Signed Off"
      9. } catch {
      10. Write-Host Error signing off
      11. }
      12. }
      13.  
      14.  
      15. $bearer = $token.Values.values.split(" ")[1]
      16.  
      17.  
      18.  
      19. revoke-token -bearer $bearer -hostname $apiConfig.MoveItHost