Deploy-Odbcs.ps1
function Deploy-Odbcs { <# .SYNOPSIS This function ... .DESCRIPTION A bit more description .PARAMETER FromPipeline Shows how to process input from the pipeline, remaining parameters or by named parameter. .EXAMPLE Deploy-Odbcs 'abc' Description of the example. #> <# Enable -Confirm and -WhatIf. #> [CmdletBinding(SupportsShouldProcess = $true)] param ( [parameter(Mandatory=$false,Position=0)] [string] $DsnDefinitionPath = 'c:\Migrate\odbcs', [parameter(Mandatory=$false)] [string] $MachineName #[parameter(Mandatory=$true)] #[System.Management.Automation.PSCredential] $mycreds ) begin { } process { $Dsns = gci $DsnDefinitionPath; $session = New-PSSession -ComputerName $MachineName # -Credential $mycreds Invoke-Command -Session $session -ScriptBlock{ param($dsns) foreach ($dsnText in $dsns){ $dsn = Get-Content $dsnText.PsPath | ConvertFrom-Json # ($dsn.PropertyValue | Select-Object @{Name='Name';Expression={('"' +$_ + '"')}} ).Name -join ',' #$dsn | select -ExpandProperty Attribute #$obj_list = $dsn.PropertyValue | Select-Object @{Name='Name';Expression={($_)}} Add-OdbcDsn -DriverName $dsn.DriverName -DsnType System -Platform $dsn.Platform -Name $dsn.Name -SetPropertyValue @( [string] (($dsn.PropertyValue | Select-Object @{Name='Name';Expression={('"' +$_ + '"')}} ).Name -join ',') ) -CimSession } } -Args ($Dsns) } end { } } if ($loadingModule) { Export-ModuleMember -Function 'Deploy-Odbcs' } |