From 542942e78a8e4fd2879e23023ad5521b4802262c Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sun, 3 Jun 2018 22:18:48 +0100 Subject: [PATCH 01/16] Added manifest --- .../DSR_iSCSIInitiator/DSR_iSCSIInitiator.psd1 | Bin 0 -> 8194 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/DSR_iSCSIInitiator.psd1 diff --git a/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/DSR_iSCSIInitiator.psd1 b/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/DSR_iSCSIInitiator.psd1 new file mode 100644 index 0000000000000000000000000000000000000000..ff44fcf09e30bcf591a2cab331450c3ea8e0fe18 GIT binary patch literal 8194 zcmeI1Yi}Dx6o%(B692&>NKO$=n>H;J38_)iw2^vKofJMGA;*_sn%Ks6n^vfQ9eAHP zKA9cwZeoW<@S$3*_cn9pJ@<3QfB&@>z6@W4wa^I9!YFjZ+i((kdO8j5Fbspx*V8o2 z^ro-xllY}Lt{HYiE4&K7YHTa)=-k)A%$d%%ewo#rui|Sx7S*B7NgUDBx{YuYK7=21 zeJKR(a4aOf@Fctlw?uO!JU#s~=T6vKf*NC?c01e^h1=o2e(&hI8NM&f2G7IrXME$> zTA?FcgD{R8k?zZ&ywkY$i8@`i`-W2^!9X(lTH$2dlu(jU_-%wbWLz2^YF8=Xrm(`&tz0o-eXZkI# zKGwQ;=CL>@A`zF+eJ@f$KPgJpYX}UBluRb;@~0c3;c;TQShS%T+p?4sT@yO|dLm@l z)+8XMt}H(1X*YgPKI~qX^oeZx(IPwI&c3&`65fDijzxPU>Sm!HMf2E_+h^UHCIS08 zh{&PV(mE#LhGIM3M|>kTTjX}c#_1@&?})2h4=JAz*NfURPE+Q<*A{a}LkO@ixFY64 z0Zn&m@#Io|Hm7+ibf=n!E+*28W6!1iQyh&wpJ@yhz#TJMvN|FHddB9D<4Aaed*Vfs z8@cQvEmTphj+ggjHH+S#{N^gyi5iyCSI50pBatU_nhBZN)AeiOI=QLV$W?g42Jv$w zkIt~)jqqHV?Lc>X`eKprOkXF8fvegSG3emDo**hfKBn;;Uu;KAmJ8H__l!ht(}qka*}@ zU5OXSle|t0wT!c_c=l9vEAc)_io46A=>JdF#>p}=eJNh4NYN&iNIg$X?L^zbM#wWn zcVxCM{UOg@_*PFpt0uW0@3tkwuI{(4AU(H_GLr3D9M!QT2kvS_)#!_T3K7RTBsf@C#Gn(|jFyyi zh)pK1wW`2$%-fE5BM%efno$zu<4>)z6w8YEr;4*9MaiNc)oJZO5pf*(sOI^-^m#Jp zoX*4SHP_u)jLY<5tJ|8dzY6BPXy0`Ic+h`?yNF>G?2Eos_EDl8c1KJjMwow)HN3~? zYhG0qztVG{QF?l0WApL+hH^={U%!=g?`6yJs6d`{Jd0dZ`_x{{XQ?Z&cz_l4!u#`h zhX%1!>R!Cd_Zt$wM0T$Mus@5O@Hm;jx1Atz24ks=kssOJd*_BKWPG|CJ#(TfXuN9A zXAqO{T&qVs{#tjtvr--mhf`<*$O+P=i%>}HH;O`%_J3uIb|?=26-A|J2Ba^msLpl?lcz4ZfQrIob^TY zI@LSUDMR=Q#k`bOtIkg8dyb}9Ph1_zUd%Q<^>5@ec&NxT9qTmUN_1|uW81CP#s6Dv}LX17-6l>nnej! z*D)?ve3u%)_UhQHNcNrU6)EBG?4MFWSWQ7CXS*55A4;3J97Ve|;!Z%_HuXZZDEY*?*X zCp)7@Lg@QTWt8-uqwu@NQHj+{&N?a|_wR60dD1W04zcA3aF}h_F3?52dOgbhIn7n@ zkrAkPEf2DzLNp@kq&}lum)GgDo*EX{EL5ki%a3}GJ|9Uc#Cuyc_seojVSUcJ*~Q43 zqCh Date: Sun, 3 Jun 2018 22:20:51 +0100 Subject: [PATCH 02/16] moved public functions nto own ps1 to simplify code dot sourced these funtions so module is ware of them removed export-modulemeber as manifest is performing this duty --- .../DSR_iSCSIInitiator.psm1 | 1135 +---------------- 1 file changed, 3 insertions(+), 1132 deletions(-) diff --git a/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/DSR_iSCSIInitiator.psm1 b/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/DSR_iSCSIInitiator.psm1 index 6c54ec2..5d8fb94 100644 --- a/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/DSR_iSCSIInitiator.psm1 +++ b/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/DSR_iSCSIInitiator.psm1 @@ -1,3 +1,6 @@ +# Dot Source DSC Resource Files +Get-ChildItem -Path (Join-Path (Join-Path $PSScriptRoot "Public") "*.ps1") | ForEach-Object { . $_.FullName } + $modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules' # Import the Networking Resource Helper Module @@ -10,1136 +13,6 @@ $LocalizedData = Get-LocalizedData ` -ResourceName 'DSR_iSCSIInitiator' ` -ResourcePath (Split-Path -Parent $Script:MyInvocation.MyCommand.Path) -<# - .SYNOPSIS - Returns the current state of the specified iSCSI Initiator. - - .PARAMETER NodeAddress - Represents the IQN of the discovered target. - - .PARAMETER TargetPortalAddress - Represents the IP address or DNS name of the target portal. - - .PARAMETER Ensure - Ensures that Target is Absent or Present. - - .PARAMETER InitiatorPortalAddress - Specifies the IP address associated with the portal. -#> -function Get-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param - ( - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [System.String] - $NodeAddress, - - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [System.String] - $TargetPortalAddress, - - [Parameter()] - [ValidateSet('Present', 'Absent')] - [System.String] - $Ensure = 'Present', - - [Parameter()] - [System.String] - $InitiatorPortalAddress - ) - - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.GettingiSCSIInitiatorMessage) ` - -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress - ) -join '' ) - - $returnValue = @{ - NodeAddress = $NodeAddress - TargetPortalAddress = $TargetPortalAddress - InitiatorPortalAddress = $InitiatorPortalAddress - Ensure = 'Absent' - } - - # Lookup the Target Portal - $targetPortal = Get-TargetPortal ` - -TargetPortalAddress $TargetPortalAddress ` - -InitiatorPortalAddress $InitiatorPortalAddress - - if ($targetPortal) - { - $returnValue.TargetPortalAddress = $targetPortal.TargetPortalAddress - $returnValue.InitiatorPortalAddress = $targetPortal.InitiatorPortalAddress - $returnValue.TargetPortalPortNumber = $targetPortal.TargetPortalPortNumber - $returnValue.InitiatorInstanceName = $targetPortal.InitiatorInstanceName - $returnValue.IsDataDigest = $targetPortal.IsDataDigest - $returnValue.IsHeaderDigest = $targetPortal.IsHeaderDigest - - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSITargetPortalExistsMessage) ` - -f $TargetPortalAddress, $InitiatorPortalAddress - ) -join '' ) - } - else - { - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSITargetPortalDoesNotExistMessage) ` - -f $TargetPortalAddress, $InitiatorPortalAddress - ) -join '' ) - } # if - - # Lookup the Target - $target = Get-Target ` - -NodeAddress $NodeAddress - - if ($target) - { - $returnValue.NodeAddress = $target.NodeAddress - $returnValue.IsConnected = $target.IsConnected - - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSITargetExistsMessage) ` - -f $NodeAddress - ) -join '' ) - } - else - { - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSITargetDoesNotExistMessage) ` - -f $NodeAddress - ) -join '' ) - } # if - - # The rest of the properties can only be populated if the Target is connected. - if ($target.IsConnected) - { - # Lookup the Connection - $connection = Get-Connection ` - -Target $Target - - $returnValue.Ensure = 'Present' - - if ($connection) - { - $returnValue.TargetPortalAddress = $connection.TargetAddress - $returnValue.InitiatorPortalAddress = $connection.InitiatorAddress - $returnValue.TargetPortalPortNumber = $connection.TargetPortNumber - $returnValue.ConnectionIdentifier = $connection.ConnectionIdentifier - - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSIConnectionExistsMessage) ` - -f $NodeAddress - ) -join '' ) - } - else - { - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSIConnectionDoesNotExistMessage) ` - -f $NodeAddress - ) -join '' ) - } # if - - # Lookup the Session - $session = Get-Session ` - -Target $target - - if ($session) - { - $returnValue.AuthenticationType = $session.AuthenticationType - $returnValue.InitiatorInstanceName = $session.InitiatorInstanceName - $returnValue.InitiatorPortalAddress = $session.InitiatorPortalAddress - $returnValue.IsConnected = $session.IsConnected - $returnValue.IsDataDigest = $session.IsDataDigest - $returnValue.IsDiscovered = $session.IsDiscovered - $returnValue.IsHeaderDigest = $session.IsHeaderDigest - $returnValue.IsPersistent = $session.IsPersistent - $returnValue.SessionIdentifier = $session.SessionIdentifier - - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSISessionExistsMessage) ` - -f $NodeAddress - ) -join '' ) - } - else - { - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSISessionDoesNotExistMessage) ` - -f $NodeAddress - ) -join '' ) - } # if - } # if - - # Get the iSNS Server - $iSNSServerCurrent = Get-WmiObject ` - -Class MSiSCSIInitiator_iSNSServerClass ` - -Namespace root\wmi - if ($iSNSServerCurrent) - { - $returnValue += @{ - iSNSServer = $iSNSServerCurrent.iSNSServerAddress - } - } - - $returnValue -} # Get-TargetResource - -<# - .SYNOPSIS - Creates, updates or removes an iSCSI Initiator. - - .PARAMETER NodeAddress - Represents the IQN of the discovered target. - - .PARAMETER TargetPortalAddress - Represents the IP address or DNS name of the target portal. - - .PARAMETER Ensure - Ensures that Target is Absent or Present. - - .PARAMETER InitiatorPortalAddress - Specifies the IP address associated with the portal. - - .PARAMETER TargetPortalPortNumber - Specifies the TCP/IP port number for the target portal. - - .PARAMETER InitiatorInstanceName - The name of the initiator instance that the iSCSI initiator service uses to send SendTargets - requests to the target portal. If no instance name is specified, the iSCSI initiator service - chooses the initiator instance. - - .PARAMETER AuthenticationType - Specifies the type of authentication to use when logging into the target. - - .PARAMETER ChapUsername - Specifies the user name to use when establishing a connection authenticated by using Mutual - CHAP. - - .PARAMETER ChapSecret - Specifies the CHAP secret to use when establishing a connection authenticated by using CHAP. - - .PARAMETER IsDataDigest - Enables data digest when the initiator logs into the target portal. - - .PARAMETER IsHeaderDigest - Enables header digest when the initiator logs into the target portal. By not specifying this - parameter, the digest setting is determined by the initiator kernel mode driver. - - .PARAMETER IsMultipathEnabled - Indicates that the initiator has enabled Multipath I/O (MPIO) and it will be used when logging - into the target portal. - - .PARAMETER IsPersistent - Specifies that the session is to be automatically connected after each restart. - - .PARAMETER ReportToPnP - Specifies that the operation is reported to PNP. - - .PARAMETER iSNSServer - Specifies an iSNS Server to register this Initiator with. -#> -function Set-TargetResource -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [System.String] - $NodeAddress, - - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [System.String] - $TargetPortalAddress, - - [Parameter()] - [ValidateSet('Present', 'Absent')] - [System.String] - $Ensure = 'Present', - - [Parameter()] - [System.String] - $InitiatorPortalAddress, - - [Parameter()] - [System.Uint16] - $TargetPortalPortNumber, - - [Parameter()] - [System.String] - $InitiatorInstanceName, - - [Parameter()] - [ValidateSet('None', 'OneWayCHAP', 'MutualCHAP')] - [System.String] - $AuthenticationType, - - [Parameter()] - [System.String] - $ChapUsername, - - [Parameter()] - [System.String] - $ChapSecret, - - [Parameter()] - [System.Boolean] - $IsDataDigest, - - [Parameter()] - [System.Boolean] - $IsHeaderDigest, - - [Parameter()] - [System.Boolean] - $IsMultipathEnabled, - - [Parameter()] - [System.Boolean] - $IsPersistent, - - [Parameter()] - [System.Boolean] - $ReportToPNP, - - [Parameter()] - [System.String] - $iSNSServer - ) - - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.SettingiSCSIInitiatorMessage) ` - -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress - ) -join '' ) - - # Remove any parameters that can't be splatted. - $null = $PSBoundParameters.Remove('Ensure') - - $targetSplat = @{ TargetPortalAddress = $TargetPortalAddress } - if ($PSBoundParameters.ContainsKey('InitiatorPortalAddress')) - { - $targetSplat += @{ InitiatorPortalAddress = $InitiatorPortalAddress } - } - - # Lookup the existing iSCSI Target Portal - $targetPortal = Get-TargetPortal @TargetSplat - - # Get the iSNS Server - $iSNSServerCurrent = Get-WmiObject ` - -Class MSiSCSIInitiator_iSNSServerClass ` - -Namespace root\wmi - - $returnValue += @{ - iSNSServer = $iSNSServerCurrent.iSNSServerAddress - } - - if ($Ensure -eq 'Present') - { - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.EnsureiSCSITargetPortalExistsMessage) ` - -f $TargetPortalAddress, $InitiatorPortalAddress - ) -join '' ) - - [Boolean] $create = $false - - if ($targetPortal) - { - # The iSCSI Target Portal exists - check the parameters - if (($TargetPortalPortNumber) ` - -and ($targetPortal.TargetPortalPortNumber -ne $TargetPortalPortNumber)) - { - $create = $true - } # if - if (($InitiatorInstanceName) ` - -and ($targetPortal.InitiatorInstanceName -ne $InitiatorInstanceName)) - { - $create = $true - } # if - if (($null -ne $IsDataDigest) ` - -and ($targetPortal.IsDataDigest -ne $IsDataDigest)) - { - $create = $true - } # if - if (($null -ne $IsHeaderDigest) ` - -and ($targetPortal.IsHeaderDigest -ne $IsHeaderDigest)) - { - $create = $true - } # if - - if ($create) - { - # The Target Portal exists but has different parameters - # so it has to be removed and recreated - Remove-iSCSITargetPortal @TargetSplat -ErrorAction Stop - - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSITargetPortalRemovedForRecreateMessage) ` - -f $TargetPortalAddress, $InitiatorPortalAddress - ) -join '' ) - } # if - } - else - { - $create = $true - } # if - - if ($create) - { - # Create the iSCSI Target Portal using a splat - [PSObject] $splat = [PSObject]@{} + $PSBoundParameters - $splat.Remove('NodeAddress') - $splat.Remove('IsMultipathEnabled') - $splat.Remove('IsPersistent') - $splat.Remove('ReportToPNP') - $splat.Remove('iSNSServer') - New-iSCSITargetPortal ` - @splat ` - -ErrorAction Stop - - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSITargetPortalCreatedMessage) ` - -f $TargetPortalAddress, $InitiatorPortalAddress - ) -join '' ) - } - - # Lookup the Target - $target = Get-Target ` - -NodeAddress $NodeAddress - - # Check the Target is connected - [Boolean] $connect = $false - - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.EnsureiSCSITargetIsConnectedMessage) ` - -f $NodeAddress - ) -join '' ) - - if ($target) - { - # Lookup the Connection - $connection = Get-Connection ` - -Target $target - - # Lookup the Session - $session = Get-Session ` - -Target $target - - if ($connection -and $session) - { - # Check that the session and connection parameters are correct - - # The Connection.TargetAddress will always be an IP Address - # even if the TargetPortalAddress was specified as a Hostname - try - { - $targetPortalIP = @( - ([System.Net.IPAddress]$TargetPortalAddress).IPAddressToString - ) - } - catch - { - # This is a TargetPortalAddress is a Hostname so resolve it to IP addresses - $targetPortalIP = @( - (Resolve-DNSName -Name $TargetPortalAddress -Type A).IPAddress - ) - } # try - - if ($connection.TargetAddress -notin $targetPortalIP) - { - $connect = $true - } # if - if ($connection.InitiatorAddress -ne $InitiatorPortalAddress) - { - $connect = $true - } # if - if (($TargetPortalPortNumber) ` - -and ($connection.TargetPortNumber -ne $TargetPortalPortNumber)) - { - $connect = $true - } # if - if (($AuthenticationType) ` - -and ($session.AuthenticationType -ne $AuthenticationType)) - { - $connect = $true - } # if - if (($InitiatorInstanceName) ` - -and ($session.InitiatorInstanceName -ne $InitiatorInstanceName)) - { - $connect = $true - } # if - if ($PSBoundParameters.ContainsKey('InitiatorPortalAddress') ` - -and ($session.InitiatorPortalAddress -ne $InitiatorPortalAddress)) - { - $connect = $true - } # if - if (($null -ne $IsDataDigest) ` - -and ($session.IsDataDigest -ne $IsDataDigest)) - { - $connect = $true - } # if - if (($null -ne $IsHeaderDigest) ` - -and ($session.IsHeaderDigest -ne $IsHeaderDigest)) - { - $connect = $true - } # if - - if ($connect) - { - # The Target/Session/Connection has different parameters - # So disconnect everything so it can be reconnected - Disconnect-IscsiTarget ` - -NodeAddress $NodeAddress ` - -Confirm:$False ` - -ErrorAction Stop - - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSITargetDisconnectedMessage) ` - -f $NodeAddress - ) -join '' ) - - } # if - } - else - { - # Either the session or connection doesn't exist - # so reconnect or the target is not connected - $connect = $true - } # if - } - else - { - $connect = $true - } # if - - if ($connect) - { - [PSObject] $splat = [PSObject]@{} + $PSBoundParameters - $splat.Remove('IsMultipathEnabled') - $splat.Remove('iSNSServer') - - $Session = Connect-IscsiTarget ` - @splat ` - -ErrorAction Stop - - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSITargetConnectedMessage) ` - -f $NodeAddress - ) -join '' ) - } # if - - if (($PSBoundParameters.ContainsKey('IsPersistent')) ` - -and ($IsPersistent -ne $session.IsPersistent)) - { - if ($IsPersistent -eq $true) - { - # Ensure session is persistent - $session | Register-IscsiSession ` - -IsMultipathEnabled $IsMultipathEnabled ` - -ErrorAction Stop - - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSISessionSetPersistentMessage) ` - -f $NodeAddress - ) -join '' ) - } - else - { - # Ensure session is not persistent - $session | Unregister-IscsiSession ` - -ErrorAction Stop - - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSISessionRemovedPersistentMessage) ` - -f $NodeAddress - ) -join '' ) - } - } - - # Check the iSNS Server setting - if ($PSBoundParameters.ContainsKey('iSNSServer')) - { - if ([String]::IsNullOrEmpty($iSNSServer)) - { - if ($iSNSServerCurrent) - { - # The iSNS Server is set but should not be - remove it - Remove-WmiObject ` - -Path $iSNSServerCurrent.Path ` - -ErrorAction Stop - - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSNSServerRemovedMessage) - ) -join '' ) - } # if - } - else - { - try - { - Set-WmiInstance ` - -Namespace root\wmi ` - -Class WT_iSNSServer ` - -Arguments @{ServerName = $iSNSServer} ` - -ErrorAction Stop - - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSNSServerUpdatedMessage) ` - -f $iSNSServer - ) -join '' ) - } - catch - { - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSNSServerUpdateErrorMessage) ` - -f $iSNSServer - ) -join '' ) - } - } # if - } # if - } - else - { - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.EnsureiSCSITargetIsDisconnectedMessage) ` - -f $NodeAddress - ) -join '' ) - - # Lookup the Target - $target = Get-Target ` - -NodeAddress $NodeAddress - - if ($target) - { - if ($target.IsConnected) - { - Disconnect-IscsiTarget ` - -NodeAddress $NodeAddress ` - -Confirm:$false ` - -ErrorAction Stop - - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSITargetDisconnectedMessage) ` - -f $NodeAddress - ) -join '' ) - } - } - - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.EnsureiSCSITargetPortalDoesNotExistMessage) ` - -f $TargetPortalAddress, $InitiatorPortalAddress - ) -join '' ) - - if ($targetPortal) - { - # The iSCSI Target Portal shouldn't exist - remove it - Remove-iSCSITargetPortal ` - @TargetSplat ` - -Confirm:$False ` - -ErrorAction Stop - - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSITargetPortalRemovedMessage) ` - -f $TargetPortalAddress, $InitiatorPortalAddress - ) -join '' ) - } # if - - if ($iSNSServerCurrent) - { - # The iSNS Server is set but should not be - remove it - Remove-WmiObject ` - -Path $iSNSServerCurrent.Path ` - -ErrorAction Stop - - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSIServerTargetiSNSRemovedMessage) ` - -f $TargetName - ) -join '' ) - } # if - } # if -} # Set-TargetResource - -<# - .SYNOPSIS - Tests if an iSCSI Initiator needs to be created, updated or removed. - .PARAMETER NodeAddress - Represents the IQN of the discovered target. - - .PARAMETER TargetPortalAddress - Represents the IP address or DNS name of the target portal. - - .PARAMETER Ensure - Ensures that Target is Absent or Present. - - .PARAMETER InitiatorPortalAddress - Specifies the IP address associated with the portal. - - .PARAMETER TargetPortalPortNumber - Specifies the TCP/IP port number for the target portal. - - .PARAMETER InitiatorInstanceName - The name of the initiator instance that the iSCSI initiator service uses to send SendTargets - requests to the target portal. If no instance name is specified, the iSCSI initiator service - chooses the initiator instance. - - .PARAMETER AuthenticationType - Specifies the type of authentication to use when logging into the target. - - .PARAMETER ChapUsername - Specifies the user name to use when establishing a connection authenticated by using Mutual - CHAP. - - .PARAMETER ChapSecret - Specifies the CHAP secret to use when establishing a connection authenticated by using CHAP. - - .PARAMETER IsDataDigest - Enables data digest when the initiator logs into the target portal. - - .PARAMETER IsHeaderDigest - Enables header digest when the initiator logs into the target portal. By not specifying this - parameter, the digest setting is determined by the initiator kernel mode driver. - - .PARAMETER IsMultipathEnabled - Indicates that the initiator has enabled Multipath I/O (MPIO) and it will be used when logging - into the target portal. - - .PARAMETER IsPersistent - Specifies that the session is to be automatically connected after each restart. - - .PARAMETER ReportToPnP - Specifies that the operation is reported to PNP. - - .PARAMETER iSNSServer - Specifies an iSNS Server to register this Initiator with. -#> -function Test-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Boolean])] - param - ( - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [System.String] - $NodeAddress, - - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [System.String] - $TargetPortalAddress, - - [Parameter()] - [ValidateSet('Present', 'Absent')] - [System.String] - $Ensure = 'Present', - - [Parameter()] - [System.String] - $InitiatorPortalAddress, - - [Parameter()] - [System.Uint16] - $TargetPortalPortNumber, - - [Parameter()] - [System.String] - $InitiatorInstanceName, - - [Parameter()] - [ValidateSet('None', 'OneWayCHAP', 'MutualCHAP')] - [System.String] - $AuthenticationType, - - [Parameter()] - [System.String] - $ChapUsername, - - [Parameter()] - [System.String] - $ChapSecret, - - [Parameter()] - [System.Boolean] - $IsDataDigest, - - [Parameter()] - [System.Boolean] - $IsHeaderDigest, - - [Parameter()] - [System.Boolean] - $IsMultipathEnabled, - - [Parameter()] - [System.Boolean] - $IsPersistent, - - [Parameter()] - [System.Boolean] - $ReportToPNP, - - [Parameter()] - [System.String] - $iSNSServer - ) - - # Flag to signal whether settings are correct - [Boolean] $desiredConfigurationMatch = $true - - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.TestingiSCSIInitiatorMessage) ` - -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress - ) -join '' ) - - $targetSplat = @{ TargetPortalAddress = $TargetPortalAddress } - if ($PSBoundParameters.ContainsKey('InitiatorPortalAddress')) - { - $targetSplat += @{ InitiatorPortalAddress = $InitiatorPortalAddress } - } - - # Lookup the existing iSCSI Target Portal - $targetPortal = Get-TargetPortal @TargetSplat - - # Get the iSNS Server - $iSNSServerCurrent = Get-WmiObject ` - -Class MSiSCSIInitiator_iSNSServerClass ` - -Namespace root\wmi - - $returnValue += @{ - iSNSServer = $iSNSServerCurrent.iSNSServerAddress - } - - if ($Ensure -eq 'Present') - { - # The iSCSI Target Portal should exist - if ($targetPortal) - { - # The iSCSI Target Portal exists already - check the parameters - if (($TargetPortalPortNumber) ` - -and ($targetPortal.TargetPortalPortNumber -ne $TargetPortalPortNumber)) - { - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSIInitiatorParameterNeedsUpdateMessage) ` - -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress, 'TargetPortal', 'TargetPortalPortNumber' - ) -join '' ) - $desiredConfigurationMatch = $false - } # if - - if (($InitiatorInstanceName) ` - -and ($targetPortal.InitiatorInstanceName -ne $InitiatorInstanceName)) - { - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSIInitiatorParameterNeedsUpdateMessage) ` - -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress, 'TargetPortal', 'InitiatorInstanceName' - ) -join '' ) - $desiredConfigurationMatch = $false - } # if - - if (($null -ne $IsDataDigest) ` - -and ($targetPortal.IsDataDigest -ne $IsDataDigest)) - { - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSIInitiatorParameterNeedsUpdateMessage) ` - -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress, 'TargetPortal', 'IsDataDigest' - ) -join '' ) - $desiredConfigurationMatch = $false - } # if - - if (($null -ne $IsHeaderDigest) ` - -and ($targetPortal.IsHeaderDigest -ne $IsHeaderDigest)) - { - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSIInitiatorParameterNeedsUpdateMessage) ` - -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress, 'TargetPortal', 'IsHeaderDigest' - ) -join '' ) - $desiredConfigurationMatch = $false - } # if - - # Lookup the Target - $target = Get-Target ` - -NodeAddress $NodeAddress - - if (! $target) - { - # Ths iSCSI Target doesn't exist but should - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSITargetDoesNotExistButShouldMessage) ` - -f $NodeAddress - ) -join '' ) - $desiredConfigurationMatch = $false - return $desiredConfigurationMatch - } # if - - if (-not $target.IsConnected) - { - # Ths iSCSI Target exists but is not connected - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSITargetNotConnectedMessage) ` - -f $NodeAddress - ) -join '' ) - $desiredConfigurationMatch = $false - return $desiredConfigurationMatch - } # if - - # Lookup the Connection - $connection = Get-Connection ` - -Target $target - - if (-not $connection) - { - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSIConnectionDoesNotExistButShouldMessage) ` - -f $NodeAddress - ) -join '' ) - $desiredConfigurationMatch = $false - return $desiredConfigurationMatch - } # if - - <# - Check the Connection parameters are correct - The Connection.TargetAddress will always be an IP Address - even if the TargetPortalAddress was specified as a Hostname - #> - try - { - $targetPortalIP = @( - ([System.Net.IPAddress]$TargetPortalAddress).IPAddressToString - ) - } - catch - { - # This is a TargetPortalAddress is a Hostname so resolve it to IP addresses - $targetPortalIP = @( - (Resolve-DNSName -Name $TargetPortalAddress -Type A).IPAddress - ) - } # try - - if ($connection.TargetAddress -notin $targetPortalIP) - { - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSIInitiatorParameterNeedsUpdateMessage) ` - -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress, 'Connection', 'TargetAddress' - ) -join '' ) - $desiredConfigurationMatch = $false - } - - if ($PSBoundParameters.ContainsKey('InitiatorPortalAddress') ` - -and ($connection.InitiatorAddress -ne $InitiatorPortalAddress)) - { - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSIInitiatorParameterNeedsUpdateMessage) ` - -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress, 'Connection', 'InitiatorAddress' - ) -join '' ) - $desiredConfigurationMatch = $false - } # if - - if (($TargetPortalPortNumber) ` - -and ($connection.TargetPortNumber -ne $TargetPortalPortNumber)) - { - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSIInitiatorParameterNeedsUpdateMessage) ` - -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress, 'Connection', 'TargetPortNumber' - ) -join '' ) - $desiredConfigurationMatch = $false - } # if - - # Lookup the Session - $session = Get-Session ` - -Target $target - - if (-not $session) - { - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSISessionDoesNotExistButShouldMessage) ` - -f $NodeAddress - ) -join '' ) - $desiredConfigurationMatch = $false - return $desiredConfigurationMatch - } # if - - # Check the Session parameters are correct - if (($AuthenticationType) ` - -and ($session.AuthenticationType -ne $AuthenticationType)) - { - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSIInitiatorParameterNeedsUpdateMessage) ` - -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress, 'Session', 'AuthenticationType' - ) -join '' ) - $desiredConfigurationMatch = $false - } # if - - if (($InitiatorInstanceName) ` - -and ($session.InitiatorInstanceName -ne $InitiatorInstanceName)) - { - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSIInitiatorParameterNeedsUpdateMessage) ` - -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress, 'Session', 'InitiatorInstanceName' - ) -join '' ) - $desiredConfigurationMatch = $false - } # if - - if ($PSBoundParameters.ContainsKey('InitiatorPortalAddress') ` - -and ($session.InitiatorPortalAddress -ne $InitiatorPortalAddress)) - { - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSIInitiatorParameterNeedsUpdateMessage) ` - -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress, 'Session', 'InitiatorAddress' - ) -join '' ) - $desiredConfigurationMatch = $false - } # if - - if (($null -ne $IsDataDigest) ` - -and ($session.IsDataDigest -ne $IsDataDigest)) - { - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSIInitiatorParameterNeedsUpdateMessage) ` - -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress, 'Session', 'IsDataDigest' - ) -join '' ) - $desiredConfigurationMatch = $false - } # if - - if (($null -ne $IsHeaderDigest) ` - -and ($session.IsHeaderDigest -ne $IsHeaderDigest)) - { - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSIInitiatorParameterNeedsUpdateMessage) ` - -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress, 'Session', 'IsHeaderDigest' - ) -join '' ) - $desiredConfigurationMatch = $false - } # if - - if (($null -ne $IsPersistent) ` - -and ($session.IsPersistent -ne $IsPersistent)) - { - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSIInitiatorParameterNeedsUpdateMessage) ` - -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress, 'Session', 'IsPersistent' - ) -join '' ) - $desiredConfigurationMatch = $false - } # if - } - else - { - # Ths iSCSI Target Portal doesn't exist but should - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSITargetPortalDoesNotExistButShouldMessage) ` - -f $TargetPortalAddress, $InitiatorPortalAddress - ) -join '' ) - $desiredConfigurationMatch = $false - } # if - - # Check the iSNS Server setting - if ($PSBoundParameters.ContainsKey('iSNSServer') ` - -and ($iSNSServerCurrent.iSNSServerAddress -ne $iSNSServer)) - { - # The iSNS Server is different so needs update - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSNSServerNeedsUpdateMessage) ` - -f $iSNSServerCurrent.iSNSServerAddress, $iSNSServer - ) -join '' ) - $desiredConfigurationMatch = $false - } # if - } - else - { - # Lookup the Target - $target = Get-Target ` - -NodeAddress $NodeAddress - - if ($target.IsConnected) - { - # The iSCSI Target exists and is connected - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSITargetExistsButShouldNotMessage) ` - -f $NodeAddress - ) -join '' ) - $desiredConfigurationMatch = $false - } # if - - # The iSCSI Target Portal should not exist - if ($targetPortal) - { - # The iSCSI Target Portal exists but should not - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSITargetPortalExistsButShouldNotMessage) ` - -f $TargetPortalAddress, $InitiatorPortalAddress - ) -join '' ) - $desiredConfigurationMatch = $false - } - else - { - # The iSCSI Target Portal does not exist and should not - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSCSITargetPortalDoesNotExistAndShouldNotMessage) ` - -f $TargetPortalAddress, $InitiatorPortalAddress - ) -join '' ) - } # if - - # Check the iSNS Server setting - if ($iSNSServerCurrent) - { - # The iSNS Server is set but should not be - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.iSNSServerIsSetButShouldNotBeMessage) - ) -join '' ) - $desiredConfigurationMatch = $false - } # if - } # if - return $desiredConfigurationMatch -} # Test-TargetResource - # Helper Functions <# .SYNOPSIS @@ -1275,5 +148,3 @@ function Get-Connection } return $Connection } # Get-Connection - -Export-ModuleMember -function *-TargetResource From 159f0695ff85a0bd06ba55aec9e3ea3f93bad1f1 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sun, 3 Jun 2018 22:21:19 +0100 Subject: [PATCH 03/16] Funtions moved to new files to make cleaner --- .../Public/Get-TargetResource.ps1 | 185 +++++++ .../Public/Set-TargetResource.ps1 | 492 ++++++++++++++++++ .../Public/Test-TargetResource.ps1 | 452 ++++++++++++++++ 3 files changed, 1129 insertions(+) create mode 100644 Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/Public/Get-TargetResource.ps1 create mode 100644 Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/Public/Set-TargetResource.ps1 create mode 100644 Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/Public/Test-TargetResource.ps1 diff --git a/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/Public/Get-TargetResource.ps1 b/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/Public/Get-TargetResource.ps1 new file mode 100644 index 0000000..73f98cd --- /dev/null +++ b/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/Public/Get-TargetResource.ps1 @@ -0,0 +1,185 @@ +<# + .SYNOPSIS + Returns the current state of the specified iSCSI Initiator. + + .PARAMETER NodeAddress + Represents the IQN of the discovered target. + + .PARAMETER TargetPortalAddress + Represents the IP address or DNS name of the target portal. + + .PARAMETER Ensure + Ensures that Target is Absent or Present. + + .PARAMETER InitiatorPortalAddress + Specifies the IP address associated with the portal. +#> + +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [System.String] + $NodeAddress, + + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [System.String] + $TargetPortalAddress, + + [Parameter()] + [ValidateSet('Present', 'Absent')] + [System.String] + $Ensure = 'Present', + + [Parameter()] + [System.String] + $InitiatorPortalAddress + ) + + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.GettingiSCSIInitiatorMessage) ` + -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress + ) -join '' ) + + $returnValue = @{ + NodeAddress = $NodeAddress + TargetPortalAddress = $TargetPortalAddress + InitiatorPortalAddress = $InitiatorPortalAddress + Ensure = 'Absent' + } + + # Lookup the Target Portal + $targetPortal = Get-TargetPortal ` + -TargetPortalAddress $TargetPortalAddress ` + -InitiatorPortalAddress $InitiatorPortalAddress + + if ($targetPortal) + { + $returnValue.TargetPortalAddress = $targetPortal.TargetPortalAddress + $returnValue.InitiatorPortalAddress = $targetPortal.InitiatorPortalAddress + $returnValue.TargetPortalPortNumber = $targetPortal.TargetPortalPortNumber + $returnValue.InitiatorInstanceName = $targetPortal.InitiatorInstanceName + $returnValue.IsDataDigest = $targetPortal.IsDataDigest + $returnValue.IsHeaderDigest = $targetPortal.IsHeaderDigest + + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSITargetPortalExistsMessage) ` + -f $TargetPortalAddress, $InitiatorPortalAddress + ) -join '' ) + } + else + { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSITargetPortalDoesNotExistMessage) ` + -f $TargetPortalAddress, $InitiatorPortalAddress + ) -join '' ) + } # if + + # Lookup the Target + $target = Get-Target ` + -NodeAddress $NodeAddress + + if ($target) + { + $returnValue.NodeAddress = $target.NodeAddress + $returnValue.IsConnected = $target.IsConnected + + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSITargetExistsMessage) ` + -f $NodeAddress + ) -join '' ) + } + else + { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSITargetDoesNotExistMessage) ` + -f $NodeAddress + ) -join '' ) + } # if + + # The rest of the properties can only be populated if the Target is connected. + if ($target.IsConnected) + { + # Lookup the Connection + $connection = Get-Connection ` + -Target $Target + + $returnValue.Ensure = 'Present' + + if ($connection) + { + $returnValue.TargetPortalAddress = $connection.TargetAddress + $returnValue.InitiatorPortalAddress = $connection.InitiatorAddress + $returnValue.TargetPortalPortNumber = $connection.TargetPortNumber + $returnValue.ConnectionIdentifier = $connection.ConnectionIdentifier + + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSIConnectionExistsMessage) ` + -f $NodeAddress + ) -join '' ) + } + else + { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSIConnectionDoesNotExistMessage) ` + -f $NodeAddress + ) -join '' ) + } # if + + # Lookup the Session + $session = Get-Session ` + -Target $target + + if ($session) + { + $returnValue.AuthenticationType = $session.AuthenticationType + $returnValue.InitiatorInstanceName = $session.InitiatorInstanceName + $returnValue.InitiatorPortalAddress = $session.InitiatorPortalAddress + $returnValue.IsConnected = $session.IsConnected + $returnValue.IsDataDigest = $session.IsDataDigest + $returnValue.IsDiscovered = $session.IsDiscovered + $returnValue.IsHeaderDigest = $session.IsHeaderDigest + $returnValue.IsPersistent = $session.IsPersistent + $returnValue.SessionIdentifier = $session.SessionIdentifier + + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSISessionExistsMessage) ` + -f $NodeAddress + ) -join '' ) + } + else + { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSISessionDoesNotExistMessage) ` + -f $NodeAddress + ) -join '' ) + } # if + } # if + + # Get the iSNS Server + $iSNSServerCurrent = Get-WmiObject ` + -Class MSiSCSIInitiator_iSNSServerClass ` + -Namespace root\wmi + if ($iSNSServerCurrent) + { + $returnValue += @{ + iSNSServer = $iSNSServerCurrent.iSNSServerAddress + } + } + + $returnValue +} # Get-TargetResource \ No newline at end of file diff --git a/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/Public/Set-TargetResource.ps1 b/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/Public/Set-TargetResource.ps1 new file mode 100644 index 0000000..17158f5 --- /dev/null +++ b/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/Public/Set-TargetResource.ps1 @@ -0,0 +1,492 @@ +<# + .SYNOPSIS + Creates, updates or removes an iSCSI Initiator. + + .PARAMETER NodeAddress + Represents the IQN of the discovered target. + + .PARAMETER TargetPortalAddress + Represents the IP address or DNS name of the target portal. + + .PARAMETER Ensure + Ensures that Target is Absent or Present. + + .PARAMETER InitiatorPortalAddress + Specifies the IP address associated with the portal. + + .PARAMETER TargetPortalPortNumber + Specifies the TCP/IP port number for the target portal. + + .PARAMETER InitiatorInstanceName + The name of the initiator instance that the iSCSI initiator service uses to send SendTargets + requests to the target portal. If no instance name is specified, the iSCSI initiator service + chooses the initiator instance. + + .PARAMETER AuthenticationType + Specifies the type of authentication to use when logging into the target. + + .PARAMETER ChapUsername + Specifies the user name to use when establishing a connection authenticated by using Mutual + CHAP. + + .PARAMETER ChapSecret + Specifies the CHAP secret to use when establishing a connection authenticated by using CHAP. + + .PARAMETER IsDataDigest + Enables data digest when the initiator logs into the target portal. + + .PARAMETER IsHeaderDigest + Enables header digest when the initiator logs into the target portal. By not specifying this + parameter, the digest setting is determined by the initiator kernel mode driver. + + .PARAMETER IsMultipathEnabled + Indicates that the initiator has enabled Multipath I/O (MPIO) and it will be used when logging + into the target portal. + + .PARAMETER IsPersistent + Specifies that the session is to be automatically connected after each restart. + + .PARAMETER ReportToPnP + Specifies that the operation is reported to PNP. + + .PARAMETER iSNSServer + Specifies an iSNS Server to register this Initiator with. +#> + +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [System.String] + $NodeAddress, + + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [System.String] + $TargetPortalAddress, + + [Parameter()] + [ValidateSet('Present', 'Absent')] + [System.String] + $Ensure = 'Present', + + [Parameter()] + [System.String] + $InitiatorPortalAddress, + + [Parameter()] + [System.Uint16] + $TargetPortalPortNumber, + + [Parameter()] + [System.String] + $InitiatorInstanceName, + + [Parameter()] + [ValidateSet('None', 'OneWayCHAP', 'MutualCHAP')] + [System.String] + $AuthenticationType, + + [Parameter()] + [System.String] + $ChapUsername, + + [Parameter()] + [System.String] + $ChapSecret, + + [Parameter()] + [System.Boolean] + $IsDataDigest, + + [Parameter()] + [System.Boolean] + $IsHeaderDigest, + + [Parameter()] + [System.Boolean] + $IsMultipathEnabled, + + [Parameter()] + [System.Boolean] + $IsPersistent, + + [Parameter()] + [System.Boolean] + $ReportToPNP, + + [Parameter()] + [System.String] + $iSNSServer + ) + + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.SettingiSCSIInitiatorMessage) ` + -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress + ) -join '' ) + + # Remove any parameters that can't be splatted. + $null = $PSBoundParameters.Remove('Ensure') + + $targetSplat = @{ TargetPortalAddress = $TargetPortalAddress } + if ($PSBoundParameters.ContainsKey('InitiatorPortalAddress')) + { + $targetSplat += @{ InitiatorPortalAddress = $InitiatorPortalAddress } + } + + # Lookup the existing iSCSI Target Portal + $targetPortal = Get-TargetPortal @TargetSplat + + # Get the iSNS Server + $iSNSServerCurrent = Get-WmiObject ` + -Class MSiSCSIInitiator_iSNSServerClass ` + -Namespace root\wmi + + $returnValue += @{ + iSNSServer = $iSNSServerCurrent.iSNSServerAddress + } + + if ($Ensure -eq 'Present') + { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.EnsureiSCSITargetPortalExistsMessage) ` + -f $TargetPortalAddress, $InitiatorPortalAddress + ) -join '' ) + + [Boolean] $create = $false + + if ($targetPortal) + { + # The iSCSI Target Portal exists - check the parameters + if (($TargetPortalPortNumber) ` + -and ($targetPortal.TargetPortalPortNumber -ne $TargetPortalPortNumber)) + { + $create = $true + } # if + if (($InitiatorInstanceName) ` + -and ($targetPortal.InitiatorInstanceName -ne $InitiatorInstanceName)) + { + $create = $true + } # if + if (($null -ne $IsDataDigest) ` + -and ($targetPortal.IsDataDigest -ne $IsDataDigest)) + { + $create = $true + } # if + if (($null -ne $IsHeaderDigest) ` + -and ($targetPortal.IsHeaderDigest -ne $IsHeaderDigest)) + { + $create = $true + } # if + + if ($create) + { + # The Target Portal exists but has different parameters + # so it has to be removed and recreated + Remove-iSCSITargetPortal @TargetSplat -ErrorAction Stop + + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSITargetPortalRemovedForRecreateMessage) ` + -f $TargetPortalAddress, $InitiatorPortalAddress + ) -join '' ) + } # if + } + else + { + $create = $true + } # if + + if ($create) + { + # Create the iSCSI Target Portal using a splat + [PSObject] $splat = [PSObject]@{} + $PSBoundParameters + $splat.Remove('NodeAddress') + $splat.Remove('IsMultipathEnabled') + $splat.Remove('IsPersistent') + $splat.Remove('ReportToPNP') + $splat.Remove('iSNSServer') + New-iSCSITargetPortal ` + @splat ` + -ErrorAction Stop + + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSITargetPortalCreatedMessage) ` + -f $TargetPortalAddress, $InitiatorPortalAddress + ) -join '' ) + } + + # Lookup the Target + $target = Get-Target ` + -NodeAddress $NodeAddress + + # Check the Target is connected + [Boolean] $connect = $false + + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.EnsureiSCSITargetIsConnectedMessage) ` + -f $NodeAddress + ) -join '' ) + + if ($target) + { + # Lookup the Connection + $connection = Get-Connection ` + -Target $target + + # Lookup the Session + $session = Get-Session ` + -Target $target + + if ($connection -and $session) + { + # Check that the session and connection parameters are correct + + # The Connection.TargetAddress will always be an IP Address + # even if the TargetPortalAddress was specified as a Hostname + try + { + $targetPortalIP = @( + ([System.Net.IPAddress]$TargetPortalAddress).IPAddressToString + ) + } + catch + { + # This is a TargetPortalAddress is a Hostname so resolve it to IP addresses + $targetPortalIP = @( + (Resolve-DNSName -Name $TargetPortalAddress -Type A).IPAddress + ) + } # try + + if ($connection.TargetAddress -notin $targetPortalIP) + { + $connect = $true + } # if + if ($connection.InitiatorAddress -ne $InitiatorPortalAddress) + { + $connect = $true + } # if + if (($TargetPortalPortNumber) ` + -and ($connection.TargetPortNumber -ne $TargetPortalPortNumber)) + { + $connect = $true + } # if + if (($AuthenticationType) ` + -and ($session.AuthenticationType -ne $AuthenticationType)) + { + $connect = $true + } # if + if (($InitiatorInstanceName) ` + -and ($session.InitiatorInstanceName -ne $InitiatorInstanceName)) + { + $connect = $true + } # if + if ($PSBoundParameters.ContainsKey('InitiatorPortalAddress') ` + -and ($session.InitiatorPortalAddress -ne $InitiatorPortalAddress)) + { + $connect = $true + } # if + if (($null -ne $IsDataDigest) ` + -and ($session.IsDataDigest -ne $IsDataDigest)) + { + $connect = $true + } # if + if (($null -ne $IsHeaderDigest) ` + -and ($session.IsHeaderDigest -ne $IsHeaderDigest)) + { + $connect = $true + } # if + + if ($connect) + { + # The Target/Session/Connection has different parameters + # So disconnect everything so it can be reconnected + Disconnect-IscsiTarget ` + -NodeAddress $NodeAddress ` + -Confirm:$False ` + -ErrorAction Stop + + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSITargetDisconnectedMessage) ` + -f $NodeAddress + ) -join '' ) + + } # if + } + else + { + # Either the session or connection doesn't exist + # so reconnect or the target is not connected + $connect = $true + } # if + } + else + { + $connect = $true + } # if + + if ($connect) + { + [PSObject] $splat = [PSObject]@{} + $PSBoundParameters + $splat.Remove('IsMultipathEnabled') + $splat.Remove('iSNSServer') + + $Session = Connect-IscsiTarget ` + @splat ` + -ErrorAction Stop + + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSITargetConnectedMessage) ` + -f $NodeAddress + ) -join '' ) + } # if + + if (($PSBoundParameters.ContainsKey('IsPersistent')) ` + -and ($IsPersistent -ne $session.IsPersistent)) + { + if ($IsPersistent -eq $true) + { + # Ensure session is persistent + $session | Register-IscsiSession ` + -IsMultipathEnabled $IsMultipathEnabled ` + -ErrorAction Stop + + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSISessionSetPersistentMessage) ` + -f $NodeAddress + ) -join '' ) + } + else + { + # Ensure session is not persistent + $session | Unregister-IscsiSession ` + -ErrorAction Stop + + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSISessionRemovedPersistentMessage) ` + -f $NodeAddress + ) -join '' ) + } + } + + # Check the iSNS Server setting + if ($PSBoundParameters.ContainsKey('iSNSServer')) + { + if ([String]::IsNullOrEmpty($iSNSServer)) + { + if ($iSNSServerCurrent) + { + # The iSNS Server is set but should not be - remove it + Remove-WmiObject ` + -Path $iSNSServerCurrent.Path ` + -ErrorAction Stop + + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSNSServerRemovedMessage) + ) -join '' ) + } # if + } + else + { + try + { + Set-WmiInstance ` + -Namespace root\wmi ` + -Class WT_iSNSServer ` + -Arguments @{ServerName = $iSNSServer} ` + -ErrorAction Stop + + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSNSServerUpdatedMessage) ` + -f $iSNSServer + ) -join '' ) + } + catch + { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSNSServerUpdateErrorMessage) ` + -f $iSNSServer + ) -join '' ) + } + } # if + } # if + } + else + { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.EnsureiSCSITargetIsDisconnectedMessage) ` + -f $NodeAddress + ) -join '' ) + + # Lookup the Target + $target = Get-Target ` + -NodeAddress $NodeAddress + + if ($target) + { + if ($target.IsConnected) + { + Disconnect-IscsiTarget ` + -NodeAddress $NodeAddress ` + -Confirm:$false ` + -ErrorAction Stop + + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSITargetDisconnectedMessage) ` + -f $NodeAddress + ) -join '' ) + } + } + + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.EnsureiSCSITargetPortalDoesNotExistMessage) ` + -f $TargetPortalAddress, $InitiatorPortalAddress + ) -join '' ) + + if ($targetPortal) + { + # The iSCSI Target Portal shouldn't exist - remove it + Remove-iSCSITargetPortal ` + @TargetSplat ` + -Confirm:$False ` + -ErrorAction Stop + + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSITargetPortalRemovedMessage) ` + -f $TargetPortalAddress, $InitiatorPortalAddress + ) -join '' ) + } # if + + if ($iSNSServerCurrent) + { + # The iSNS Server is set but should not be - remove it + Remove-WmiObject ` + -Path $iSNSServerCurrent.Path ` + -ErrorAction Stop + + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSIServerTargetiSNSRemovedMessage) ` + -f $TargetName + ) -join '' ) + } # if + } # if +} # Set-TargetResource \ No newline at end of file diff --git a/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/Public/Test-TargetResource.ps1 b/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/Public/Test-TargetResource.ps1 new file mode 100644 index 0000000..5759d15 --- /dev/null +++ b/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/Public/Test-TargetResource.ps1 @@ -0,0 +1,452 @@ +<# + .SYNOPSIS + Tests if an iSCSI Initiator needs to be created, updated or removed. + .PARAMETER NodeAddress + Represents the IQN of the discovered target. + + .PARAMETER TargetPortalAddress + Represents the IP address or DNS name of the target portal. + + .PARAMETER Ensure + Ensures that Target is Absent or Present. + + .PARAMETER InitiatorPortalAddress + Specifies the IP address associated with the portal. + + .PARAMETER TargetPortalPortNumber + Specifies the TCP/IP port number for the target portal. + + .PARAMETER InitiatorInstanceName + The name of the initiator instance that the iSCSI initiator service uses to send SendTargets + requests to the target portal. If no instance name is specified, the iSCSI initiator service + chooses the initiator instance. + + .PARAMETER AuthenticationType + Specifies the type of authentication to use when logging into the target. + + .PARAMETER ChapUsername + Specifies the user name to use when establishing a connection authenticated by using Mutual + CHAP. + + .PARAMETER ChapSecret + Specifies the CHAP secret to use when establishing a connection authenticated by using CHAP. + + .PARAMETER IsDataDigest + Enables data digest when the initiator logs into the target portal. + + .PARAMETER IsHeaderDigest + Enables header digest when the initiator logs into the target portal. By not specifying this + parameter, the digest setting is determined by the initiator kernel mode driver. + + .PARAMETER IsMultipathEnabled + Indicates that the initiator has enabled Multipath I/O (MPIO) and it will be used when logging + into the target portal. + + .PARAMETER IsPersistent + Specifies that the session is to be automatically connected after each restart. + + .PARAMETER ReportToPnP + Specifies that the operation is reported to PNP. + + .PARAMETER iSNSServer + Specifies an iSNS Server to register this Initiator with. +#> +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [System.String] + $NodeAddress, + + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [System.String] + $TargetPortalAddress, + + [Parameter()] + [ValidateSet('Present', 'Absent')] + [System.String] + $Ensure = 'Present', + + [Parameter()] + [System.String] + $InitiatorPortalAddress, + + [Parameter()] + [System.Uint16] + $TargetPortalPortNumber, + + [Parameter()] + [System.String] + $InitiatorInstanceName, + + [Parameter()] + [ValidateSet('None', 'OneWayCHAP', 'MutualCHAP')] + [System.String] + $AuthenticationType, + + [Parameter()] + [System.String] + $ChapUsername, + + [Parameter()] + [System.String] + $ChapSecret, + + [Parameter()] + [System.Boolean] + $IsDataDigest, + + [Parameter()] + [System.Boolean] + $IsHeaderDigest, + + [Parameter()] + [System.Boolean] + $IsMultipathEnabled, + + [Parameter()] + [System.Boolean] + $IsPersistent, + + [Parameter()] + [System.Boolean] + $ReportToPNP, + + [Parameter()] + [System.String] + $iSNSServer + ) + + # Flag to signal whether settings are correct + [Boolean] $desiredConfigurationMatch = $true + + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.TestingiSCSIInitiatorMessage) ` + -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress + ) -join '' ) + + $targetSplat = @{ TargetPortalAddress = $TargetPortalAddress } + if ($PSBoundParameters.ContainsKey('InitiatorPortalAddress')) + { + $targetSplat += @{ InitiatorPortalAddress = $InitiatorPortalAddress } + } + + # Lookup the existing iSCSI Target Portal + $targetPortal = Get-TargetPortal @TargetSplat + + # Get the iSNS Server + $iSNSServerCurrent = Get-WmiObject ` + -Class MSiSCSIInitiator_iSNSServerClass ` + -Namespace root\wmi + + $returnValue += @{ + iSNSServer = $iSNSServerCurrent.iSNSServerAddress + } + + if ($Ensure -eq 'Present') + { + # The iSCSI Target Portal should exist + if ($targetPortal) + { + # The iSCSI Target Portal exists already - check the parameters + if (($TargetPortalPortNumber) ` + -and ($targetPortal.TargetPortalPortNumber -ne $TargetPortalPortNumber)) + { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSIInitiatorParameterNeedsUpdateMessage) ` + -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress, 'TargetPortal', 'TargetPortalPortNumber' + ) -join '' ) + $desiredConfigurationMatch = $false + } # if + + if (($InitiatorInstanceName) ` + -and ($targetPortal.InitiatorInstanceName -ne $InitiatorInstanceName)) + { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSIInitiatorParameterNeedsUpdateMessage) ` + -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress, 'TargetPortal', 'InitiatorInstanceName' + ) -join '' ) + $desiredConfigurationMatch = $false + } # if + + if (($null -ne $IsDataDigest) ` + -and ($targetPortal.IsDataDigest -ne $IsDataDigest)) + { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSIInitiatorParameterNeedsUpdateMessage) ` + -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress, 'TargetPortal', 'IsDataDigest' + ) -join '' ) + $desiredConfigurationMatch = $false + } # if + + if (($null -ne $IsHeaderDigest) ` + -and ($targetPortal.IsHeaderDigest -ne $IsHeaderDigest)) + { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSIInitiatorParameterNeedsUpdateMessage) ` + -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress, 'TargetPortal', 'IsHeaderDigest' + ) -join '' ) + $desiredConfigurationMatch = $false + } # if + + # Lookup the Target + $target = Get-Target ` + -NodeAddress $NodeAddress + + if (! $target) + { + # Ths iSCSI Target doesn't exist but should + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSITargetDoesNotExistButShouldMessage) ` + -f $NodeAddress + ) -join '' ) + $desiredConfigurationMatch = $false + return $desiredConfigurationMatch + } # if + + if (-not $target.IsConnected) + { + # Ths iSCSI Target exists but is not connected + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSITargetNotConnectedMessage) ` + -f $NodeAddress + ) -join '' ) + $desiredConfigurationMatch = $false + return $desiredConfigurationMatch + } # if + + # Lookup the Connection + $connection = Get-Connection ` + -Target $target + + if (-not $connection) + { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSIConnectionDoesNotExistButShouldMessage) ` + -f $NodeAddress + ) -join '' ) + $desiredConfigurationMatch = $false + return $desiredConfigurationMatch + } # if + + <# + Check the Connection parameters are correct + The Connection.TargetAddress will always be an IP Address + even if the TargetPortalAddress was specified as a Hostname + #> + try + { + $targetPortalIP = @( + ([System.Net.IPAddress]$TargetPortalAddress).IPAddressToString + ) + } + catch + { + # This is a TargetPortalAddress is a Hostname so resolve it to IP addresses + $targetPortalIP = @( + (Resolve-DNSName -Name $TargetPortalAddress -Type A).IPAddress + ) + } # try + + if ($connection.TargetAddress -notin $targetPortalIP) + { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSIInitiatorParameterNeedsUpdateMessage) ` + -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress, 'Connection', 'TargetAddress' + ) -join '' ) + $desiredConfigurationMatch = $false + } + + if ($PSBoundParameters.ContainsKey('InitiatorPortalAddress') ` + -and ($connection.InitiatorAddress -ne $InitiatorPortalAddress)) + { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSIInitiatorParameterNeedsUpdateMessage) ` + -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress, 'Connection', 'InitiatorAddress' + ) -join '' ) + $desiredConfigurationMatch = $false + } # if + + if (($TargetPortalPortNumber) ` + -and ($connection.TargetPortNumber -ne $TargetPortalPortNumber)) + { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSIInitiatorParameterNeedsUpdateMessage) ` + -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress, 'Connection', 'TargetPortNumber' + ) -join '' ) + $desiredConfigurationMatch = $false + } # if + + # Lookup the Session + $session = Get-Session ` + -Target $target + + if (-not $session) + { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSISessionDoesNotExistButShouldMessage) ` + -f $NodeAddress + ) -join '' ) + $desiredConfigurationMatch = $false + return $desiredConfigurationMatch + } # if + + # Check the Session parameters are correct + if (($AuthenticationType) ` + -and ($session.AuthenticationType -ne $AuthenticationType)) + { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSIInitiatorParameterNeedsUpdateMessage) ` + -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress, 'Session', 'AuthenticationType' + ) -join '' ) + $desiredConfigurationMatch = $false + } # if + + if (($InitiatorInstanceName) ` + -and ($session.InitiatorInstanceName -ne $InitiatorInstanceName)) + { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSIInitiatorParameterNeedsUpdateMessage) ` + -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress, 'Session', 'InitiatorInstanceName' + ) -join '' ) + $desiredConfigurationMatch = $false + } # if + + if ($PSBoundParameters.ContainsKey('InitiatorPortalAddress') ` + -and ($session.InitiatorPortalAddress -ne $InitiatorPortalAddress)) + { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSIInitiatorParameterNeedsUpdateMessage) ` + -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress, 'Session', 'InitiatorAddress' + ) -join '' ) + $desiredConfigurationMatch = $false + } # if + + if (($null -ne $IsDataDigest) ` + -and ($session.IsDataDigest -ne $IsDataDigest)) + { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSIInitiatorParameterNeedsUpdateMessage) ` + -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress, 'Session', 'IsDataDigest' + ) -join '' ) + $desiredConfigurationMatch = $false + } # if + + if (($null -ne $IsHeaderDigest) ` + -and ($session.IsHeaderDigest -ne $IsHeaderDigest)) + { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSIInitiatorParameterNeedsUpdateMessage) ` + -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress, 'Session', 'IsHeaderDigest' + ) -join '' ) + $desiredConfigurationMatch = $false + } # if + + if (($null -ne $IsPersistent) ` + -and ($session.IsPersistent -ne $IsPersistent)) + { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSIInitiatorParameterNeedsUpdateMessage) ` + -f $NodeAddress, $TargetPortalAddress, $InitiatorPortalAddress, 'Session', 'IsPersistent' + ) -join '' ) + $desiredConfigurationMatch = $false + } # if + } + else + { + # Ths iSCSI Target Portal doesn't exist but should + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSITargetPortalDoesNotExistButShouldMessage) ` + -f $TargetPortalAddress, $InitiatorPortalAddress + ) -join '' ) + $desiredConfigurationMatch = $false + } # if + + # Check the iSNS Server setting + if ($PSBoundParameters.ContainsKey('iSNSServer') ` + -and ($iSNSServerCurrent.iSNSServerAddress -ne $iSNSServer)) + { + # The iSNS Server is different so needs update + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSNSServerNeedsUpdateMessage) ` + -f $iSNSServerCurrent.iSNSServerAddress, $iSNSServer + ) -join '' ) + $desiredConfigurationMatch = $false + } # if + } + else + { + # Lookup the Target + $target = Get-Target ` + -NodeAddress $NodeAddress + + if ($target.IsConnected) + { + # The iSCSI Target exists and is connected + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSITargetExistsButShouldNotMessage) ` + -f $NodeAddress + ) -join '' ) + $desiredConfigurationMatch = $false + } # if + + # The iSCSI Target Portal should not exist + if ($targetPortal) + { + # The iSCSI Target Portal exists but should not + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSITargetPortalExistsButShouldNotMessage) ` + -f $TargetPortalAddress, $InitiatorPortalAddress + ) -join '' ) + $desiredConfigurationMatch = $false + } + else + { + # The iSCSI Target Portal does not exist and should not + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSCSITargetPortalDoesNotExistAndShouldNotMessage) ` + -f $TargetPortalAddress, $InitiatorPortalAddress + ) -join '' ) + } # if + + # Check the iSNS Server setting + if ($iSNSServerCurrent) + { + # The iSNS Server is set but should not be + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($LocalizedData.iSNSServerIsSetButShouldNotBeMessage) + ) -join '' ) + $desiredConfigurationMatch = $false + } # if + } # if + return $desiredConfigurationMatch +} # Test-TargetResource From 43c7aa295dd89f38ce751f8a06e9ee77d8be03eb Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sun, 3 Jun 2018 22:27:56 +0100 Subject: [PATCH 04/16] changed to cim class --- .../DSR_iSCSIInitiator/Public/Get-TargetResource.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/Public/Get-TargetResource.ps1 b/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/Public/Get-TargetResource.ps1 index 73f98cd..37f3013 100644 --- a/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/Public/Get-TargetResource.ps1 +++ b/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/Public/Get-TargetResource.ps1 @@ -171,7 +171,7 @@ function Get-TargetResource } # if # Get the iSNS Server - $iSNSServerCurrent = Get-WmiObject ` + $iSNSServerCurrent = Get-CimInstance ` -Class MSiSCSIInitiator_iSNSServerClass ` -Namespace root\wmi if ($iSNSServerCurrent) @@ -182,4 +182,4 @@ function Get-TargetResource } $returnValue -} # Get-TargetResource \ No newline at end of file +} # Get-TargetResource From 921f68db54aaa8b97b25d12546910aee59a4e4cf Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sun, 3 Jun 2018 22:29:40 +0100 Subject: [PATCH 05/16] Converted to cim class --- .../DSR_iSCSIInitiator/Public/Set-TargetResource.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/Public/Set-TargetResource.ps1 b/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/Public/Set-TargetResource.ps1 index 17158f5..9eab6a5 100644 --- a/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/Public/Set-TargetResource.ps1 +++ b/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/Public/Set-TargetResource.ps1 @@ -142,7 +142,7 @@ function Set-TargetResource $targetPortal = Get-TargetPortal @TargetSplat # Get the iSNS Server - $iSNSServerCurrent = Get-WmiObject ` + $iSNSServerCurrent = Get-CimInstance ` -Class MSiSCSIInitiator_iSNSServerClass ` -Namespace root\wmi @@ -489,4 +489,4 @@ function Set-TargetResource ) -join '' ) } # if } # if -} # Set-TargetResource \ No newline at end of file +} # Set-TargetResource From f44922911b5ac4acb7b14542444e53e5c27814a1 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sun, 3 Jun 2018 22:30:39 +0100 Subject: [PATCH 06/16] converted to cim class --- .../DSR_iSCSIInitiator/Public/Test-TargetResource.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/Public/Test-TargetResource.ps1 b/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/Public/Test-TargetResource.ps1 index 5759d15..33dd961 100644 --- a/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/Public/Test-TargetResource.ps1 +++ b/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/Public/Test-TargetResource.ps1 @@ -141,7 +141,7 @@ function Test-TargetResource $targetPortal = Get-TargetPortal @TargetSplat # Get the iSNS Server - $iSNSServerCurrent = Get-WmiObject ` + $iSNSServerCurrent = Get-CimInstance ` -Class MSiSCSIInitiator_iSNSServerClass ` -Namespace root\wmi From 33d4ff69b005d134b7896893f77979d6611ac82d Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sun, 3 Jun 2018 22:36:33 +0100 Subject: [PATCH 07/16] Replaced Get-WMIObject with Get-CimInstance as is safe --- .../DSR_iSCSIServerTarget/DSR_iSCSIServerTarget.psm1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/iSCSIDsc/DSCResources/DSR_iSCSIServerTarget/DSR_iSCSIServerTarget.psm1 b/Modules/iSCSIDsc/DSCResources/DSR_iSCSIServerTarget/DSR_iSCSIServerTarget.psm1 index 1a70543..6e3fed5 100644 --- a/Modules/iSCSIDsc/DSCResources/DSR_iSCSIServerTarget/DSR_iSCSIServerTarget.psm1 +++ b/Modules/iSCSIDsc/DSCResources/DSR_iSCSIServerTarget/DSR_iSCSIServerTarget.psm1 @@ -83,7 +83,7 @@ function Get-TargetResource } # if # Get the iSNS Server - $iSNSServerCurrent = Get-WmiObject ` + $iSNSServerCurrent = Get-CimInstance ` -Class WT_iSNSServer ` -Namespace root\wmi if ($iSNSServerCurrent) @@ -154,7 +154,7 @@ function Set-TargetResource $serverTarget = Get-ServerTarget -TargetName $TargetName # Get the iSNS Server - $iSNSServerCurrent = Get-WmiObject ` + $iSNSServerCurrent = Get-CimInstance ` -Class WT_iSNSServer ` -Namespace root\wmi @@ -384,7 +384,7 @@ function Test-TargetResource $serverTarget = Get-ServerTarget -TargetName $TargetName # Get the iSNS Server - $iSNSServerCurrent = Get-WmiObject ` + $iSNSServerCurrent = Get-CimInstance ` -Class WT_iSNSServer ` -Namespace root\wmi From 6ff0eab1ffbf774ac74f33d3fdef14d67e2a0786 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sun, 3 Jun 2018 22:39:20 +0100 Subject: [PATCH 08/16] Replaced Get-WMIObject as is safe to do so for simple query --- .../DSR_iSCSIInitiator.Integration.Tests.ps1 | 2 +- Tests/Unit/DSR_iSCSIInitiator.Tests.ps1 | 192 +++++++++--------- 2 files changed, 97 insertions(+), 97 deletions(-) diff --git a/Tests/Integration/DSR_iSCSIInitiator.Integration.Tests.ps1 b/Tests/Integration/DSR_iSCSIInitiator.Integration.Tests.ps1 index eb00ae1..4645515 100644 --- a/Tests/Integration/DSR_iSCSIInitiator.Integration.Tests.ps1 +++ b/Tests/Integration/DSR_iSCSIInitiator.Integration.Tests.ps1 @@ -124,7 +124,7 @@ try $Initiator.IsDiscovered | Should -Be $ConnectionNew.IsDiscovered $Initiator.IsHeaderDigest | Should -Be $ConnectionNew.IsHeaderDigest $Initiator.IsPersistent | Should -Be $ConnectionNew.IsPersistent - $iSNSServerNew = Get-WmiObject -Class MSiSCSIInitiator_iSNSServerClass -Namespace root\wmi + $iSNSServerNew = Get-CimInstance -Class MSiSCSIInitiator_iSNSServerClass -Namespace root\wmi # The iSNS Server is not usually accessible so won't be able to be set # $Initiator.iSNSServer | Should Be $iSNSServerNew.iSNSServerAddress } diff --git a/Tests/Unit/DSR_iSCSIInitiator.Tests.ps1 b/Tests/Unit/DSR_iSCSIInitiator.Tests.ps1 index d29c242..5a2d3f7 100644 --- a/Tests/Unit/DSR_iSCSIInitiator.Tests.ps1 +++ b/Tests/Unit/DSR_iSCSIInitiator.Tests.ps1 @@ -188,7 +188,7 @@ try Mock Get-Target Mock Get-Connection Mock Get-Session - Mock Get-WMIObject + Mock Get-CimInstance It 'should return absent' { $Result = Get-TargetResource ` -NodeAddress $TestInitiator.NodeAddress ` @@ -201,7 +201,7 @@ try Assert-MockCalled -commandName Get-Target -Exactly 1 Assert-MockCalled -commandName Get-Connection -Exactly 0 Assert-MockCalled -commandName Get-Session -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } @@ -210,7 +210,7 @@ try Mock Get-Target Mock Get-Connection Mock Get-Session - Mock Get-WMIObject + Mock Get-CimInstance It 'should return absent but with Target Portal data' { $Result = Get-TargetResource ` -NodeAddress $TestInitiator.NodeAddress ` @@ -229,7 +229,7 @@ try Assert-MockCalled -commandName Get-Target -Exactly 1 Assert-MockCalled -commandName Get-Connection -Exactly 0 Assert-MockCalled -commandName Get-Session -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } @@ -238,7 +238,7 @@ try Mock Get-Target -MockWith { return @($MockTargetNotConnected) } Mock Get-Connection Mock Get-Session - Mock Get-WMIObject + Mock Get-CimInstance It 'should return absent but with Target Portal data' { $Result = Get-TargetResource ` -NodeAddress $TestInitiator.NodeAddress ` @@ -257,7 +257,7 @@ try Assert-MockCalled -commandName Get-Target -Exactly 1 Assert-MockCalled -commandName Get-Connection -Exactly 0 Assert-MockCalled -commandName Get-Session -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } @@ -266,7 +266,7 @@ try Mock Get-Target -MockWith { return @($MockTargetNotConnected) } Mock Get-Connection Mock Get-Session - Mock Get-WMIObject + Mock Get-CimInstance It 'should return absent but with Target Portal data' { $Result = Get-TargetResource ` -NodeAddress $TestInitiatorWithoutInitiatorAddress.NodeAddress ` @@ -284,7 +284,7 @@ try Assert-MockCalled -commandName Get-Target -Exactly 1 Assert-MockCalled -commandName Get-Connection -Exactly 0 Assert-MockCalled -commandName Get-Session -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } @@ -293,7 +293,7 @@ try Mock Get-Target -MockWith { return @($MockTarget) } Mock Get-Connection -MockWith { return @($MockConnection) } Mock Get-Session -MockWith { return @($MockSession) } - Mock Get-WMIObject + Mock Get-CimInstance It 'should return correct data' { $Result = Get-TargetResource ` -NodeAddress $TestInitiator.NodeAddress ` @@ -319,7 +319,7 @@ try Assert-MockCalled -commandName Get-Target -Exactly 1 Assert-MockCalled -commandName Get-Connection -Exactly 1 Assert-MockCalled -commandName Get-Session -Exactly 1 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } @@ -328,7 +328,7 @@ try Mock Get-Target -MockWith { return @($MockTarget) } Mock Get-Connection -MockWith { return @($MockConnection) } Mock Get-Session -MockWith { return @($MockSession) } - Mock Get-WMIObject + Mock Get-CimInstance It 'should return correct data' { $Result = Get-TargetResource ` -NodeAddress $TestInitiatorWithoutInitiatorAddress.NodeAddress ` @@ -353,7 +353,7 @@ try Assert-MockCalled -commandName Get-Target -Exactly 1 Assert-MockCalled -commandName Get-Connection -Exactly 1 Assert-MockCalled -commandName Get-Session -Exactly 1 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } @@ -362,7 +362,7 @@ try Mock Get-Target -MockWith { return @($MockTarget) } Mock Get-Connection -MockWith { return @($MockConnection) } Mock Get-Session -MockWith { return @($MockSession) } - Mock Get-WMIObject -MockWith { return @($MockiSNSSrver) } + Mock Get-CimInstance -MockWith { return @($MockiSNSSrver) } It 'should return correct data' { $Result = Get-TargetResource ` -NodeAddress $TestInitiator.NodeAddress ` @@ -389,7 +389,7 @@ try Assert-MockCalled -commandName Get-Target -Exactly 1 Assert-MockCalled -commandName Get-Connection -Exactly 1 Assert-MockCalled -commandName Get-Session -Exactly 1 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } } @@ -406,7 +406,7 @@ try Mock Disconnect-IscsiTarget Mock Register-IscsiSession Mock Unregister-IscsiSession - Mock Get-WMIObject + Mock Get-CimInstance Mock Set-WMIInstance Mock Remove-WMIObject It 'should not throw error' { @@ -426,7 +426,7 @@ try Assert-MockCalled -commandName Disconnect-IscsiTarget -Exactly 0 Assert-MockCalled -commandName Register-IscsiSession -Exactly 1 Assert-MockCalled -commandName Unregister-IscsiSession -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -443,7 +443,7 @@ try Mock Disconnect-IscsiTarget Mock Register-IscsiSession Mock Unregister-IscsiSession - Mock Get-WMIObject + Mock Get-CimInstance Mock Set-WMIInstance Mock Remove-WMIObject It 'should not throw error' { @@ -463,7 +463,7 @@ try Assert-MockCalled -commandName Disconnect-IscsiTarget -Exactly 0 Assert-MockCalled -commandName Register-IscsiSession -Exactly 1 Assert-MockCalled -commandName Unregister-IscsiSession -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -480,7 +480,7 @@ try Mock Disconnect-IscsiTarget Mock Register-IscsiSession Mock Unregister-IscsiSession - Mock Get-WMIObject + Mock Get-CimInstance Mock Set-WMIInstance Mock Remove-WMIObject It 'should not throw error' { @@ -500,7 +500,7 @@ try Assert-MockCalled -commandName Disconnect-IscsiTarget -Exactly 0 Assert-MockCalled -commandName Register-IscsiSession -Exactly 1 Assert-MockCalled -commandName Unregister-IscsiSession -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -517,7 +517,7 @@ try Mock Disconnect-IscsiTarget Mock Register-IscsiSession Mock Unregister-IscsiSession - Mock Get-WMIObject + Mock Get-CimInstance Mock Set-WMIInstance Mock Remove-WMIObject It 'should not throw error' { @@ -537,7 +537,7 @@ try Assert-MockCalled -commandName Disconnect-IscsiTarget -Exactly 0 Assert-MockCalled -commandName Register-IscsiSession -Exactly 1 Assert-MockCalled -commandName Unregister-IscsiSession -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -553,7 +553,7 @@ try Mock Disconnect-IscsiTarget Mock Register-IscsiSession Mock Unregister-IscsiSession - Mock Get-WMIObject + Mock Get-CimInstance Mock Set-WMIInstance Mock Remove-WMIObject @@ -576,7 +576,7 @@ try Assert-MockCalled -commandName Disconnect-IscsiTarget -Exactly 0 Assert-MockCalled -commandName Register-IscsiSession -Exactly 1 Assert-MockCalled -commandName Unregister-IscsiSession -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -601,7 +601,7 @@ try Assert-MockCalled -commandName Disconnect-IscsiTarget -Exactly 0 Assert-MockCalled -commandName Register-IscsiSession -Exactly 1 Assert-MockCalled -commandName Unregister-IscsiSession -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -626,7 +626,7 @@ try Assert-MockCalled -commandName Disconnect-IscsiTarget -Exactly 0 Assert-MockCalled -commandName Register-IscsiSession -Exactly 1 Assert-MockCalled -commandName Unregister-IscsiSession -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -651,7 +651,7 @@ try Assert-MockCalled -commandName Disconnect-IscsiTarget -Exactly 0 Assert-MockCalled -commandName Register-IscsiSession -Exactly 1 Assert-MockCalled -commandName Unregister-IscsiSession -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -668,7 +668,7 @@ try Mock Disconnect-IscsiTarget Mock Register-IscsiSession Mock Unregister-IscsiSession - Mock Get-WMIObject + Mock Get-CimInstance Mock Set-WMIInstance Mock Remove-WMIObject It 'should not throw error' { @@ -688,7 +688,7 @@ try Assert-MockCalled -commandName Disconnect-IscsiTarget -Exactly 0 Assert-MockCalled -commandName Register-IscsiSession -Exactly 1 Assert-MockCalled -commandName Unregister-IscsiSession -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -705,7 +705,7 @@ try Mock Disconnect-IscsiTarget Mock Register-IscsiSession Mock Unregister-IscsiSession - Mock Get-WMIObject + Mock Get-CimInstance Mock Set-WMIInstance Mock Remove-WMIObject Mock Resolve-DNSName -MockWith { @@ -728,7 +728,7 @@ try Assert-MockCalled -commandName Disconnect-IscsiTarget -Exactly 0 Assert-MockCalled -commandName Register-IscsiSession -Exactly 1 Assert-MockCalled -commandName Unregister-IscsiSession -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 Assert-MockCalled -commandName Resolve-DNSName -Exactly 1 @@ -746,7 +746,7 @@ try Mock Disconnect-IscsiTarget Mock Register-IscsiSession Mock Unregister-IscsiSession - Mock Get-WMIObject + Mock Get-CimInstance Mock Set-WMIInstance Mock Remove-WMIObject Mock Resolve-DNSName -MockWith { @@ -769,7 +769,7 @@ try Assert-MockCalled -commandName Disconnect-IscsiTarget -Exactly 1 Assert-MockCalled -commandName Register-IscsiSession -Exactly 1 Assert-MockCalled -commandName Unregister-IscsiSession -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 Assert-MockCalled -commandName Resolve-DNSName -Exactly 1 @@ -787,7 +787,7 @@ try Mock Disconnect-IscsiTarget Mock Register-IscsiSession Mock Unregister-IscsiSession - Mock Get-WMIObject + Mock Get-CimInstance Mock Set-WMIInstance Mock Remove-WMIObject It 'should not throw error' { @@ -808,7 +808,7 @@ try Assert-MockCalled -commandName Disconnect-IscsiTarget -Exactly 1 Assert-MockCalled -commandName Register-IscsiSession -Exactly 1 Assert-MockCalled -commandName Unregister-IscsiSession -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -825,7 +825,7 @@ try Mock Disconnect-IscsiTarget Mock Register-IscsiSession Mock Unregister-IscsiSession - Mock Get-WMIObject + Mock Get-CimInstance Mock Set-WMIInstance Mock Remove-WMIObject It 'should not throw error' { @@ -845,7 +845,7 @@ try Assert-MockCalled -commandName Disconnect-IscsiTarget -Exactly 0 Assert-MockCalled -commandName Register-IscsiSession -Exactly 0 Assert-MockCalled -commandName Unregister-IscsiSession -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -862,7 +862,7 @@ try Mock Disconnect-IscsiTarget Mock Register-IscsiSession Mock Unregister-IscsiSession - Mock Get-WMIObject + Mock Get-CimInstance Mock Set-WMIInstance Mock Remove-WMIObject It 'should not throw error' { @@ -883,7 +883,7 @@ try Assert-MockCalled -commandName Disconnect-IscsiTarget -Exactly 0 Assert-MockCalled -commandName Register-IscsiSession -Exactly 0 Assert-MockCalled -commandName Unregister-IscsiSession -Exactly 1 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -900,7 +900,7 @@ try Mock Disconnect-IscsiTarget Mock Register-IscsiSession Mock Unregister-IscsiSession - Mock Get-WMIObject + Mock Get-CimInstance Mock Set-WMIInstance Mock Remove-WMIObject It 'should not throw error' { @@ -921,7 +921,7 @@ try Assert-MockCalled -commandName Disconnect-IscsiTarget -Exactly 1 Assert-MockCalled -commandName Register-IscsiSession -Exactly 0 Assert-MockCalled -commandName Unregister-IscsiSession -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -938,7 +938,7 @@ try Mock Disconnect-IscsiTarget Mock Register-IscsiSession Mock Unregister-IscsiSession - Mock Get-WMIObject + Mock Get-CimInstance Mock Set-WMIInstance Mock Remove-WMIObject It 'should not throw error' { @@ -959,7 +959,7 @@ try Assert-MockCalled -commandName Disconnect-IscsiTarget -Exactly 0 Assert-MockCalled -commandName Register-IscsiSession -Exactly 0 Assert-MockCalled -commandName Unregister-IscsiSession -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -976,7 +976,7 @@ try Mock Disconnect-IscsiTarget Mock Register-IscsiSession Mock Unregister-IscsiSession - Mock Get-WMIObject + Mock Get-CimInstance Mock Set-WMIInstance Mock Remove-WMIObject It 'should not throw error' { @@ -997,7 +997,7 @@ try Assert-MockCalled -commandName Disconnect-IscsiTarget -Exactly 1 Assert-MockCalled -commandName Register-IscsiSession -Exactly 0 Assert-MockCalled -commandName Unregister-IscsiSession -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -1014,7 +1014,7 @@ try Mock Disconnect-IscsiTarget Mock Register-IscsiSession Mock Unregister-IscsiSession - Mock Get-WMIObject + Mock Get-CimInstance Mock Set-WMIInstance Mock Remove-WMIObject It 'should not throw error' { @@ -1035,7 +1035,7 @@ try Assert-MockCalled -commandName Disconnect-IscsiTarget -Exactly 0 Assert-MockCalled -commandName Register-IscsiSession -Exactly 0 Assert-MockCalled -commandName Unregister-IscsiSession -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -1052,7 +1052,7 @@ try Mock Disconnect-IscsiTarget Mock Register-IscsiSession Mock Unregister-IscsiSession - Mock Get-WMIObject -MockWith { return @($MockiSNSSrver) } + Mock Get-CimInstance -MockWith { return @($MockiSNSSrver) } Mock Set-WMIInstance Mock Remove-WMIObject It 'should not throw error' { @@ -1073,7 +1073,7 @@ try Assert-MockCalled -commandName Disconnect-IscsiTarget -Exactly 0 Assert-MockCalled -commandName Register-IscsiSession -Exactly 0 Assert-MockCalled -commandName Unregister-IscsiSession -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 1 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -1090,7 +1090,7 @@ try Mock Disconnect-IscsiTarget Mock Register-IscsiSession Mock Unregister-IscsiSession - Mock Get-WMIObject + Mock Get-CimInstance Mock Set-WMIInstance Mock Remove-WMIObject It 'should not throw error' { @@ -1110,7 +1110,7 @@ try Assert-MockCalled -commandName Disconnect-IscsiTarget -Exactly 0 Assert-MockCalled -commandName Register-IscsiSession -Exactly 0 Assert-MockCalled -commandName Unregister-IscsiSession -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 1 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -1127,7 +1127,7 @@ try Mock Disconnect-IscsiTarget Mock Register-IscsiSession Mock Unregister-IscsiSession - Mock Get-WMIObject -MockWith { return @($MockiSNSSrver) } + Mock Get-CimInstance -MockWith { return @($MockiSNSSrver) } Mock Set-WMIInstance Mock Remove-WMIObject It 'should not throw error' { @@ -1148,7 +1148,7 @@ try Assert-MockCalled -commandName Disconnect-IscsiTarget -Exactly 0 Assert-MockCalled -commandName Register-IscsiSession -Exactly 0 Assert-MockCalled -commandName Unregister-IscsiSession -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 1 } @@ -1165,7 +1165,7 @@ try Mock Disconnect-IscsiTarget Mock Register-IscsiSession Mock Unregister-IscsiSession - Mock Get-WMIObject -MockWith { return @($MockiSNSSrver) } + Mock Get-CimInstance -MockWith { return @($MockiSNSSrver) } Mock Set-WMIInstance Mock Remove-WMIObject It 'should not throw error' { @@ -1186,7 +1186,7 @@ try Assert-MockCalled -commandName Disconnect-IscsiTarget -Exactly 0 Assert-MockCalled -commandName Register-IscsiSession -Exactly 0 Assert-MockCalled -commandName Unregister-IscsiSession -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 1 } @@ -1199,7 +1199,7 @@ try Mock Get-Target Mock Get-Connection Mock Get-Session - Mock Get-WMIObject + Mock Get-CimInstance It 'should return false' { $Splat = $TestInitiator.Clone() Test-TargetResource @Splat | Should -Be $False @@ -1209,7 +1209,7 @@ try Assert-MockCalled -commandName Get-Target -Exactly 0 Assert-MockCalled -commandName Get-Connection -Exactly 0 Assert-MockCalled -commandName Get-Session -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } @@ -1218,7 +1218,7 @@ try Mock Get-Target Mock Get-Connection Mock Get-Session - Mock Get-WMIObject + Mock Get-CimInstance It 'should return false' { $Splat = $TestInitiatorWithoutInitiatorAddress.Clone() Test-TargetResource @Splat | Should -Be $False @@ -1228,7 +1228,7 @@ try Assert-MockCalled -commandName Get-Target -Exactly 0 Assert-MockCalled -commandName Get-Connection -Exactly 0 Assert-MockCalled -commandName Get-Session -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } @@ -1237,7 +1237,7 @@ try Mock Get-Target Mock Get-Connection Mock Get-Session - Mock Get-WMIObject + Mock Get-CimInstance It 'should return false' { $Splat = $TestInitiator.Clone() Test-TargetResource @Splat | Should -Be $False @@ -1247,7 +1247,7 @@ try Assert-MockCalled -commandName Get-Target -Exactly 1 Assert-MockCalled -commandName Get-Connection -Exactly 0 Assert-MockCalled -commandName Get-Session -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } @@ -1256,7 +1256,7 @@ try Mock Get-Target -MockWith { return @($MockTargetNotConnected) } Mock Get-Connection Mock Get-Session - Mock Get-WMIObject + Mock Get-CimInstance It 'should return false' { $Splat = $TestInitiator.Clone() Test-TargetResource @Splat | Should -Be $False @@ -1266,7 +1266,7 @@ try Assert-MockCalled -commandName Get-Target -Exactly 1 Assert-MockCalled -commandName Get-Connection -Exactly 0 Assert-MockCalled -commandName Get-Session -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } @@ -1275,7 +1275,7 @@ try Mock Get-Target -MockWith { return @($MockTargetNotConnected) } Mock Get-Connection Mock Get-Session - Mock Get-WMIObject + Mock Get-CimInstance It 'should return false' { $Splat = $TestInitiatorWithoutInitiatorAddress.Clone() Test-TargetResource @Splat | Should -Be $False @@ -1285,7 +1285,7 @@ try Assert-MockCalled -commandName Get-Target -Exactly 1 Assert-MockCalled -commandName Get-Connection -Exactly 0 Assert-MockCalled -commandName Get-Session -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } @@ -1293,7 +1293,7 @@ try Mock Get-Target -MockWith { return @($MockTarget) } Mock Get-Connection Mock Get-Session - Mock Get-WMIObject + Mock Get-CimInstance Context 'Target Portal does exist and should but TargetPortalPortNumber is different' { It 'should return false' { @@ -1306,7 +1306,7 @@ try Assert-MockCalled -commandName Get-Target -Exactly 1 Assert-MockCalled -commandName Get-Connection -Exactly 1 Assert-MockCalled -commandName Get-Session -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } @@ -1321,7 +1321,7 @@ try Assert-MockCalled -commandName Get-Target -Exactly 1 Assert-MockCalled -commandName Get-Connection -Exactly 1 Assert-MockCalled -commandName Get-Session -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } @@ -1336,7 +1336,7 @@ try Assert-MockCalled -commandName Get-Target -Exactly 1 Assert-MockCalled -commandName Get-Connection -Exactly 1 Assert-MockCalled -commandName Get-Session -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } @@ -1351,7 +1351,7 @@ try Assert-MockCalled -commandName Get-Target -Exactly 1 Assert-MockCalled -commandName Get-Connection -Exactly 1 Assert-MockCalled -commandName Get-Session -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } @@ -1360,7 +1360,7 @@ try Mock Get-Target -MockWith { return @($MockTarget) } Mock Get-Connection -MockWith { return @($MockConnection) } Mock Get-Session -MockWith { return @($MockSessionPersistent) } - Mock Get-WMIObject + Mock Get-CimInstance Mock Resolve-DNSName -MockWith { return @( @{ IPAddress = $MockConnection.TargetAddress } ) } @@ -1373,7 +1373,7 @@ try Assert-MockCalled -commandName Get-Target -Exactly 1 Assert-MockCalled -commandName Get-Connection -Exactly 1 Assert-MockCalled -commandName Get-Session -Exactly 1 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Resolve-DNSName -Exactly 1 } } @@ -1383,7 +1383,7 @@ try Mock Get-Target -MockWith { return @($MockTarget) } Mock Get-Connection -MockWith { return @($MockConnection) } Mock Get-Session -MockWith { return @($MockSessionPersistent) } - Mock Get-WMIObject + Mock Get-CimInstance Mock Resolve-DNSName -MockWith { return @( @{ IPAddress = '1.1.1.1' } ) } @@ -1396,7 +1396,7 @@ try Assert-MockCalled -commandName Get-Target -Exactly 1 Assert-MockCalled -commandName Get-Connection -Exactly 1 Assert-MockCalled -commandName Get-Session -Exactly 1 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Resolve-DNSName -Exactly 1 } } @@ -1406,7 +1406,7 @@ try Mock Get-Target -MockWith { return @($MockTarget) } Mock Get-Connection -MockWith { return @($MockConnection) } Mock Get-Session -MockWith { return @($MockSession) } - Mock Get-WMIObject + Mock Get-CimInstance It 'should return false' { $Splat = $TestInitiator.Clone() $Splat.AuthenticationType = 'None' @@ -1417,7 +1417,7 @@ try Assert-MockCalled -commandName Get-Target -Exactly 1 Assert-MockCalled -commandName Get-Connection -Exactly 1 Assert-MockCalled -commandName Get-Session -Exactly 1 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } @@ -1426,7 +1426,7 @@ try Mock Get-Target -MockWith { return @($MockTarget) } Mock Get-Connection -MockWith { return @($MockConnection) } Mock Get-Session -MockWith { return @($MockSessionPersistent) } - Mock Get-WMIObject + Mock Get-CimInstance It 'should return true' { $Splat = $TestInitiator.Clone() Test-TargetResource @Splat | Should -Be $True @@ -1436,7 +1436,7 @@ try Assert-MockCalled -commandName Get-Target -Exactly 1 Assert-MockCalled -commandName Get-Connection -Exactly 1 Assert-MockCalled -commandName Get-Session -Exactly 1 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } @@ -1445,7 +1445,7 @@ try Mock Get-Target -MockWith { return @($MockTarget) } Mock Get-Connection -MockWith { return @($MockConnection) } Mock Get-Session -MockWith { return @($MockSessionPersistent) } - Mock Get-WMIObject + Mock Get-CimInstance It 'should return false' { $Splat = $TestInitiator.Clone() $Splat.IsPersistent = $False @@ -1456,7 +1456,7 @@ try Assert-MockCalled -commandName Get-Target -Exactly 1 Assert-MockCalled -commandName Get-Connection -Exactly 1 Assert-MockCalled -commandName Get-Session -Exactly 1 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } @@ -1465,7 +1465,7 @@ try Mock Get-Target -MockWith { return @($MockTarget) } Mock Get-Connection Mock Get-Session - Mock Get-WMIObject + Mock Get-CimInstance It 'should return false' { $Splat = $TestInitiator.Clone() $Splat.Ensure = 'Absent' @@ -1476,7 +1476,7 @@ try Assert-MockCalled -commandName Get-Target -Exactly 1 Assert-MockCalled -commandName Get-Connection -Exactly 0 Assert-MockCalled -commandName Get-Session -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } @@ -1485,7 +1485,7 @@ try Mock Get-Target -MockWith { return @($MockTargetNotConnected) } Mock Get-Connection Mock Get-Session - Mock Get-WMIObject + Mock Get-CimInstance It 'should return false' { $Splat = $TestInitiator.Clone() $Splat.Ensure = 'Absent' @@ -1496,7 +1496,7 @@ try Assert-MockCalled -commandName Get-Target -Exactly 1 Assert-MockCalled -commandName Get-Connection -Exactly 0 Assert-MockCalled -commandName Get-Session -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } @@ -1505,7 +1505,7 @@ try Mock Get-Target -MockWith { return @($MockTarget) } Mock Get-Connection Mock Get-Session - Mock Get-WMIObject + Mock Get-CimInstance It 'should return false' { $Splat = $TestInitiator.Clone() $Splat.Ensure = 'Absent' @@ -1516,7 +1516,7 @@ try Assert-MockCalled -commandName Get-Target -Exactly 1 Assert-MockCalled -commandName Get-Connection -Exactly 0 Assert-MockCalled -commandName Get-Session -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } @@ -1525,7 +1525,7 @@ try Mock Get-Target Mock Get-Connection Mock Get-Session - Mock Get-WMIObject + Mock Get-CimInstance It 'should return true' { $Splat = $TestInitiator.Clone() $Splat.Ensure = 'Absent' @@ -1536,7 +1536,7 @@ try Assert-MockCalled -commandName Get-Target -Exactly 1 Assert-MockCalled -commandName Get-Connection -Exactly 0 Assert-MockCalled -commandName Get-Session -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } @@ -1545,7 +1545,7 @@ try Mock Get-Target -MockWith { return @($MockTarget) } Mock Get-Connection -MockWith { return @($MockConnection) } Mock Get-Session -MockWith { return @($MockSessionPersistent) } - Mock Get-WMIObject + Mock Get-CimInstance It 'should return false' { $Splat = $TestInitiatorWithiSNS.Clone() Test-TargetResource @Splat | Should -Be $False @@ -1555,7 +1555,7 @@ try Assert-MockCalled -commandName Get-Target -Exactly 1 Assert-MockCalled -commandName Get-Connection -Exactly 1 Assert-MockCalled -commandName Get-Session -Exactly 1 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } @@ -1564,7 +1564,7 @@ try Mock Get-Target -MockWith { return @($MockTarget) } Mock Get-Connection -MockWith { return @($MockConnection) } Mock Get-Session -MockWith { return @($MockSessionPersistent) } - Mock Get-WMIObject -MockWith { return @($MockiSNSSrver) } + Mock Get-CimInstance -MockWith { return @($MockiSNSSrver) } It 'should return false' { $Splat = $TestInitiatorWithiSNS.Clone() $Splat.iSNSServer = 'different.contoso.com' @@ -1575,7 +1575,7 @@ try Assert-MockCalled -commandName Get-Target -Exactly 1 Assert-MockCalled -commandName Get-Connection -Exactly 1 Assert-MockCalled -commandName Get-Session -Exactly 1 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } @@ -1584,7 +1584,7 @@ try Mock Get-Target -MockWith { return @($MockTarget) } Mock Get-Connection -MockWith { return @($MockConnection) } Mock Get-Session -MockWith { return @($MockSessionPersistent) } - Mock Get-WMIObject -MockWith { return @($MockiSNSSrver) } + Mock Get-CimInstance -MockWith { return @($MockiSNSSrver) } It 'should return false' { $Splat = $TestInitiatorWithiSNS.Clone() $Splat.iSNSServer = '' @@ -1595,7 +1595,7 @@ try Assert-MockCalled -commandName Get-Target -Exactly 1 Assert-MockCalled -commandName Get-Connection -Exactly 1 Assert-MockCalled -commandName Get-Session -Exactly 1 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } @@ -1604,7 +1604,7 @@ try Mock Get-Target Mock Get-Connection Mock Get-Session - Mock Get-WMIObject -MockWith { return @($MockiSNSSrver) } + Mock Get-CimInstance -MockWith { return @($MockiSNSSrver) } It 'should return false' { $Splat = $TestInitiator.Clone() $Splat.Ensure = 'Absent' @@ -1615,7 +1615,7 @@ try Assert-MockCalled -commandName Get-Target -Exactly 1 Assert-MockCalled -commandName Get-Connection -Exactly 0 Assert-MockCalled -commandName Get-Session -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } } From 55222568db0dab8ff3695d8b7b47703eabce0e33 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sat, 23 Jun 2018 22:46:13 +0100 Subject: [PATCH 09/16] Revoved extraneous data --- .../DSR_iSCSIInitiator.psd1 | Bin 8194 -> 1568 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/DSR_iSCSIInitiator.psd1 b/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/DSR_iSCSIInitiator.psd1 index ff44fcf09e30bcf591a2cab331450c3ea8e0fe18..2aa8b3c288af0a04a967a57ac6db02794426e709 100644 GIT binary patch literal 1568 zcmc&z!EW0y487|sh;~3WAaU&^?b-qbRwP@NL$RXny32q;w&_HGExD51%oz6Xqhu#_ zlcC4$;Df2h$45T$m>t87%IX54Z=VO^AnZVSGu@$(lCo~f$QVzstlEX}7R0p7EA zLcS69jG^qe={s-+z?LR}>!JY9VL+on{e)TI$>(UiIc`Q?4nkhb)Y3mMgl(YG>WP|m z#=q#fpGY<7S7<`TP9n^d%*Cpvjd8qGQPnynX6o6l{p#^m+X&V4`vzjWaKI&voa+@@ zNc%iq?+xL~x`e0B*G}^{Av3ixaH}?`<26#dC|5!v6@RR~vOWFJ$e#PBLF><_ZUn}8 zk3TD=Y2;d!{Rs?xJBhoX3N^Jx2bJOwG6hmuw>h-PMV4}%8Q)X)kYRx|A~y$eQa3{n zR(1G#? zt_4pDd`&ysfezBI3&G8+$^X+S+|EW4{^u1LSTRLI3~& literal 8194 zcmeI1Yi}Dx6o%(B692&>NKO$=n>H;J38_)iw2^vKofJMGA;*_sn%Ks6n^vfQ9eAHP zKA9cwZeoW<@S$3*_cn9pJ@<3QfB&@>z6@W4wa^I9!YFjZ+i((kdO8j5Fbspx*V8o2 z^ro-xllY}Lt{HYiE4&K7YHTa)=-k)A%$d%%ewo#rui|Sx7S*B7NgUDBx{YuYK7=21 zeJKR(a4aOf@Fctlw?uO!JU#s~=T6vKf*NC?c01e^h1=o2e(&hI8NM&f2G7IrXME$> zTA?FcgD{R8k?zZ&ywkY$i8@`i`-W2^!9X(lTH$2dlu(jU_-%wbWLz2^YF8=Xrm(`&tz0o-eXZkI# zKGwQ;=CL>@A`zF+eJ@f$KPgJpYX}UBluRb;@~0c3;c;TQShS%T+p?4sT@yO|dLm@l z)+8XMt}H(1X*YgPKI~qX^oeZx(IPwI&c3&`65fDijzxPU>Sm!HMf2E_+h^UHCIS08 zh{&PV(mE#LhGIM3M|>kTTjX}c#_1@&?})2h4=JAz*NfURPE+Q<*A{a}LkO@ixFY64 z0Zn&m@#Io|Hm7+ibf=n!E+*28W6!1iQyh&wpJ@yhz#TJMvN|FHddB9D<4Aaed*Vfs z8@cQvEmTphj+ggjHH+S#{N^gyi5iyCSI50pBatU_nhBZN)AeiOI=QLV$W?g42Jv$w zkIt~)jqqHV?Lc>X`eKprOkXF8fvegSG3emDo**hfKBn;;Uu;KAmJ8H__l!ht(}qka*}@ zU5OXSle|t0wT!c_c=l9vEAc)_io46A=>JdF#>p}=eJNh4NYN&iNIg$X?L^zbM#wWn zcVxCM{UOg@_*PFpt0uW0@3tkwuI{(4AU(H_GLr3D9M!QT2kvS_)#!_T3K7RTBsf@C#Gn(|jFyyi zh)pK1wW`2$%-fE5BM%efno$zu<4>)z6w8YEr;4*9MaiNc)oJZO5pf*(sOI^-^m#Jp zoX*4SHP_u)jLY<5tJ|8dzY6BPXy0`Ic+h`?yNF>G?2Eos_EDl8c1KJjMwow)HN3~? zYhG0qztVG{QF?l0WApL+hH^={U%!=g?`6yJs6d`{Jd0dZ`_x{{XQ?Z&cz_l4!u#`h zhX%1!>R!Cd_Zt$wM0T$Mus@5O@Hm;jx1Atz24ks=kssOJd*_BKWPG|CJ#(TfXuN9A zXAqO{T&qVs{#tjtvr--mhf`<*$O+P=i%>}HH;O`%_J3uIb|?=26-A|J2Ba^msLpl?lcz4ZfQrIob^TY zI@LSUDMR=Q#k`bOtIkg8dyb}9Ph1_zUd%Q<^>5@ec&NxT9qTmUN_1|uW81CP#s6Dv}LX17-6l>nnej! z*D)?ve3u%)_UhQHNcNrU6)EBG?4MFWSWQ7CXS*55A4;3J97Ve|;!Z%_HuXZZDEY*?*X zCp)7@Lg@QTWt8-uqwu@NQHj+{&N?a|_wR60dD1W04zcA3aF}h_F3?52dOgbhIn7n@ zkrAkPEf2DzLNp@kq&}lum)GgDo*EX{EL5ki%a3}GJ|9Uc#Cuyc_seojVSUcJ*~Q43 zqCh Date: Sat, 23 Jun 2018 22:51:42 +0100 Subject: [PATCH 10/16] Updated with changes --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b914e4..9ee7d07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ - Enabled PSSA rule violations to fail build - Fixes [Issue #27](https://github.com/PlagueHO/iSCSIDsc/issues/27). - Updated tests to meet Pester v4 standard. - Added Open Code of Conduct. +- Simplify Initiator code layout by moving exposed DSC functions into own files +- Added Module manifest +- Changed Get-WMIObject for Get-CimInstance within DSR_iSCSIServerTarget.psm1. - Fixes [Issue #18](https://github.com/PlagueHO/iSCSIDsc/issues/18) ## 1.5.0.0 From 5e6ef7d064544726f3eea2de6c6a16f8837c007f Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sat, 23 Jun 2018 23:19:49 +0100 Subject: [PATCH 11/16] Updated Tests --- Tests/Unit/DSR_iSCSIServerTarget.Tests.ps1 | 92 +++++++++++----------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/Tests/Unit/DSR_iSCSIServerTarget.Tests.ps1 b/Tests/Unit/DSR_iSCSIServerTarget.Tests.ps1 index 434e779..6fdaa7d 100644 --- a/Tests/Unit/DSR_iSCSIServerTarget.Tests.ps1 +++ b/Tests/Unit/DSR_iSCSIServerTarget.Tests.ps1 @@ -97,7 +97,7 @@ try Context 'Server Target does not exist' { Mock Get-iSCSIServerTarget - Mock Get-WMIObject + Mock Get-CimInstance It 'should return absent Server Target' { $Result = Get-TargetResource ` @@ -109,14 +109,14 @@ try } It 'should call the expected mocks' { Assert-MockCalled -commandName Get-iSCSIServerTarget -Exactly 1 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-Cimnstance -Exactly 1 } } Context 'Server Target exists and iSNS Server not set' { Mock Get-iSCSIServerTarget -MockWith { return @($MockServerTarget) } - Mock Get-WMIObject + Mock Get-CimInstance It 'should return correct Server Target' { $Result = Get-TargetResource ` @@ -130,14 +130,14 @@ try } It 'should call the expected mocks' { Assert-MockCalled -commandName Get-iSCSIServerTarget -Exactly 1 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } Context 'Server Target exists and iSNS Server set' { Mock Get-iSCSIServerTarget -MockWith { return @($MockServerTarget) } - Mock Get-WMIObject -MockWith { return @($MockiSNSSrver) } + Mock Get-CimInstance -MockWith { return @($MockiSNSSrver) } It 'should return correct Server Target' { $Result = Get-TargetResource ` @@ -151,7 +151,7 @@ try } It 'should call the expected mocks' { Assert-MockCalled -commandName Get-iSCSIServerTarget -Exactly 1 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } } @@ -166,7 +166,7 @@ try Mock Remove-iSCSIServerTarget Mock Add-IscsiVirtualDiskTargetMapping Mock Remove-IscsiVirtualDiskTargetMapping - Mock Get-WMIObject + Mock Get-CimInstance Mock Set-WMIInstance Mock Remove-WMIObject @@ -183,7 +183,7 @@ try Assert-MockCalled -commandName Remove-iSCSIServerTarget -Exactly 0 Assert-MockCalled -commandName Add-IscsiVirtualDiskTargetMapping -Exactly 1 Assert-MockCalled -commandName Remove-IscsiVirtualDiskTargetMapping -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -197,7 +197,7 @@ try Mock Remove-iSCSIServerTarget Mock Add-IscsiVirtualDiskTargetMapping Mock Remove-IscsiVirtualDiskTargetMapping - Mock Get-WMIObject + Mock Get-CimInstance Mock Set-WMIInstance Mock Remove-WMIObject @@ -215,7 +215,7 @@ try Assert-MockCalled -commandName Remove-iSCSIServerTarget -Exactly 0 Assert-MockCalled -commandName Add-IscsiVirtualDiskTargetMapping -Exactly 1 Assert-MockCalled -commandName Remove-IscsiVirtualDiskTargetMapping -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -229,7 +229,7 @@ try Mock Remove-iSCSIServerTarget Mock Add-IscsiVirtualDiskTargetMapping Mock Remove-IscsiVirtualDiskTargetMapping - Mock Get-WMIObject + Mock Get-CimInstance Mock Set-WMIInstance Mock Remove-WMIObject @@ -247,7 +247,7 @@ try Assert-MockCalled -commandName Remove-iSCSIServerTarget -Exactly 0 Assert-MockCalled -commandName Add-IscsiVirtualDiskTargetMapping -Exactly 1 Assert-MockCalled -commandName Remove-IscsiVirtualDiskTargetMapping -Exactly 1 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -261,7 +261,7 @@ try Mock Remove-iSCSIServerTarget Mock Add-IscsiVirtualDiskTargetMapping Mock Remove-IscsiVirtualDiskTargetMapping - Mock Get-WMIObject + Mock Get-CimInstnace Mock Set-WMIInstance Mock Remove-WMIObject @@ -279,7 +279,7 @@ try Assert-MockCalled -commandName Remove-iSCSIServerTarget -Exactly 0 Assert-MockCalled -commandName Add-IscsiVirtualDiskTargetMapping -Exactly 0 Assert-MockCalled -commandName Remove-IscsiVirtualDiskTargetMapping -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -293,7 +293,7 @@ try Mock Remove-iSCSIServerTarget Mock Add-IscsiVirtualDiskTargetMapping Mock Remove-IscsiVirtualDiskTargetMapping - Mock Get-WMIObject + Mock Get-CimInstnace Mock Set-WMIInstance Mock Remove-WMIObject @@ -311,7 +311,7 @@ try Assert-MockCalled -commandName Remove-iSCSIServerTarget -Exactly 1 Assert-MockCalled -commandName Add-IscsiVirtualDiskTargetMapping -Exactly 0 Assert-MockCalled -commandName Remove-IscsiVirtualDiskTargetMapping -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -325,7 +325,7 @@ try Mock Remove-iSCSIServerTarget Mock Add-IscsiVirtualDiskTargetMapping Mock Remove-IscsiVirtualDiskTargetMapping - Mock Get-WMIObject + Mock Get-CimInstnace Mock Set-WMIInstance Mock Remove-WMIObject @@ -343,7 +343,7 @@ try Assert-MockCalled -commandName Remove-iSCSIServerTarget -Exactly 0 Assert-MockCalled -commandName Add-IscsiVirtualDiskTargetMapping -Exactly 0 Assert-MockCalled -commandName Remove-IscsiVirtualDiskTargetMapping -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -357,7 +357,7 @@ try Mock Remove-iSCSIServerTarget Mock Add-IscsiVirtualDiskTargetMapping Mock Remove-IscsiVirtualDiskTargetMapping - Mock Get-WMIObject -MockWith { return @($MockiSNSSrver) } + Mock Get-CimInstnace -MockWith { return @($MockiSNSSrver) } Mock Set-WMIInstance Mock Remove-WMIObject @@ -375,7 +375,7 @@ try Assert-MockCalled -commandName Remove-iSCSIServerTarget -Exactly 0 Assert-MockCalled -commandName Add-IscsiVirtualDiskTargetMapping -Exactly 0 Assert-MockCalled -commandName Remove-IscsiVirtualDiskTargetMapping -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 1 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -389,7 +389,7 @@ try Mock Remove-iSCSIServerTarget Mock Add-IscsiVirtualDiskTargetMapping Mock Remove-IscsiVirtualDiskTargetMapping - Mock Get-WMIObject + Mock Get-CimInstnace Mock Set-WMIInstance Mock Remove-WMIObject @@ -406,7 +406,7 @@ try Assert-MockCalled -commandName Remove-iSCSIServerTarget -Exactly 0 Assert-MockCalled -commandName Add-IscsiVirtualDiskTargetMapping -Exactly 0 Assert-MockCalled -commandName Remove-IscsiVirtualDiskTargetMapping -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 1 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -420,7 +420,7 @@ try Mock Remove-iSCSIServerTarget Mock Add-IscsiVirtualDiskTargetMapping Mock Remove-IscsiVirtualDiskTargetMapping - Mock Get-WMIObject -MockWith { return @($MockiSNSSrver) } + Mock Get-CimInstnace -MockWith { return @($MockiSNSSrver) } Mock Set-WMIInstance Mock Remove-WMIObject @@ -438,7 +438,7 @@ try Assert-MockCalled -commandName Remove-iSCSIServerTarget -Exactly 0 Assert-MockCalled -commandName Add-IscsiVirtualDiskTargetMapping -Exactly 0 Assert-MockCalled -commandName Remove-IscsiVirtualDiskTargetMapping -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 1 } @@ -452,7 +452,7 @@ try Mock Remove-iSCSIServerTarget Mock Add-IscsiVirtualDiskTargetMapping Mock Remove-IscsiVirtualDiskTargetMapping - Mock Get-WMIObject -MockWith { return @($MockiSNSSrver) } + Mock Get-CimInstnace -MockWith { return @($MockiSNSSrver) } Mock Set-WMIInstance Mock Remove-WMIObject @@ -470,7 +470,7 @@ try Assert-MockCalled -commandName Remove-iSCSIServerTarget -Exactly 0 Assert-MockCalled -commandName Add-IscsiVirtualDiskTargetMapping -Exactly 0 Assert-MockCalled -commandName Remove-IscsiVirtualDiskTargetMapping -Exactly 0 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 1 } @@ -482,7 +482,7 @@ try Context 'Server Target does not exist but should' { Mock Get-iSCSIServerTarget - Mock Get-WMIObject + Mock Get-CimInstnace It 'should return false' { $Splat = $TestServerTarget.Clone() @@ -490,14 +490,14 @@ try } It 'should call expected Mocks' { Assert-MockCalled -commandName Get-iSCSIServerTarget -Exactly 1 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 } } Context 'Server Target exists and should but has a different Paths' { Mock Get-iSCSIServerTarget -MockWith { return @($MockServerTarget) } - Mock Get-WMIObject + Mock Get-CimInstnace It 'should return false' { $Splat = $TestServerTarget.Clone() @@ -506,14 +506,14 @@ try } It 'should call expected Mocks' { Assert-MockCalled -commandName Get-iSCSIServerTarget -Exactly 1 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 } } Context 'Server Target exists and should but has a different InitiatorIds' { Mock Get-iSCSIServerTarget -MockWith { return @($MockServerTarget) } - Mock Get-WMIObject + Mock Get-CimInstnace It 'should return false' { $Splat = $TestServerTarget.Clone() @@ -522,14 +522,14 @@ try } It 'should call expected Mocks' { Assert-MockCalled -commandName Get-iSCSIServerTarget -Exactly 1 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 } } Context 'Server Target exists and should and all parameters match' { Mock Get-iSCSIServerTarget -MockWith { return @($MockServerTarget) } - Mock Get-WMIObject + Mock Get-CimInstnace It 'should return true' { $Splat = $TestServerTarget.Clone() @@ -537,14 +537,14 @@ try } It 'should call expected Mocks' { Assert-MockCalled -commandName Get-iSCSIServerTarget -Exactly 1 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 } } Context 'Server Target exists but should not' { Mock Get-iSCSIServerTarget -MockWith { return @($MockServerTarget) } - Mock Get-WMIObject + Mock Get-CimInstnace It 'should return false' { $Splat = $TestServerTarget.Clone() @@ -553,14 +553,14 @@ try } It 'should call expected Mocks' { Assert-MockCalled -commandName Get-iSCSIServerTarget -Exactly 1 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 } } Context 'Server Target does not exist and should not' { Mock Get-iSCSIServerTarget - Mock Get-WMIObject + Mock Get-CimInstnace It 'should return true' { $Splat = $TestServerTarget.Clone() @@ -569,14 +569,14 @@ try } It 'should call expected Mocks' { Assert-MockCalled -commandName Get-iSCSIServerTarget -Exactly 1 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 } } Context 'Server Target exists and should and iSNS Server is not set' { Mock Get-iSCSIServerTarget -MockWith { return @($MockServerTarget) } - Mock Get-WMIObject + Mock Get-CimInstnace It 'should return false' { $Splat = $TestServerTargetWithiSNS.Clone() @@ -584,14 +584,14 @@ try } It 'should call expected Mocks' { Assert-MockCalled -commandName Get-iSCSIServerTarget -Exactly 1 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 } } Context 'Server Target exists and should and iSNS Server is different' { Mock Get-iSCSIServerTarget -MockWith { return @($MockServerTarget) } - Mock Get-WMIObject -MockWith { return @($MockiSNSSrver) } + Mock Get-CimInstnace -MockWith { return @($MockiSNSSrver) } It 'should return false' { $Splat = $TestServerTargetWithiSNS.Clone() @@ -600,14 +600,14 @@ try } It 'should call expected Mocks' { Assert-MockCalled -commandName Get-iSCSIServerTarget -Exactly 1 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 } } Context 'Server Target exists and should and iSNS Server should be cleared' { Mock Get-iSCSIServerTarget -MockWith { return @($MockServerTarget) } - Mock Get-WMIObject -MockWith { return @($MockiSNSSrver) } + Mock Get-CimInstnace -MockWith { return @($MockiSNSSrver) } It 'should return false' { $Splat = $TestServerTargetWithiSNS.Clone() @@ -616,14 +616,14 @@ try } It 'should call expected Mocks' { Assert-MockCalled -commandName Get-iSCSIServerTarget -Exactly 1 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 } } Context 'Server Target does not exist and should not but iSNS Server is set' { Mock Get-iSCSIServerTarget - Mock Get-WMIObject -MockWith { return @($MockiSNSSrver) } + Mock Get-CimInstnace -MockWith { return @($MockiSNSSrver) } It 'should return false' { $Splat = $TestServerTarget.Clone() @@ -632,7 +632,7 @@ try } It 'should call expected Mocks' { Assert-MockCalled -commandName Get-iSCSIServerTarget -Exactly 1 - Assert-MockCalled -commandName Get-WMIObject -Exactly 1 + Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 } } } From c7a369b95f19425809ab6a3e0c765468ff473a94 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Mon, 25 Jun 2018 19:26:55 +0100 Subject: [PATCH 12/16] Fix find replace error --- Tests/Unit/DSR_iSCSIServerTarget.Tests.ps1 | 70 +++++++++++----------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/Tests/Unit/DSR_iSCSIServerTarget.Tests.ps1 b/Tests/Unit/DSR_iSCSIServerTarget.Tests.ps1 index 6fdaa7d..4065b3d 100644 --- a/Tests/Unit/DSR_iSCSIServerTarget.Tests.ps1 +++ b/Tests/Unit/DSR_iSCSIServerTarget.Tests.ps1 @@ -247,7 +247,7 @@ try Assert-MockCalled -commandName Remove-iSCSIServerTarget -Exactly 0 Assert-MockCalled -commandName Add-IscsiVirtualDiskTargetMapping -Exactly 1 Assert-MockCalled -commandName Remove-IscsiVirtualDiskTargetMapping -Exactly 1 - Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -261,7 +261,7 @@ try Mock Remove-iSCSIServerTarget Mock Add-IscsiVirtualDiskTargetMapping Mock Remove-IscsiVirtualDiskTargetMapping - Mock Get-CimInstnace + Mock Get-CimInstance Mock Set-WMIInstance Mock Remove-WMIObject @@ -279,7 +279,7 @@ try Assert-MockCalled -commandName Remove-iSCSIServerTarget -Exactly 0 Assert-MockCalled -commandName Add-IscsiVirtualDiskTargetMapping -Exactly 0 Assert-MockCalled -commandName Remove-IscsiVirtualDiskTargetMapping -Exactly 0 - Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -293,7 +293,7 @@ try Mock Remove-iSCSIServerTarget Mock Add-IscsiVirtualDiskTargetMapping Mock Remove-IscsiVirtualDiskTargetMapping - Mock Get-CimInstnace + Mock Get-CimInstance Mock Set-WMIInstance Mock Remove-WMIObject @@ -311,7 +311,7 @@ try Assert-MockCalled -commandName Remove-iSCSIServerTarget -Exactly 1 Assert-MockCalled -commandName Add-IscsiVirtualDiskTargetMapping -Exactly 0 Assert-MockCalled -commandName Remove-IscsiVirtualDiskTargetMapping -Exactly 0 - Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -325,7 +325,7 @@ try Mock Remove-iSCSIServerTarget Mock Add-IscsiVirtualDiskTargetMapping Mock Remove-IscsiVirtualDiskTargetMapping - Mock Get-CimInstnace + Mock Get-CimInstance Mock Set-WMIInstance Mock Remove-WMIObject @@ -343,7 +343,7 @@ try Assert-MockCalled -commandName Remove-iSCSIServerTarget -Exactly 0 Assert-MockCalled -commandName Add-IscsiVirtualDiskTargetMapping -Exactly 0 Assert-MockCalled -commandName Remove-IscsiVirtualDiskTargetMapping -Exactly 0 - Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -357,7 +357,7 @@ try Mock Remove-iSCSIServerTarget Mock Add-IscsiVirtualDiskTargetMapping Mock Remove-IscsiVirtualDiskTargetMapping - Mock Get-CimInstnace -MockWith { return @($MockiSNSSrver) } + Mock Get-CimInstance -MockWith { return @($MockiSNSSrver) } Mock Set-WMIInstance Mock Remove-WMIObject @@ -375,7 +375,7 @@ try Assert-MockCalled -commandName Remove-iSCSIServerTarget -Exactly 0 Assert-MockCalled -commandName Add-IscsiVirtualDiskTargetMapping -Exactly 0 Assert-MockCalled -commandName Remove-IscsiVirtualDiskTargetMapping -Exactly 0 - Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 1 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -389,7 +389,7 @@ try Mock Remove-iSCSIServerTarget Mock Add-IscsiVirtualDiskTargetMapping Mock Remove-IscsiVirtualDiskTargetMapping - Mock Get-CimInstnace + Mock Get-CimInstance Mock Set-WMIInstance Mock Remove-WMIObject @@ -406,7 +406,7 @@ try Assert-MockCalled -commandName Remove-iSCSIServerTarget -Exactly 0 Assert-MockCalled -commandName Add-IscsiVirtualDiskTargetMapping -Exactly 0 Assert-MockCalled -commandName Remove-IscsiVirtualDiskTargetMapping -Exactly 0 - Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 1 Assert-MockCalled -commandName Remove-WMIObject -Exactly 0 } @@ -420,7 +420,7 @@ try Mock Remove-iSCSIServerTarget Mock Add-IscsiVirtualDiskTargetMapping Mock Remove-IscsiVirtualDiskTargetMapping - Mock Get-CimInstnace -MockWith { return @($MockiSNSSrver) } + Mock Get-CimInstance -MockWith { return @($MockiSNSSrver) } Mock Set-WMIInstance Mock Remove-WMIObject @@ -438,7 +438,7 @@ try Assert-MockCalled -commandName Remove-iSCSIServerTarget -Exactly 0 Assert-MockCalled -commandName Add-IscsiVirtualDiskTargetMapping -Exactly 0 Assert-MockCalled -commandName Remove-IscsiVirtualDiskTargetMapping -Exactly 0 - Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 1 } @@ -452,7 +452,7 @@ try Mock Remove-iSCSIServerTarget Mock Add-IscsiVirtualDiskTargetMapping Mock Remove-IscsiVirtualDiskTargetMapping - Mock Get-CimInstnace -MockWith { return @($MockiSNSSrver) } + Mock Get-CimInstance -MockWith { return @($MockiSNSSrver) } Mock Set-WMIInstance Mock Remove-WMIObject @@ -470,7 +470,7 @@ try Assert-MockCalled -commandName Remove-iSCSIServerTarget -Exactly 0 Assert-MockCalled -commandName Add-IscsiVirtualDiskTargetMapping -Exactly 0 Assert-MockCalled -commandName Remove-IscsiVirtualDiskTargetMapping -Exactly 0 - Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 Assert-MockCalled -commandName Set-WMIInstance -Exactly 0 Assert-MockCalled -commandName Remove-WMIObject -Exactly 1 } @@ -482,7 +482,7 @@ try Context 'Server Target does not exist but should' { Mock Get-iSCSIServerTarget - Mock Get-CimInstnace + Mock Get-CimInstance It 'should return false' { $Splat = $TestServerTarget.Clone() @@ -490,14 +490,14 @@ try } It 'should call expected Mocks' { Assert-MockCalled -commandName Get-iSCSIServerTarget -Exactly 1 - Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } Context 'Server Target exists and should but has a different Paths' { Mock Get-iSCSIServerTarget -MockWith { return @($MockServerTarget) } - Mock Get-CimInstnace + Mock Get-CimInstance It 'should return false' { $Splat = $TestServerTarget.Clone() @@ -506,14 +506,14 @@ try } It 'should call expected Mocks' { Assert-MockCalled -commandName Get-iSCSIServerTarget -Exactly 1 - Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } Context 'Server Target exists and should but has a different InitiatorIds' { Mock Get-iSCSIServerTarget -MockWith { return @($MockServerTarget) } - Mock Get-CimInstnace + Mock Get-CimInstance It 'should return false' { $Splat = $TestServerTarget.Clone() @@ -522,14 +522,14 @@ try } It 'should call expected Mocks' { Assert-MockCalled -commandName Get-iSCSIServerTarget -Exactly 1 - Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } Context 'Server Target exists and should and all parameters match' { Mock Get-iSCSIServerTarget -MockWith { return @($MockServerTarget) } - Mock Get-CimInstnace + Mock Get-CimInstance It 'should return true' { $Splat = $TestServerTarget.Clone() @@ -537,14 +537,14 @@ try } It 'should call expected Mocks' { Assert-MockCalled -commandName Get-iSCSIServerTarget -Exactly 1 - Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } Context 'Server Target exists but should not' { Mock Get-iSCSIServerTarget -MockWith { return @($MockServerTarget) } - Mock Get-CimInstnace + Mock Get-CimInstance It 'should return false' { $Splat = $TestServerTarget.Clone() @@ -553,14 +553,14 @@ try } It 'should call expected Mocks' { Assert-MockCalled -commandName Get-iSCSIServerTarget -Exactly 1 - Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } Context 'Server Target does not exist and should not' { Mock Get-iSCSIServerTarget - Mock Get-CimInstnace + Mock Get-CimInstance It 'should return true' { $Splat = $TestServerTarget.Clone() @@ -569,14 +569,14 @@ try } It 'should call expected Mocks' { Assert-MockCalled -commandName Get-iSCSIServerTarget -Exactly 1 - Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } Context 'Server Target exists and should and iSNS Server is not set' { Mock Get-iSCSIServerTarget -MockWith { return @($MockServerTarget) } - Mock Get-CimInstnace + Mock Get-CimInstance It 'should return false' { $Splat = $TestServerTargetWithiSNS.Clone() @@ -584,14 +584,14 @@ try } It 'should call expected Mocks' { Assert-MockCalled -commandName Get-iSCSIServerTarget -Exactly 1 - Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } Context 'Server Target exists and should and iSNS Server is different' { Mock Get-iSCSIServerTarget -MockWith { return @($MockServerTarget) } - Mock Get-CimInstnace -MockWith { return @($MockiSNSSrver) } + Mock Get-CimInstance -MockWith { return @($MockiSNSSrver) } It 'should return false' { $Splat = $TestServerTargetWithiSNS.Clone() @@ -600,14 +600,14 @@ try } It 'should call expected Mocks' { Assert-MockCalled -commandName Get-iSCSIServerTarget -Exactly 1 - Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } Context 'Server Target exists and should and iSNS Server should be cleared' { Mock Get-iSCSIServerTarget -MockWith { return @($MockServerTarget) } - Mock Get-CimInstnace -MockWith { return @($MockiSNSSrver) } + Mock Get-CimInstance -MockWith { return @($MockiSNSSrver) } It 'should return false' { $Splat = $TestServerTargetWithiSNS.Clone() @@ -616,14 +616,14 @@ try } It 'should call expected Mocks' { Assert-MockCalled -commandName Get-iSCSIServerTarget -Exactly 1 - Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } Context 'Server Target does not exist and should not but iSNS Server is set' { Mock Get-iSCSIServerTarget - Mock Get-CimInstnace -MockWith { return @($MockiSNSSrver) } + Mock Get-CimInstance -MockWith { return @($MockiSNSSrver) } It 'should return false' { $Splat = $TestServerTarget.Clone() @@ -632,7 +632,7 @@ try } It 'should call expected Mocks' { Assert-MockCalled -commandName Get-iSCSIServerTarget -Exactly 1 - Assert-MockCalled -commandName Get-CimInstnace -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } } From 102a1a1ec40b7dcaec584354b867ea4fdf33a647 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Mon, 25 Jun 2018 19:34:12 +0100 Subject: [PATCH 13/16] Fix Typo --- Tests/Unit/DSR_iSCSIServerTarget.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Unit/DSR_iSCSIServerTarget.Tests.ps1 b/Tests/Unit/DSR_iSCSIServerTarget.Tests.ps1 index 4065b3d..4afcd9e 100644 --- a/Tests/Unit/DSR_iSCSIServerTarget.Tests.ps1 +++ b/Tests/Unit/DSR_iSCSIServerTarget.Tests.ps1 @@ -109,7 +109,7 @@ try } It 'should call the expected mocks' { Assert-MockCalled -commandName Get-iSCSIServerTarget -Exactly 1 - Assert-MockCalled -commandName Get-Cimnstance -Exactly 1 + Assert-MockCalled -commandName Get-CimInstance -Exactly 1 } } From 2acbe52f718b62c1287c2cc8abd3b696bc54e7c6 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Mon, 25 Jun 2018 20:00:52 +0100 Subject: [PATCH 14/16] fix DSC misunderstanding --- .../DSCResources/DSR_iSCSIInitiator/DSR_iSCSIInitiator.psd1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/DSR_iSCSIInitiator.psd1 b/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/DSR_iSCSIInitiator.psd1 index 2aa8b3c..eae4ee2 100644 --- a/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/DSR_iSCSIInitiator.psd1 +++ b/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/DSR_iSCSIInitiator.psd1 @@ -30,7 +30,7 @@ Description = 'Desired State Configuration resource for the management of iSCSI PowerShellVersion = '5.1' # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. -FunctionsToExport = '' +FunctionsToExport = 'Get-TargetResource', 'Set-TargetResource', 'Test-TargetResource' # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. CmdletsToExport = '' @@ -42,7 +42,7 @@ VariablesToExport = '' AliasesToExport = '' # DSC resources to export from this module -DscResourcesToExport = 'Get-TargetResource', 'Set-TargetResource', 'Test-TargetResource' +DscResourcesToExport = 'DSR_iSCSIInitiator' } From 6b105447fcdf96da95da25c6587ca2c83b76f65a Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Mon, 25 Jun 2018 20:23:37 +0100 Subject: [PATCH 15/16] Test if module teste are simply looking for text --- .../DSR_iSCSIInitiator/DSR_iSCSIInitiator.psm1 | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/DSR_iSCSIInitiator.psm1 b/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/DSR_iSCSIInitiator.psm1 index 5d8fb94..6fcec00 100644 --- a/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/DSR_iSCSIInitiator.psm1 +++ b/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/DSR_iSCSIInitiator.psm1 @@ -1,6 +1,20 @@ # Dot Source DSC Resource Files Get-ChildItem -Path (Join-Path (Join-Path $PSScriptRoot "Public") "*.ps1") | ForEach-Object { . $_.FullName } +<# +function get-TargetResource +{ +} + +function Test-Targetresource +{ +} + +functionSet-TargetResource +{ +} +#> + $modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules' # Import the Networking Resource Helper Module From e7fd578196c4e7a75abd745f94f9742a204ecac9 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Mon, 25 Jun 2018 20:27:10 +0100 Subject: [PATCH 16/16] regressed file --- .../DSR_iSCSIInitiator/DSR_iSCSIInitiator.psm1 | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/DSR_iSCSIInitiator.psm1 b/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/DSR_iSCSIInitiator.psm1 index 6fcec00..5d8fb94 100644 --- a/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/DSR_iSCSIInitiator.psm1 +++ b/Modules/iSCSIDsc/DSCResources/DSR_iSCSIInitiator/DSR_iSCSIInitiator.psm1 @@ -1,20 +1,6 @@ # Dot Source DSC Resource Files Get-ChildItem -Path (Join-Path (Join-Path $PSScriptRoot "Public") "*.ps1") | ForEach-Object { . $_.FullName } -<# -function get-TargetResource -{ -} - -function Test-Targetresource -{ -} - -functionSet-TargetResource -{ -} -#> - $modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules' # Import the Networking Resource Helper Module