Friday, May 26, 2017

Diskpart and PowerShell – part 6: Multiple partitions on a disk

Diskpart and PowerShell – part 6: Multiple partitions on a disk

http://ift.tt/2r3THyD

So far we’ve looked at creating a single partition on a disk. This time we’ll look at how you can create multiple partitions on a disk. The are good reasons not to do this but its something I’ve seen done on a frequent basis.

Lets create a 20GB disk as an example and mount it

New-VHD -Path C:\test\Test1.vhdx -Dynamic -SizeBytes 20GB
Get-VHD -Path C:\test\Test1.vhdx | Mount-VHD

Initialise the disk

Initialize-Disk -Number 1

Now we can create some partitions

New-Partition -DiskNumber 1 -DriveLetter F -Size 5GB
New-Partition -DiskNumber 1 -DriveLetter G -Size 5GB
New-Partition -DiskNumber 1 -DriveLetter H -Size 5GB
New-Partition -DiskNumber 1 -DriveLetter I -Size 4.87GB

The reason that the last partition is only 4.87 G is that 128MB of disk space is reserved

PS> Get-Partition -DiskNumber 1 | Format-Table -AutoSize


   DiskPath: \\?\scsi#disk&ven_msft&prod_virtual_disk#2&1f4adffe&0&000003#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}

PartitionNumber DriveLetter Offset         Size Type
--------------- ----------- ------         ---- ----
1                           17408        128 MB Reserved
2               F           135266304      5 GB Basic
3               G           5503975424     5 GB Basic
4               H           10872684544    5 GB Basic
5               I           16241393664 4.87 GB Basic

You can format the 4 new volumes in one pass

Get-Partition -DiskNumber 1 | 
where Type -ne 'Reserved' | 
Format-Volume -FileSystem NTFS -Confirm:$false –Force

PS> Get-Partition -DiskNumber 1 | Get-Volume | select DriveLetter, FileSystem, Size

DriveLetter FileSystem       Size
----------- ----------       ----
          H NTFS       5368705024
          G NTFS       5368705024
          I NTFS       5229244416
          F NTFS       5368705024

The Storage module can be used to simply and easily create multiple volumes on a disk




Powershell

Powershell

via Richard Siddaway's Blog http://ift.tt/1JR1noE

May 26, 2017 at 12:54AM

Wednesday, April 26, 2017

DiskPart and PowerShell–part 1

DiskPart and PowerShell–part 1

http://ift.tt/2oxlxFy

An attendee at the Summit made the statement that the DiskPart utility didn’t have any equivalent in PowerShell. That’s not strictly true as the storage module provides a lot of functionality that maps to diskpart functionality.

The module contents include:

PS> Get-Command -Module Storage | select name

