Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
NetApp Windows Unified Host Utilities DSC Resource
function Get-TargetResource
{
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
(
[parameter(Mandatory = $true)]
[System.String]
$Path,
[string]
$Name = 'NetApp Windows Unified Host Utilities',
[string]
$ProductId,
[string]
$Version,
[ValidateSet("Present", "Absent")]
[string]
$Ensure = 'Present'
)
# check if guid
if ($ProductId -match "{.*?}")
{
$prodId = $ProductId
}
else
{
$prodId = "{$ProductId}"
}
$product = Get-CimInstance -ClassName Win32_Product -Filter "Name = '$Name' AND IdentifyingNumber = '$prodId'"
if ($product -eq $null)
{
return $null
}
if ($product -ne $null)
{
$currentVersion = $product.Version
$currentEnsure = "Present"
}
else
{
$currentVersion = $null
$currentEnsure = "Absent"
}
return @{
Name = $Name;
ProductId = $ProductId;
Version = $currentVersion;
Ensure = $currentEnsure;
}
}
function Set-TargetResource
{
[CmdletBinding()]
param
(
[parameter(Mandatory = $true)]
[System.String]
$Path,
[string]
$Name = "SnapDrive",
[string]
$ProductId,
[string]
$Version,
[ValidateSet("Present", "Absent")]
[string]
$Ensure = 'Present'
)
$current = Get-TargetResource @PSBoundParameters
if ($Ensure -eq 'Present')
{
$ArgumentList = @"
/i $($Path) /qn /L*v C:\windows\temp\NetAppHostUtilities.txt MULTIPATHING=1
"@
}
else
{
$ArgumentList = @"
/x $($Path) /qn /L*v C:\windows\temp\NetAppHostUtilities.txt
"@
}
$process = Start-Process -FilePath "msiexec.exe" -ArgumentList $ArgumentList -Wait -PassThru
Write-Verbose "Installation ended with an exit code of $($process.ExitCode)."
if ($process.ExitCode -ne 0 -and $process.ExitCode -ne 3010)
{
Write-Error "The installer did not complete. The error code is $($process.ExitCode)."
}
}
function Test-TargetResource
{
[CmdletBinding()]
[OutputType([System.Boolean])]
param
(
[parameter(Mandatory = $true)]
[System.String]
$Path,
[string]
$Name = "SnapDrive",
[string]
$ProductId,
[string]
$Version,
[ValidateSet("Present", "Absent")]
[string]
$Ensure = 'Present'
)
$current = Get-TargetResource @PSBoundParameters
if ($Ensure -eq "Absent")
{
if ($current -ne $null)
{
Write-Verbose "$Name is currently installed. It will be removed."
return $false
}
return $true
}
if ($current -eq $null)
{
Write-Verbose "Product $($Name) is not currently installed. It will be installed."
return $false
}
return $true
}
Export-ModuleMember -Function *-TargetResource
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.