Solved

List all available function in global profile

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

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
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: 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 10

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

Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

Question has a verified solution.

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

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
This article will help you understand what HashTables are and how to use them in PowerShell.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
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…

685 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