?
Solved

List all available function in global profile

Posted on 2014-02-25
8
Medium Priority
?
301 Views
Last Modified: 2014-03-18
How do I list all functions loaded from our global powershell profile?

If I do this, I get all functions loaded, but I only want those that comes from the global profile:
Get-Command -type Function

Open in new window

Is it possible?
0
Comment
Question by:Kasper Katzmann
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 11

Expert Comment

by:Joe Klimis
ID: 39912616
Hi

You will need to identify something unique about the functions loaded in the global profile
 
select  a function and look at all its properties to identify this you could use a command like the following.

(get-command -type function)[2] | select -Property *

Open in new window


this returns
HelpUri             :
ScriptBlock         :
CmdletBinding       : False
DefaultParameterSet :
Definition          :
Options             : None
Description         : MyCompany
Verb                : Add
Noun                : BitLockerKeyProtector
HelpFile            :
OutputType          : {}
Name                : Add-BitLockerKeyProtector
CommandType         : Function
Visibility          : Public
ModuleName          : BitLocker
Module              : BitLocker
RemotingCapability  : PowerShell
Parameters          : {}
ParameterSets       : {}

Open in new window


If will then be a simple matter of filtering the results

Get-Command -type Function | ? {$_.Description  -eq "MyCompany" }

Open in new window


let me know if this helps , or if you can provide more detail i will be able to help you more fully.

Joe
0
 

Author Comment

by:Kasper Katzmann
ID: 39913221
Thanks for answering.

There isn't any unique things about them, that they have in common. Could I add something unique to each function in the global profile?
0
 
LVL 11

Expert Comment

by:Joe Klimis
ID: 39915699
Hi

you could set the read only option on all your functions when you set them

Function test1 { write-host "hello" }
Set-Item –Path Function:test1 –Options ReadOnly
get-item function:*  | ? {$_.options -eq "Readonly"}

CommandType     Name                                               ModuleName
-----------     ----                                               ----------
Function        Joe
Function        test1

Open in new window

0
WatchGuard's M Series Appliances - Miecom Approved

WatchGuard's newest M series appliances were put to the test by Miercom.  We had great results and outperformed all of our competitors in both stateless and stateful traffic throghput scenarios! Ready to see how your UTM appliance stacked up? Download the Miercom Report!

 

Author Comment

by:Kasper Katzmann
ID: 39918943
Hmmm, I'm not sure if I understand this one.
Doesn't this require, that I know the name of all the functions in the global profile?
0
 

Author Comment

by:Kasper Katzmann
ID: 39925867
I was thinking... is it possible to extract all the words "Function" and the word comming right after?
0
 
LVL 11

Expert Comment

by:Joe Klimis
ID: 39925895
Hi

I am still not quite clear on exactly what is required here ,  

please run the following command and highlight the items you only want to be displayed

if you are trying to identify you own functions , when they are created you could create them read only , which will allow you to Identify them.

Regards

Joe
Get-Command -type Function | select -Property * | ft 

Open in new window

0
 

Accepted Solution

by:
Kasper Katzmann earned 0 total points
ID: 39926115
We have put a lot of functions into the Global Profile (C:\Windows\System32\WindowsPowerShell\v1.0\Profile.ps1)

There are nothing else than our own (homemade) functions in this file, but there's a lot of them.

I've been trying with  Select-String, which turned out to be the right approach.

$lines = Select-String "C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1" -Pattern "Function" | Select line

foreach ($line in $lines) {

$funcName = $line.line -split "\("
Write-Host $funcName[0]

}

Open in new window

gives me this:
function str2email
function Get-admin
function Get-MasterSID
Function Phone-Number
function new-primary-mailaddress
function get-struct
function update-struct
function Get-Styr-ADUser
function Get-Styr-Users
Function Update-Users
function Get-CASActiveUsers
Function Get-Cau
function update-DistributionGroup-members
function update-Organisation
function update-Fordelingspostkasser
function List-DistributionGroup-members
function List-Organisation
function List-Fordelingspostkasser
function make-id
function New-DistributionGroup-from-group
function opret-Fordelingspostkasser
function get-group-from-customattribute
function get-linked-user-list
function update-SharedMailbox-members
function update-SharedMailboxes... (and so on)

Open in new window

So at last I cracked the code.

I really appreciate your effort, Thanks!
0
 

Author Closing Comment

by:Kasper Katzmann
ID: 39936349
This gives me exactly what I needed
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will help you understand what HashTables are and how to use them in PowerShell.
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question