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 Answer
0
Accepted Answer

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
answered 10 months ago
profile pictureAWS
EXPERT
reviewed 10 months ago
  • 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.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions