General Discussion

powershell script

Lionl
463 Views

I am looking for a sample powershell script to login to the snapcenter server and run Get-SmBackup

1 ACCEPTED SOLUTION

PravinKumar
254 Views

Hi Lion liao,

 

Please find the sample script to connect to SnapCenter and run Get-SmBackup command:

 

# Define SnapCenter server and credentials
$SnapCenterServer = "https://snapcenter:8146" # Replace with your SnapCenter server address
$Username = "demo\administrator" # Replace with your username
$Password = ConvertTo-SecureString "password@123" -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential($Username, $Password)

# Connect to the SnapCenter server
Write-Host "Connecting to SnapCenter Server: $SnapCenterServer..."
Open-SmConnection -SMSbaseurl $SnapCenterServer -Credential $Credential

# Check if the connection was successful
if ($?) {
Write-Host "Connected to SnapCenter Server successfully."
# Get SnapCenter backups Write-Host "Fetching SnapCenter backups..."
$Backups = Get-SmBackup

# Output backup details
if ($Backups) {
$Backups
} else {
Write-Host "No backups found."
}
} else {
Write-Host "Failed to connect to SnapCenter Server."
}

 

Output from my lab:

 

Connecting to SnapCenter Server: https://snapcenter:8146...

Connected to SnapCenter Server successfully.
Fetching SnapCenter backups...

BackupId BackupName BackupTime BackupType
-------- ---------- ---------- ----------
1 RG1_SQL1_11-18-2024_02.38.40.9407 11/18/2024 2:39:01 AM Full Backup

 

Regards,

Pravin Kumar

View solution in original post

1 REPLY 1

PravinKumar
255 Views

Hi Lion liao,

 

Please find the sample script to connect to SnapCenter and run Get-SmBackup command:

 

# Define SnapCenter server and credentials
$SnapCenterServer = "https://snapcenter:8146" # Replace with your SnapCenter server address
$Username = "demo\administrator" # Replace with your username
$Password = ConvertTo-SecureString "password@123" -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential($Username, $Password)

# Connect to the SnapCenter server
Write-Host "Connecting to SnapCenter Server: $SnapCenterServer..."
Open-SmConnection -SMSbaseurl $SnapCenterServer -Credential $Credential

# Check if the connection was successful
if ($?) {
Write-Host "Connected to SnapCenter Server successfully."
# Get SnapCenter backups Write-Host "Fetching SnapCenter backups..."
$Backups = Get-SmBackup

# Output backup details
if ($Backups) {
$Backups
} else {
Write-Host "No backups found."
}
} else {
Write-Host "Failed to connect to SnapCenter Server."
}

 

Output from my lab:

 

Connecting to SnapCenter Server: https://snapcenter:8146...

Connected to SnapCenter Server successfully.
Fetching SnapCenter backups...

BackupId BackupName BackupTime BackupType
-------- ---------- ---------- ----------
1 RG1_SQL1_11-18-2024_02.38.40.9407 11/18/2024 2:39:01 AM Full Backup

 

Regards,

Pravin Kumar

Public