C'est en effet. En fait, j'ai un truc vraiment génial qui fait ça pour le snapin SQL. Le premier segment du code est une fonction qui va créer un manifeste de module pour vous à partir de l'un des emplacements du module. Il vous invitera toujours (comme le fait la cmdlet New-ModuleManifest) pour certains paramètres requis, comme la description. Il trouve tous les types et fichiers de format, ainsi que tous les fichiers .dll nommés .ps .dll (la plupart des snapins suivent cette convention), puis il crée un manifeste de module qui enveloppe le module d'origine. Le second fragment de code le fait spécifiquement pour SQL PSSnapin.
function New-ModuleManifestFromSnapIn {
[CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium')]
param(
[Parameter(Mandatory=$true, Position=0)]
[System.String]
${Path},
# The location in the filesystem where the V1 snapin resides
[Parameter(Mandatory=$true)]
[System.String]
${OriginalPath},
[System.Guid]
${Guid},
[Parameter(Mandatory=$true)]
[AllowEmptyString()]
[System.String]
${Author},
[Parameter(Mandatory=$true)]
[AllowEmptyString()]
[System.String]
${CompanyName},
[Parameter(Mandatory=$true)]
[AllowEmptyString()]
[System.String]
${Copyright},
[ValidateNotNull()]
[System.Version]
${ModuleVersion},
[Parameter(Mandatory=$true)]
[AllowEmptyString()]
[System.String]
${Description},
[System.Reflection.ProcessorArchitecture]
${ProcessorArchitecture},
[System.Version]
${PowerShellVersion},
[System.Version]
${ClrVersion},
[System.Version]
${DotNetFrameworkVersion},
[System.String]
${PowerShellHostName},
[System.Version]
${PowerShellHostVersion},
[System.Object[]]
${RequiredModules},
[AllowEmptyCollection()]
[System.String[]]
${ScriptsToProcess},
[AllowEmptyCollection()]
[System.Object[]]
${ModuleList},
[AllowNull()]
[System.Object]
${PrivateData},
[Switch]
${PassThru}
)
process {
$types = Get-ChildItem $originalPath -Filter *.types.ps1xml
$formats = Get-ChildItem $originalPath -Filter *.format.ps1xml
$dlls = Get-ChildItem $originalPath -Filter *.ps*.dll
$null = $psBoundParameters.Remove("OriginalPath")
$psBoundParameters += @{
VariablesToExport = "*"
FunctionsToExport = "*"
AliasesToExport = "*"
CmdletsToExport = "*"
FileList = @()
RequiredAssemblies = @()
ModuleToProcess = ""
NestedModules = @($dlls | Select-Object -ExpandProperty FullName)
TypesToProcess = @($types | Select-Object -ExpandProperty FullName)
FormatsToProcess = @($formats | Select-Object -ExpandProperty FullName)
}
New-ModuleManifest @psBoundParameters
}
}
Ce morceau montrera créer un manifeste en pointant l'outil @ SQL.
$basePath = $env:SqlSamplesSourceDataPath | Split-Path
if (${env:ProgramFiles(x86)}) {
$basePath = $basePath.Replace($env:ProgramFiles, ${env:ProgramFiles(x86)})
}
$path = Join-Path $basePath "Binn"
$basicMetaData = @{
Author = "Microsoft Corporation"
Description = "A Manifest to enable using the SQL PowerShell snapin in V2"
CompanyName = "Microsoft Corporation"
Copyright = (Get-Date).Year
}
New-ModuleManifestFromSnapin -Path $psScriptRoot\Sql.psd1 -OriginalPath $path @BasicMetaData
Le morceau final copier tout fichier nommé la culture actuelle (à savoir SQL \ en-us) dans le répertoire du module, qui fera le travail Get-Help pour les applets de commande.
Cette astuce a fonctionné pour quelques snapins, mais peut nécessiter certaines personnalisations pour chaque snapin que vous souhaitez réexposer en tant que module. Heureusement, c'est un coût ponctuel.
$Culture = Get-Culture
$CultureList = "$path\$culture",
(Join-Path $path $culture.ThreeLetterIsoLanguageName),
(Join-Path $path $culture.TwoLetterIsoLanguageName)
$CultureDirectory = Get-Item $CultureList -ErrorAction SilentlyContinue |
Select-Object -First 1
if ($CultureDirectory) {
$localDir = Join-Path $psScriptRoot (Split-Path $CultureDirectory -Leaf)
$item = Get-Item $localDir -ErrorAction SilentlyContinue
if ($item) {
Remove-Item $item -Recurse -Force
}
Copy-Item $CultureDirectory $LocalDir -Recurse
}
Hope this helps