Note that there are some explanatory texts on larger screens.

plurals
  1. POConverting input variable to Uint64
    primarykey
    data
    text
    <p>I'm having issues scripting the creation of a new VHD (A tool for the creation of network optimised packages). The script below basically pulls the total size of the input directory and passes that as a variable to the $intval function, which converts the size in bytes to a string, $size (nGB).</p> <p>The problem I'm having is that the cmdlet NEW-VHD requires the -SizeBytes parameter to be in the format Uint64. If you enter the parameter manually, e.g.</p> <pre><code>NEW-VHD -path $vhdpath -fixed -SizeBytes 10GB </code></pre> <p>the cmdlet functions as intended and creates the VHD as it accepts the 10GB as a Uint64. What I need is the variable $size to be somehow converted to a Uint64 whilst retaining the trailing GB. Is there any way of imitating user input in this scenario?</p> <p>I understand the below script isn't optimised or the nicest looking as it is only a proof of concept. Any suggestions regarding the above issue would be welcomed!</p> <p><strong>Code</strong></p> <pre><code>$dir = Read-Host 'What is the directory you are wishing to store inside a VHD?' $objFSO = New-Object -com Scripting.FileSystemObject $intval = $objFSO.GetFolder($dir).Size / 1GB $size = "{0:N0}GB" -f $intval $vhd = Read-Host 'What volume name do you wish to call your VHD (no spaces)?' $vhdname = ($vhd + ".vhdx") $vhdpath = ("C:\VHD\" + $vhdname) NEW-VHD -fixed -path $vhdpath -SizeBytes $size </code></pre> <p>I've had a look at a few Microsoft resources but have come up empty</p> <p><strong>Modified Code</strong></p> <pre><code>$dir = Read-Host 'What is the directory you are wishing to store inside a VHD?' $objFSO = New-Object -com Scripting.FileSystemObject $intval = $objFSO.GetFolder($dir).Size $size = $intval / 1GB $vhd = Read-Host 'What volume name do you wish to call your VHD (no spaces)?' $vhdname = ($vhd + ".vhdx") $vhdpath = ("C:\VHD\" + $vhdname) NEW-VHD -fixed -path $vhdpath -SizeBytes $size </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload