Solved

List all available function in global profile

Posted on 2014-02-25
8
286 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
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 10

Expert Comment

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

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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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 10

Expert Comment

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Synchronize a new Active Directory domain with an existing Office 365 tenant
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 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

21 Experts available now in Live!

Get 1:1 Help Now