|
117 | 117 | if (-not $PSDCSqlCredential) { |
118 | 118 | $pdcCredential = Get-PSFConfigValue -FullName psdatabaseclone.database.credential -Fallback $null |
119 | 119 | } |
120 | | - else{ |
| 120 | + else { |
121 | 121 | $pdcCredential = $PSDCSqlCredential |
122 | 122 | } |
123 | 123 |
|
|
258 | 258 | } |
259 | 259 |
|
260 | 260 | # Take apart the vhd directory |
261 | | - if (Test-Path -Path $ParentVhd) { |
262 | | - $parentVhdFileName = $ParentVhd.Split("\")[-1] |
263 | | - $parentVhdFile = $parentVhdFileName.Split(".")[0] |
| 261 | + if ($computer.IsLocalhost) { |
| 262 | + if (Test-Path -Path $ParentVhd) { |
| 263 | + $parentVhdFileName = $ParentVhd.Split("\")[-1] |
| 264 | + $parentVhdFile = $parentVhdFileName.Split(".")[0] |
| 265 | + } |
| 266 | + else { |
| 267 | + Stop-PSFFunction -Message "Parent vhd could not be found" -Target $SqlInstance -Continue |
| 268 | + } |
264 | 269 | } |
265 | 270 | else { |
266 | | - Stop-PSFFunction -Message "Parent vhd could not be found" -Target $SqlInstance -Continue |
| 271 | + $command = [scriptblock]::Create("Test-Path -Path $ParentVhd") |
| 272 | + $result = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential |
| 273 | + if ($result) { |
| 274 | + $parentVhdFileName = $ParentVhd.Split("\")[-1] |
| 275 | + $parentVhdFile = $parentVhdFileName.Split(".")[0] |
| 276 | + } |
| 277 | + else { |
| 278 | + Stop-PSFFunction -Message "Parent vhd could not be found" -Target $SqlInstance -Continue |
| 279 | + } |
267 | 280 | } |
268 | 281 |
|
| 282 | + |
269 | 283 | # Check clone name parameter |
270 | 284 | if (-not $CloneName) { |
271 | 285 | $cloneDatabase = $parentVhdFile |
|
360 | 374 | $null = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential |
361 | 375 |
|
362 | 376 | # Get the disk based on the name of the vhd |
363 | | - #$commandText = 'Get-Disk | Where-Object {$_.Location -eq' + " `"$Destination\$CloneName.vhdx`"}" |
364 | | - $commandText = "Get-Vhd -Path `"$Destination\$CloneName.vhdx`"" |
365 | | - $command = [ScriptBlock]::Create($commandText) |
| 377 | + $command = [ScriptBlock]::Create("Get-Vhd -Path `"$Destination\$CloneName.vhdx`"") |
366 | 378 | $disk = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential |
367 | 379 | } |
368 | 380 | } |
|
371 | 383 | } |
372 | 384 |
|
373 | 385 | # Check if the disk is offline |
374 | | - if ($disk.OperationalStatus -eq 'Offline') { |
| 386 | + #if ($disk.OperationalStatus -eq 'Offline') { |
375 | 387 | # Check if computer is local |
376 | 388 | if ($computer.IsLocalhost) { |
377 | | - $null = Initialize-Disk -Number $disk.DiskNumber -PartitionStyle GPT -ErrorAction SilentlyContinue |
| 389 | + $null = Initialize-Disk -Number $disk.Number -PartitionStyle GPT -ErrorAction SilentlyContinue |
378 | 390 | } |
379 | 391 | else { |
380 | | - $command = [ScriptBlock]::Create("Initialize-Disk -Number $($disk.DiskNumber) -PartitionStyle GPT -ErrorAction SilentlyContinue") |
| 392 | + $command = [ScriptBlock]::Create("Initialize-Disk -Number $($disk.Number) -PartitionStyle GPT -ErrorAction SilentlyContinue") |
| 393 | + |
381 | 394 | $null = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential |
382 | 395 | } |
383 | | - } |
| 396 | + # } |
384 | 397 |
|
385 | 398 | try { |
386 | 399 | # Check if computer is local |
|
396 | 409 | $partition = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential |
397 | 410 |
|
398 | 411 | $command = [ScriptBlock]::Create("Add-PartitionAccessPath -DiskNumber $($disk.Number) -PartitionNumber $($partition[1].PartitionNumber) -AccessPath $accessPath -ErrorAction Ignore") |
| 412 | + |
399 | 413 | $null = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential |
400 | 414 | } |
401 | 415 |
|
|
436 | 450 | # Write the data to the database |
437 | 451 | try { |
438 | 452 | # Get the data of the host |
439 | | - $computerinfo = [System.Net.Dns]::GetHostByName(($env:computerName)) |
| 453 | + if ($computer.IsLocalhost) { |
| 454 | + $computerinfo = [System.Net.Dns]::GetHostByName(($env:computerName)) |
| 455 | + |
| 456 | + $hostname = $computerinfo.HostName |
| 457 | + $ipAddress = $computerinfo.AddressList[0] |
| 458 | + $fqdn = $computerinfo.HostName |
| 459 | + } |
| 460 | + else { |
| 461 | + $command = [scriptblock]::Create('[System.Net.Dns]::GetHostByName(($env:computerName))') |
| 462 | + $computerinfo = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential |
| 463 | + |
| 464 | + $command = [scriptblock]::Create('$env:COMPUTERNAME') |
| 465 | + |
| 466 | + $hostname = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential |
| 467 | + $ipAddress = $computerinfo.AddressList[0] |
| 468 | + $fqdn = $computerinfo.HostName |
| 469 | + } |
440 | 470 |
|
441 | | - $hostname = $env:computerName |
442 | | - $ipAddress = $computerinfo.AddressList[0] |
443 | | - $fqdn = $computerinfo.HostName |
444 | 471 |
|
445 | 472 | # Setup the query to check of the host is already added |
446 | 473 | $query = " |
|
0 commit comments