kreatd / transfer

0 stars 0 forks source link

M #1

Open kreatd opened 4 months ago

kreatd commented 4 months ago

Authenticate to Azure

Connect-AzAccount

Define your subscription ID, resource group name, and ASR vault name

$subscriptionId = "your-subscription-id" $resourceGroupName = "your-resource-group-name" $vaultName = "your-asr-vault-name"

Construct the URL for the API request to get protected items

$url = "https://management.azure.com/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.RecoveryServices/vaults/$vaultName/replicationProtectedItems?api-version=2022-03-01"

try {

Make the API request to get protected items

$protectedItemsResponse = Invoke-RestMethod -Uri $url -Method Get -Headers @{Authorization = "Bearer $((Get-AzAccessToken).Token)"}

# Process each protected item
foreach ($item in $protectedItemsResponse.value) {
    $properties = $item.properties

    # Extract VM disk protection status
    $vmDiskProtectionStatus = $properties.protectedManagedDisks

    # Extract VM name
    $vmName = $properties.friendlyName

    # Output or process the information as needed
    Write-Output "VM Name: $vmName"
    Write-Output "VM Disk Protection Status: $vmDiskProtectionStatus"
    Write-Output "-----------------------------"
}

} catch { Write-Error "Error occurred: $($_.Exception.Message)" }

kreatd commented 2 months ago

Authenticate

Connect-MgGraph -Scopes "Mail.Send"

Define email parameters

$emailParams = @{ Subject = "Test Email" Body = @{ Content = "This is a test email." ContentType = "Text" } ToRecipients = @( @{ EmailAddress = @{ Address = "recipient@example.com" } } ) }

Send email

Send-MgUserMessage -UserId "user@example.com" -Message $emailParams

kreatd commented 2 months ago

Define your parameters

$tenantId = "" $clientId = "" $clientSecret = "" $scope = "https://graph.microsoft.us/.default" # Government Cloud Graph API endpoint $authority = "https://login.microsoftonline.us/$tenantId/oauth2/v2.0/token"

Prepare the request body

$body = @{ grant_type = "client_credentials" client_id = $clientId client_secret = $clientSecret scope = $scope }

Get the access token

$response = Invoke-RestMethod -Method Post -Uri $authority -ContentType "application/x-www-form-urlencoded" -Body $body $accessToken = $response.access_token

Output the token (or use it for API calls)

$accessToken

kreatd commented 2 months ago

Define the email message payload

$emailBody = @{ message = @{ subject = "Test Email" body = @{ contentType = "Text" content = "This is a test email from the Azure Government Cloud." } toRecipients = @( @{ emailAddress = @{ address = "recipient@example.com" } } ) } }

Send the email using the access token

$response = Invoke-RestMethod -Method Post -Uri "https://graph.microsoft.us/v1.0/users//sendMail" -Headers @{Authorization = "Bearer $accessToken"} -Body ($emailBody | ConvertTo-Json -Depth 3) ` -ContentType "application/json"

Check the response

$response