Application Migration Service - Powershell Module - Returns only 50 records

0

I am trying to fetch the Source Servers with the powershell cmdlet get-mgnsourceserver, it is only fetching 50 records not more than that. Not sure if there is any limitation as such with the MGN Powershell module, Please let me know if there is any alternative to get all the source server list from the Application Migration Service (MGN).

1 réponse
0
Réponse acceptée

What is your use case. Could you please brief on the same. I am guessing that the powershell output is enabling pagination which is causing you to see only 50 records. Please check if you are getting a nexttoken in your reponse. Output Pagination with AWS Tools for PowerShell

I havent tested this code, let me know if this works:

# Get the account ID
$account_id = Get-Account

# Get the first page of results
$results = Get-MgnSourceServer -AccountId $account_id -MaxResults 100

# Loop through the results
while ($results.Count -gt 0) {

    # Get the current page of results
    foreach ($source_server in $results) {
        Write-Host $source_server
    }

    # Get the next page of results
    $results = Get-MgnSourceServer -AccountId $account_id -MaxResults 100 -NextToken $results.NextToken
}

You may try out some of the below steps if it works for you:

  1. In case of powershell, total number of items to return in the command's output could be controlled by using the parameter -MaxResult <Int32>
  2. If your command result returns more than the value defined for MaxResults, then you would need to use the parameter -NextToken to fetch the next set of records.
  3. You may also try the AWS CLI describe-source-servers with options like --no-paginate or --max-items
  4. You may try the AWS API documentation for DescribeSourceServers with request body maxResults or nextToken Let me know if this helps you.
AWS
Vijesh
répondu il y a 9 mois
profile pictureAWS
EXPERT
vérifié il y a 9 mois
  • Hi Vijesh, thanks for the suggestion. I have tried the -NextToken option, however it didn't work, it keep on fetch the same 50 records every time. Since there is no fix found for the Powershell module, I am going to continue with the AWS CLI, which is fetching all the source Servers. Thanks for suggesting the AWS CLI.

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions