Skip to content

Commit 0836515

Browse files
committed
Moved files. Added should support process
1 parent 2f7708a commit 0836515

3 files changed

Lines changed: 29 additions & 18 deletions

File tree

internal/functions/Convert-PSDCLocalUncPathToLocalPath.ps1 renamed to functions/Convert-PSDCLocalUncPathToLocalPath.ps1

File renamed without changes.

functions/Invoke-PSDCRepairClone.ps1

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
5858
#>
5959

60-
[CmdLetBinding()]
60+
[CmdLetBinding(SupportsShouldProcess = $true)]
6161

6262
param(
6363
[Parameter(Mandatory = $true)]
@@ -154,12 +154,14 @@
154154
Write-PSFMessage -Message "Mounting vhd $($result.CloneLocation)" -Level Verbose
155155

156156
# 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+
}
163165
}
164166
}
165167
catch {
@@ -174,14 +176,16 @@
174176
if ($result.DatabaseName -notin $databases.Name) {
175177

176178
# 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+
}
185189
}
186190

187191
# Setup the database filestructure
@@ -195,7 +199,14 @@
195199
Write-PSFMessage -Message "Mounting database from clone" -Level Verbose
196200

197201
# 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+
}
199210
}
200211
else {
201212
Write-PSFMessage -Message "Database $($result.Database) is already attached" -Level Verbose

tests/functions/New-PSDCVhdDisk.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Describe "$commandname Unit Tests" {
1616
}
1717

1818
Context "Create VHD with -FileName parameter" {
19-
$null = New-PSDCVhdDisk -Destination $destination -FileName "$name.vhdx"
19+
$null = New-PSDCVhdDisk -Destination $destination -FileName "$name.vhdx" -ErrorAction Ignore
2020

2121
It "Should be true" {
2222
(Test-Path -Path $path) | Should Be $true
@@ -26,7 +26,7 @@ Describe "$commandname Unit Tests" {
2626
}
2727

2828
Context "Create VHD with -Name parameter" {
29-
$null = New-PSDCVhdDisk -Destination $destination -Name $name
29+
$null = New-PSDCVhdDisk -Destination $destination -Name $name -ErrorAction Ignore
3030

3131
It "Should be true" {
3232
(Test-Path -Path $path) | Should Be $true

0 commit comments

Comments
 (0)