Name
----
Disable-PhysicalDiskIndication
Disable-StorageDiagnosticLog
Enable-PhysicalDiskIndication
Enable-StorageDiagnosticLog
Flush-Volume
Get-DiskSNV
Get-PhysicalDiskSNV
Get-StorageEnclosureSNV
Initialize-Volume
Write-FileSystemCache
Add-InitiatorIdToMaskingSet
Add-PartitionAccessPath
Add-PhysicalDisk
Add-TargetPortToMaskingSet
Add-VirtualDiskToMaskingSet
Block-FileShareAccess
Clear-Disk
Clear-FileStorageTier
Clear-StorageDiagnosticInfo
Connect-VirtualDisk
Debug-FileShare
Debug-StorageSubSystem
Debug-Volume
Disable-PhysicalDiskIdentification
Disable-StorageEnclosureIdentification
Disable-StorageHighAvailability
Disable-StorageMaintenanceMode
Disconnect-VirtualDisk
Dismount-DiskImage
Enable-PhysicalDiskIdentification
Enable-StorageEnclosureIdentification
Enable-StorageHighAvailability
Enable-StorageMaintenanceMode
Format-Volume
Get-DedupProperties
Get-Disk
Get-DiskImage
Get-DiskStorageNodeView
Get-FileIntegrity
Get-FileShare
Get-FileShareAccessControlEntry
Get-FileStorageTier
Get-InitiatorId
Get-InitiatorPort
Get-MaskingSet
Get-OffloadDataTransferSetting
Get-Partition
Get-PartitionSupportedSize
Get-PhysicalDisk
Get-PhysicalDiskStorageNodeView
Get-PhysicalExtent
Get-PhysicalExtentAssociation
Get-ResiliencySetting
Get-StorageAdvancedProperty
Get-StorageDiagnosticInfo
Get-StorageEnclosure
Get-StorageEnclosureStorageNodeView
Get-StorageEnclosureVendorData
Get-StorageFaultDomain
Get-StorageFileServer
Get-StorageFirmwareInformation
Get-StorageHealthAction
Get-StorageHealthReport
Get-StorageHealthSetting
Get-StorageJob
Get-StorageNode
Get-StoragePool
Get-StorageProvider
Get-StorageReliabilityCounter
Get-StorageSetting
Get-StorageSubSystem
Get-StorageTier
Get-StorageTierSupportedSize
Get-SupportedClusterSizes
Get-SupportedFileSystems
Get-TargetPort
Get-TargetPortal
Get-VirtualDisk
Get-VirtualDiskSupportedSize
Get-Volume
Get-VolumeCorruptionCount
Get-VolumeScrubPolicy
Grant-FileShareAccess
Hide-VirtualDisk
Initialize-Disk
Mount-DiskImage
New-FileShare
New-MaskingSet
New-Partition
New-StorageFileServer
New-StoragePool
New-StorageSubsystemVirtualDisk
New-StorageTier
New-VirtualDisk
New-VirtualDiskClone
New-VirtualDiskSnapshot
New-Volume
Optimize-StoragePool
Optimize-Volume
Register-StorageSubsystem
Remove-FileShare
Remove-InitiatorId
Remove-InitiatorIdFromMaskingSet
Remove-MaskingSet
Remove-Partition
Remove-PartitionAccessPath
Remove-PhysicalDisk
Remove-StorageFileServer
Remove-StorageHealthSetting
Remove-StoragePool
Remove-StorageTier
Remove-TargetPortFromMaskingSet
Remove-VirtualDisk
Remove-VirtualDiskFromMaskingSet
Rename-MaskingSet
Repair-FileIntegrity
Repair-VirtualDisk
Repair-Volume
Reset-PhysicalDisk
Reset-StorageReliabilityCounter
Resize-Partition
Resize-StorageTier
Resize-VirtualDisk
Revoke-FileShareAccess
Set-Disk
Set-FileIntegrity
Set-FileShare
Set-FileStorageTier
Set-InitiatorPort
Set-Partition
Set-PhysicalDisk
Set-ResiliencySetting
Set-StorageFileServer
Set-StorageHealthSetting
Set-StoragePool
Set-StorageProvider
Set-StorageSetting
Set-StorageSubSystem
Set-StorageTier
Set-VirtualDisk
Set-Volume
Set-VolumeScrubPolicy
Show-VirtualDisk
Start-StorageDiagnosticLog
Stop-StorageDiagnosticLog
Stop-StorageJob
Unblock-FileShareAccess
Unregister-StorageSubsystem
Update-Disk
Update-HostStorageCache
Update-StorageFirmware
Update-StoragePool
Update-StorageProviderCache
Write-VolumeCache

In this mini series I’m going to go through a number of the diskpart options and show you how to do the same with the Storage module cmdlets.

I’m not sure if all diskpart options are available but it’ll be fun to find out.

The Storage module was introduced with Windows 8/Server 2012.

ls $pshome\modules\storage

or

Get-ChildItem $pshome\modules\storage

if you prefer shows a number of cdxml files. This means that the cmdlets are based on CIM classes which you can see at

Get-CimClass -Namespace ROOT/Microsoft/Windows/Storage

These classes aren’t available on versions of Windows prior to Windows 8/Server 2012.

I’ll also have a look at some of these classes to see if there’s anything we can do that isn’t covered directly by the storage module cmdlets.



Powershell

Powershell

via Richard Siddaway's Blog http://ift.tt/1nN0D9u

April 26, 2017 at 05:57AM

AD_bulk_new_OU

AD_bulk_new_OU

http://ift.tt/2q8jF35

Active Directory, bulk create OU's with defined sub OU's

Powershell

Powershell

via PowerShell Script Repository http://poshcode.org/

April 25, 2017 at 09:02PM