I am really new to Powershell and hopefully someone can help me with this error. I have been given the below script that is supposed to take a list of SQL servers from a text file and lists out the availablity group and the replicas for each.
# Import the dbatools and sqlserver modules
Import-Module dbatools
Import-Module sqlserver
# Specify the path to the file containing the list of servers
$serverList = "C:\Path\To\ServerList.txt"
# Read the list of servers from the file
$servers = Get-Content $serverList
# Loop through each server and retrieve availability group information
foreach ($server in $servers) {
# Get the availability groups on the server
$groups = Get-DbaAvailabilityGroup -SqlInstance $server
# Loop through each availability group and retrieve replica information
foreach ($group in $groups) {
# Get the replicas in the availability group
$replicas = Get-DbaAvailabilityGroupReplica -AvailabilityGroupName $group.AvailabilityGroupName -SqlInstance $server
# Output the availability group and replica information
Write-Output "Availability Group: $($group.AvailabilityGroupName)"
Write-Output "Replicas:"
foreach ($replica in $replicas) {
Write-Output " - $($replica.ReplicaServerName) ($($replica.ReplicaRole))"
}
Write-Output ""
}
}
The error I am getting is on"Get-DbaAvailabilityGroupReplica : The term 'Get-DbaAvailabilityGroupReplica' is not recognized...". I have tried multiple times to reinstall the dbatools and sqlserver module but it does not resolve the issue.
get-command -module dbatools
does it show the function?Get-DbaAgReplica