Private proxy functions


maybe interesting demonstation of scope you'd never want use in practice, throwing out discussion:

you can create proxy function quite this:

function private:get-acl {get-acl | select  -expand access}

when create proxy function cmdlet, have use

$executioncontext.invokecommand.getcommand('get-childitem', [system.management.automation.command types]::cmdlet)

in function script block invoke cmdlet function going proxy.  because in order of precedence functions resolve before cmdlets, , without function becomes self-referential , goes loop.

the private: option prevents function being visible in child scopes.  since functions run in own scope effect hide existence of proxy function itself, and prevent loop.

it means function available in scope created in.  added profile, change behaviour of get-acl used command line, same command used in child scope (e.g. using &{get-acl},  invoke-command {get-acl} or used in a called script) not see proxy function , use cmdlet instead.


[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

i it, think risk of forgetting ,
trying use way in script might cause problems.  profile
is getting large , i've gotten in habit of checking out
every , again make sure know whats in there.
 
 

justin rich
http://jrich523.wordpress.com
powershell v3 guide (technet)
please remember mark replies answers if , unmark them if provide no help.


Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

CRL Revocation always failed

Failed to query the results of bpa xpath

0x300000d errors in Microsoft Remote Desktop client