Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

List all available function in global profile

Posted on 2014-02-25
8
Medium Priority
?
310 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 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
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 

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

 The Evil-ution of Network Security Threats

What are the hacks that forever changed the security industry? To answer that question, we created an exciting new eBook that takes you on a trip through hacking history. It explores the top hacks from the 80s to 2010s, why they mattered, and how the security industry responded.

Question has a verified solution.

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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
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 anti-spam), the admin…
Screencast - Getting to Know the Pipeline

810 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