Export-ModuleMember vs. Keys in Manifest


hello,

i'm bit confused difference between export-modulemember , settable keys in module manifest.

"export-modulemanifest -function" in module    |    "functionstoexport" in manifest
"export-modulemanifest -variable" in module    |    "variablestoexport" in manifest
"export-modulemanifest -alias" in module         |    "aliasestoexport" in manifest


i'm unsure when should use 1 or other. can functionstoexport give script loads module access specific functions can't variablestoexport restrict variables. export-modulemember -variable seems work though.

can give quick explanation, or point link one.

risc,

look closely @ helpfile both add-modulemanifest , export-modulemember job of explaining (note did read either).

by default (no export-modulemember in module script) functions thing exported. if there call export-modulemember strictly followed.

the module manifest used _restrict_ not add. play around manifest , module. note functions exported

import-module t1.psd1 -verbose

t1.psd1
@{
moduletoprocess = 't1.psm1'
moduleversion = '1.0'
guid = 'bd430945-5352-4056-958f-d46cafe2590e'
functionstoexport = 'send-greeting', 'add-numbers'
variablestoexport = 'msg'
aliasestoexport = 'add'
}

t1.psm1
$msg = 'hello world'
$answertotheuniverse = 42

function send-greeting() { write-host $msg }
function add-numbers([int] $a,[int] $b) { $a + $b }
 
set-alias add add-numbers
set-alias hi send-greeting 
<#
export-modulemember -function send-greeting, add-numbers
export-modulemember -variable msg, answertotheuniverse
export-modulemember -alias hi, add
#>



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Generating Event ID 91, 44 with CA (In Event Viewer with source as Certsvc)

Group policy default policy cannot be edited because network name not found

Problem when changing update source