Powershell for managing Storage Replicas

Powershell to manage Storage Replicas

Get-Module -ListAvailable  : List available modules

Get-Module : List modules loaded

Get-Module  | ft Version,Name

Version    Name
-------    ----    Microsoft.PowerShell.Management    Microsoft.PowerShell.Utility
1.1        PSReadline
1.0        StorageReplica

Get-Command -Module StorageReplica | ft CommandType,Name

CommandType Name
----------- ----
Function    Clear-SRMetadata
Function    Export-SRConfiguration
Function    Get-SRDelegation
Function    Get-SRGroup
Function    Get-SRPartnership
Function    Grant-SRAccess
Function    Grant-SRDelegation
Function    New-SRGroup
Function    New-SRPartnership
Function    Remove-SRGroup
Function    Remove-SRPartnership
Function    Revoke-SRDelegation
Function    Set-SRGroup
Function    Set-SRPartnership
Function    Suspend-SRGroup
Function    Sync-SRGroup
Cmdlet      Test-SRTopology


Powershell and iSCSI

Powershell module notes:

Get-Module : List loaded modules

Get-Module –ListAvailable : List available modules

iSCSI target (Run on machine exporting disks)

Import-Module IscsiTarget



iSCSI (Run on machine importing disks)

Import-Module iSCSI





Get-Disk | Format-List -Property Path,Size,IsReadOnly

(get-wmiobject -namespace ROOT\WMI -class MSiSCSIInitiator_SessionClass).Devices | Where-Object {$_.LegacyName -ne $null} | Select-Object -Property LegacyName,DeviceInterfaceName -unique | Format-List

Disable Access to a iscsi target from a given machine

Import-Module IscsiTarget

Get-IscsiServerTarget | Format-List -Property TargetName,InitiatorIds

TargetName   : target1
InitiatorIds : {IPAddress:, IPAddress:, IPAddress:, IPAddress:}

TargetName   : target2
InitiatorIds : {IPAddress:, IPAddress:, IPAddress:, IPAddress:

Set-IscsiServerTarget -TargetName target2 -InitiatorId @(“IPAddress:″,”IPAddress:″,”IPAddress:”)

Immediately the iscsi session drops!


IIUG 2015 California Conference Pics

My  IIUG 2015 California Conference Pics (+ a few others) are at http://www.smooth1.co.uk/phone_pics/

The index.html was generated using http://www.smooth1.co.uk/powershell/htmldir.ps1

powershell script to register VMWare Workstation VMs

First realise that Powershell ISE in installed on windows 8 (and 8.1) by default!

Turn on Script Execution

Run powershell as administrator and run:

PS C:\Windows\system32> Get-ExecutionPolicy
PS C:\Windows\system32> Set-ExecutionPolicy RemoteSigned

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
http://go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is “Y”):
PS C:\Windows\system32> Get-ExecutionPolicy


Obtaining Help

Run Powershell Ise as Admin and enter


to get the help files

Adding vmrun.exe to path

Go to Control Panel – System – Advanced – Environment Variables

Edit System Variable Path and add

;C:\Program Files (x86)\VMware\VMware Workstation

to the end of the path

Powershell Script to register VM’s

Script which when passed a location for VMWare Workstation virtual machines registers each vm with the gui.by opening and closing it! http://www.smooth1.co.uk/powershell/vmreg.ps1