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).

AWS
已提問 9 個月前檢視次數 220 次
1 個回答
0
已接受的答案

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
已回答 9 個月前
profile pictureAWS
專家
已審閱 9 個月前
  • 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.

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南