|
57 | 57 |
|
58 | 58 | #> |
59 | 59 |
|
60 | | - [CmdLetBinding()] |
| 60 | + [CmdLetBinding(SupportsShouldProcess = $true)] |
61 | 61 |
|
62 | 62 | param( |
63 | 63 | [Parameter(Mandatory = $true)] |
|
154 | 154 | Write-PSFMessage -Message "Mounting vhd $($result.CloneLocation)" -Level Verbose |
155 | 155 |
|
156 | 156 | # Check if computer is local |
157 | | - if ($computer.IsLocalhost) { |
158 | | - $null = Mount-VHD -Path $result.CloneLocation -NoDriveLetter -ErrorAction SilentlyContinue |
159 | | - } |
160 | | - else { |
161 | | - $command = [ScriptBlock]::Create("Mount-VHD -Path $($result.CloneLocation) -NoDriveLetter -ErrorAction SilentlyContinue") |
162 | | - $null = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential |
| 157 | + if ($PSCmdlet.ShouldProcess($result.CloneLocation, "Mounting $($result.CloneLocation)")) { |
| 158 | + if ($computer.IsLocalhost) { |
| 159 | + $null = Mount-VHD -Path $result.CloneLocation -NoDriveLetter -ErrorAction SilentlyContinue |
| 160 | + } |
| 161 | + else { |
| 162 | + $command = [ScriptBlock]::Create("Mount-VHD -Path $($result.CloneLocation) -NoDriveLetter -ErrorAction SilentlyContinue") |
| 163 | + $null = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential |
| 164 | + } |
163 | 165 | } |
164 | 166 | } |
165 | 167 | catch { |
|
174 | 176 | if ($result.DatabaseName -notin $databases.Name) { |
175 | 177 |
|
176 | 178 | # Get all the files of the database |
177 | | - # Check if computer is local |
178 | | - if ($computer.IsLocalhost) { |
179 | | - $databaseFiles = Get-ChildItem -Path $result.AccessPath -Recurse | Where-Object {-not $_.PSIsContainer} |
180 | | - } |
181 | | - else { |
182 | | - $commandText = "Get-ChildItem -Path $($result.AccessPath) -Recurse | " + 'Where-Object {-not $_.PSIsContainer}' |
183 | | - $command = [ScriptBlock]::Create($commandText) |
184 | | - $databaseFiles = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential |
| 179 | + if ($PSCmdlet.ShouldProcess($result.AccessPath, "Retrieving database files from $($result.AccessPath)")) { |
| 180 | + # Check if computer is local |
| 181 | + if ($computer.IsLocalhost) { |
| 182 | + $databaseFiles = Get-ChildItem -Path $result.AccessPath -Recurse | Where-Object {-not $_.PSIsContainer} |
| 183 | + } |
| 184 | + else { |
| 185 | + $commandText = "Get-ChildItem -Path $($result.AccessPath) -Recurse | " + 'Where-Object {-not $_.PSIsContainer}' |
| 186 | + $command = [ScriptBlock]::Create($commandText) |
| 187 | + $databaseFiles = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential |
| 188 | + } |
185 | 189 | } |
186 | 190 |
|
187 | 191 | # Setup the database filestructure |
|
195 | 199 | Write-PSFMessage -Message "Mounting database from clone" -Level Verbose |
196 | 200 |
|
197 | 201 | # Mount the database using the config file |
198 | | - $null = Mount-DbaDatabase -SqlInstance $result.SQLInstance -Database $result.DatabaseName -FileStructure $dbFileStructure |
| 202 | + if ($PSCmdlet.ShouldProcess($result.DatabaseName, "Mounting database $($result.DatabaseName) to $($result.SQLInstance)")) { |
| 203 | + try { |
| 204 | + $null = Mount-DbaDatabase -SqlInstance $result.SQLInstance -Database $result.DatabaseName -FileStructure $dbFileStructure |
| 205 | + } |
| 206 | + catch { |
| 207 | + Stop-PSFFunction -Message "Couldn't mount database $($result.DatabaseName)" -Target $result.DatabaseName -Continue |
| 208 | + } |
| 209 | + } |
199 | 210 | } |
200 | 211 | else { |
201 | 212 | Write-PSFMessage -Message "Database $($result.Database) is already attached" -Level Verbose |
|
0 commit comments