Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

new-partition -disknumber variable problem

$
0
0

Hi,

When I use the New-Partition -DiskNumber $disknumber

i get an error which says the argument is invalid, however if i change it to be New-Partition -DiskNumber 3

the command succeeds. the variable is causing the error. however i have tried to explicitly set the variable to be int32

[int]$disknumber = Get-Disk | Where-Object {$_.BusType -eq "iSCSI" -and $_.Size -lt "5GB"} | Select -ExpandProperty Number

but this doesnt allow the command to succeed. I have also tried New-Partition -DiskNumber $disknumber.ToInt32() but it doesnt like this either.

can someone try and get a disk partitioned by using a variable instead of a hard coded number because I can't seem to get this to work?

Initialize-Disk -Number $disknumber

seems to work fine. my full code is as follows

[int]$disknumber = Get-Disk | Where-Object {$_.BusType -eq "iSCSI" -and $_.Size -lt "5GB"} | Select -ExpandProperty Number

        
        Initialize-Disk –Number $disknumber –PartitionStyle MBR –PassThru
        New-Partition -DiskNumber $disknumber -AssignDriveLetter –UseMaximumSize -DriveLetter Q
        Format-Volume -DriveLetter Q -NewFileSystemLabel "NewDisk" -Confirm:$false

any ideas much appreciated.


Viewing all articles
Browse latest Browse all 15028

Trending Articles