Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculation of free space for the VHDX file fails #160

Closed
matthias-schlimm opened this issue Dec 27, 2019 · 1 comment
Closed

Calculation of free space for the VHDX file fails #160

matthias-schlimm opened this issue Dec 27, 2019 · 1 comment

Comments

@matthias-schlimm
Copy link
Collaborator

@matthias-schlimm matthias-schlimm commented Dec 27, 2019

Calculation of free space for the VHDX file fails:

I suspect it is in line 402 in BISF.ps1:

IF (FreeSpace -le $ UsedSpace) {
A $ is missing from Freespace:
IF ($FreeSpace -le $ UsedSpace) {

However, the function Get-Space (BISF.psm1) only partially worked for me afterwards.
(The variable $ share was also used here, probably meant $ path).
Access to the network drive (for the PVS image) was not possible.
I was able to solve this with New-PSDrive / Remove-PSDrive.

After that I stumbled across the fact that a character string is returned and when comparing in BISF.ps1 the following effect occurs:

27.12.2019 11:33:52 | TST-SERVER$ | INFORMATION... | Check if there enough free Diskspace on the Custom UNC-Path available before proceed
27.12.2019 11:33:52 | TST-SERVER$ | INFORMATION... | Processing function Get-BISFSpace
27.12.2019 11:33:52 | TST-SERVER$ | INFORMATION... | Free space for \PVSSERVER\Image$ is 166,29 GB
27.12.2019 11:33:52 | TST-SERVER$ | INFORMATION... | Processing function Get-BISFSpace
27.12.2019 11:33:52 | TST-SERVER$ | INFORMATION... | Used space for C: is 18,22 GB
27.12.2019 11:33:52 | TST-SERVER$ | ERROR............... | STOP: There is NOT enough Free Space on the Custom UNC path to store the vDisk

I solved this by using the [math] :: Round () function to return a number and not a string.
(Of course, it would also be conceivable to convert to GB only on output)

IF ($path -eq $env:SystemDrive) {
            $localSpace = Get-WmiObject Win32_Volume -Filter 'DriveLetter="C:"'| select Capacity,FreeSpace

            IF ($FreeSpace) {
                  #$space = "{0:N2}" -f  (($localSpace.FreeSpace) / 1GB)
                  [int]$space = [math]::Round((($localSpace.FreeSpace) / 1GB))
                  Write-Log -Msg "Free space for $path is $space GB"
            } ELSE {
                  $usedspace = $localSpace.Capacity - $localSpace.FreeSpace
                  #$space = "{0:N2}" -f ($usedspace / 1GB)
                  [int]$space = [math]::Round(($usedspace / 1GB))
                  Write-Log -Msg "Used space for $path is $space GB"
            }
      } ELSE {
            IF ($FreeSpace) {
                  $FreeDrive =  ls function:[d-z]: -n | ?{ !(test-path $_) } | random
                  #$nwobj = new-object -comobject WScript.Network
                  # MN 2019-12-25 Changed $share to $path
                  #$status = $nwobj.mapnetworkdrive($FreeDrive,$share)
                  #$status = $nwobj.mapnetworkdrive($FreeDrive,$path)
                  $Driveletter = [string]$FreeDrive.Substring(0,1)
                  #$drive = get-psdrive $Driveletter
                  # Alternative: 
                  $drive = New-PSDrive -Name $Driveletter -Root $Path -Persist -PSProvider FileSystem
                  #$space = "{0:N2}" -f (($drive.free) / 1GB)
                  [int]$space = [math]::Round((($drive.free) / 1GB))
                  #$null = $nwobj.removenetworkdrive($FreeDrive)
                  # Alternative: 
                  $null = Remove-PSDrive -Name $Driveletter
                  Write-Log -Msg "Free space for $path is $space GB"
            } ELSE {
                  $objFSO = New-Object -com Scripting.FileSystemObject
                  #$space = "{0:N2}" -f (($objFSO.GetFolder($path).Size) / 1GB)
                  [int]$space = [math]::Round((($objFSO.GetFolder($path).Size) / 1GB))
                  Write-Log -Msg "Used space for $path is $space GB"
            }
      }
      return $space
@matthias-schlimm

This comment has been minimized.

Copy link
Collaborator Author

@matthias-schlimm matthias-schlimm commented Dec 27, 2019

codechange as described above, reference to #28

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.