Powershell parameter

Sara 401 Reputation points
2023-11-09T07:47:25.8+00:00

I have the following piece of code, where I am looking to add additional parameters for @sourcepath and $destinationapath with (prodbackupshare, corpbackupshare) as default values, and looking for some help on what would be the best way

    [CmdletBinding()]
    Param(
        [Parameter(Mandatory = $true)]
        [string]$SourceInstance,
        [Parameter(Mandatory = $true)]
        [string]$DestinationInstance,
        [Parameter(Mandatory = $true)]
        [string[]]$DatabaseNames
    )

    Begin {
        Import-AHModule SQL.Automation -ErrorAction Stop
        Import-Module dbatools -Verbose:$false -ErrorAction Stop

        foreach ($db in $DatabaseNames) {
            $SourcePath = "\\prodbackupshare\SQL_Backups\bckupShare\$db.bak"
            $DestinationPath = "\\corpbackupshare\SQL_Backups_7_Day\restoreshare"
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,169 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
1,537 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 42,826 Reputation points
    2023-11-09T16:24:21.3233333+00:00

    I think I understand what you're asking for. Does this help?

    [CmdletBinding()]
        Param(
            [Parameter(Mandatory = $true)]
            [string]$SourceInstance,
            [Parameter(Mandatory = $true)]
            [string]$DestinationInstance,
            [Parameter(Mandatory = $true)]
            [string[]]$DatabaseNames,
            $prod = "prodbackupshare",
            $corp = "corpbackupshare"
        )
    
        Begin {
            Import-AHModule SQL.Automation -ErrorAction Stop
            Import-Module dbatools -Verbose:$false -ErrorAction Stop
    
            foreach ($db in $DatabaseNames) {
                $SourcePath = "\\$prod\SQL_Backups\bckupShare\$db.bak"
                $DestinationPath = "\\$corp\SQL_Backups_7_Day\restoreshare"
    
    0 comments No comments

0 additional answers

Sort by: Most helpful