Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. function Get-TargetResource
  2. {
  3. [CmdletBinding()]
  4. [OutputType([System.Collections.Hashtable])]
  5. param
  6. (
  7. [parameter(Mandatory = $true)]
  8. [ValidateSet("Yes")]
  9. [System.String]
  10. $IsSingleInstance,
  11.  
  12. [parameter(Mandatory = $true)]
  13. [System.Boolean]
  14. $Enable
  15. )
  16.  
  17. return @{
  18. IsSingleInstance = 'Yes'
  19. Enable = Test-LMHostEnabled
  20. }
  21. }
  22.  
  23. function Set-TargetResource
  24. {
  25. [CmdletBinding()]
  26. param
  27. (
  28. [parameter(Mandatory = $true)]
  29. [System.Boolean]
  30. $Enable
  31. )
  32.  
  33. $Result = Invoke-CimMethod -ClassName Win32_NetworkAdapterConfiguration -MethodName EnableWINS -Arguments @{
  34. WINSEnableLMHostsLookup = $Enable
  35. }
  36. if ($Result.ReturnValue -ne '0')
  37. {
  38. throw "Configuring LMHOST lookup failed with ReturnValue $($Result.ReturnValue)"
  39. }
  40. }
  41.  
  42. function Test-TargetResource
  43. {
  44. [CmdletBinding()]
  45. [OutputType([System.Boolean])]
  46. param
  47. (
  48. [parameter(Mandatory = $true)]
  49. [ValidateSet("Yes")]
  50. [System.String]
  51. $IsSingleInstance,
  52.  
  53. [parameter(Mandatory = $true)]
  54. [System.Boolean]
  55. $Enable
  56. )
  57.  
  58. if ((Test-LMHostEnabled) -eq $Enable)
  59. {
  60. return $true
  61. }
  62. else
  63. {
  64. return $false
  65. }
  66. }
  67.  
  68. # Helper Functions
  69. function Test-LMHostEnabled
  70. {
  71. [CmdletBinding()]
  72. param ()
  73.  
  74. $CimInstance = Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration -Filter 'IPEnabled = TRUE'
  75. Write-Verbose -Message "LMHost lookup enabled: $($CimInstance[0].WINSEnableLMHostsLookup)"
  76. $CimInstance[0].WINSEnableLMHostsLookup
  77. }
  78.  
  79.  
  80. Export-ModuleMember -Function *-TargetResource
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement