Erstellen mehrerer iSCSI Disks mit PowerShell / Creating several iSCSI Disk with PowerShell [Windows Server]

#Yet to be improved, but works

$SystemErrorActionPreference = $ErrorActionPreference;

$ErrorActionPreference = ‚Stop‘;

# if needed add this

#[PSCredential]$cred = Get-Credential -UserName Adatum\Administrator -Message ‚Supply an Administrator login, please.‘;

$iSCSI_TargetName= ‚lon-svr1‘;

$iSCSI_TargetInitiatorIds =@(‚IPAddress:172.16.0.22‘, ‚IPAddress:172.16.0.23‘)

$iSCSI_Target = New-IscsiServerTarget -TargetName $iSCSI_TargetName -InitiatorIds $iSCSI_TargetInitiatorIds;

foreach($num in 1..3)

{

   $iPath = ‚C:\iSCSIVirtualDisks\iSCSIDisk‘ + $num + ‚.vhdx‘;

   try

   {

       Get-ChildItem $iPath | Out-Null;

       Write-Host $iPath already exists;

   }

   catch [System.Management.Automation.ItemNotFoundException]

   {

       New-IscsiVirtualDisk -SizeBytes 5GB -Path $iPath | Add-IscsiVirtualDiskTargetMapping -TargetName $iSCSI_TargetName;

       Write-Host Created $iPath;

   }

}

$ErrorActionPreference = $SystemErrorActionPreference;