Solved

List all available function in global profile

Posted on 2014-02-25
8
284 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
  • 5
  • 3
8 Comments
 
LVL 10

Expert Comment

by:JoeKlimis
Comment Utility
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
Comment Utility
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 10

Expert Comment

by:JoeKlimis
Comment Utility
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
 

Author Comment

by:Kasper Katzmann
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

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

Expert Comment

by:JoeKlimis
Comment Utility
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
Comment Utility
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
Comment Utility
This gives me exactly what I needed
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

This article will help you understand what HashTables are and how to use them in PowerShell.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now