How to find out if a script is ran, or dot-sourced?

This came up in a little thing I was working on... I'd like to be able to detect if a script is being ran "cold", or if it's being dot-sourced. I've had a good search but no luck so far.
eg, if a script can detect whether it's being ran as
.\myscript.ps1
or
. .\myscript.ps1
Not looking for a "what are you trying to do, maybe do it this way instead" sorta deal - this is more of a curio, wondering if it can actually be done.
Anyone?
A

Get-PSCallStack is another excellent way to determine this as well and also works great to determine what file a function came from. You can get some great info from it as shown below.
$ScriptStack = (Get-PSCallStack)
Write-Verbose ("Is DotSourced? -- {0}" -f ($ScriptStack[1].position.text -match '^\.\s\.')) -Verbose
Function Foo {
$FunctionStack = (Get-PSCallStack)
Write-Verbose "Originating Script for $($FunctionStack[0].Command): $($FunctionStack[0].ScriptName)" -Verbose
Write-Verbose "Originating Command calling $($FunctionStack[0].Command): $($FunctionStack[1].Command)" -Verbose
Function Main {
$FunctionStack = (Get-PSCallStack)
Write-Verbose "Originating Script for $($FunctionStack[0].Command): $($FunctionStack[0].ScriptName)" -Verbose
FOO
Boe Prox
Blog |
Twitter
PoshWSUS |
PoshPAIG | PoshChat |
PoshEventUI
PowerShell Deep Dives Book

Similar Messages

  • How to find out Password Verify script for a profile

    Hi,
    DB_VERSION : 10.2.0.4
    OS_VERSION:Windows 2003
    There is a profile MY_PROFILE created for which Password Verify Fucntion is created as " VERIFY_FUCTION"
    How can i find out contents of the script while executing VERIFY_FUCTION ?

    How can i find out contents of the script while executing VERIFY_FUCTION ?sys@11GDEMO> select * from dba_profiles where resource_name='PASSWORD_VERIFY_FUNCTION';
    PROFILE RESOURCE_NAME RESOURCE LIMIT
    DEFAULT PASSWORD_VERIFY_FUNCTION PASSWORD NULL
    sys@11GDEMO>

  • How to Find out the Name of the Table in Data Sources

    Hi All,
    How Can i find out the table names used in data Sources.
    For EX. Suppose I want to find out the table Names  in R3 Used In GL Data Source 0FI_GL_4.
    Thanks in Advance.
    Vaibhav A

    Hi,
    Usefull link:
    https://wiki.sdn.sap.com/wiki/display/BI/BW%20SD%20MM%20FI%20DATASOURCES
    Regards.

  • How to find out which query run how many times using ST03?

    Hi experts,
    I am trying to clean up all the junk queries in BWP. my questions is, How to find out that the particular query ran how my times in a year and by which user using ST03, How to do it step by step?
    I don't like to use statistic reports for this. How to do it using ST03?
    Please let me know. Thanks in advance.
    Sharat.

    Hi,
    Please find the below links which would help you solving you problem,
    SAP BW performance tunning : Includes screen shots
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/68fbb490-0201-0010-8eb5-f7e0adaff5bd
    SAP BW Query Performance Tuning with Aggregates:
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/3f66ba90-0201-0010-ac8d-b61d8fd9abe9
    With Regards,
    PCR

  • How to find out the Tcode related to a Script

    Hi All,
    Our client is using one ZFORM (on Bill Of Lading),
    How to find out, In which Tcode this particular Script was used?
    I have checked the TNAPR table,
    It's showing the Program Name Not Tcode.
    Any hint...
    Thanks,
    Kalyan

    Hi Nehal,
    In the Tcode V/G9, Output type Z013, Z016 are there for my ZFORM,
    and the corresponding Program name also given.
    If I made any change to the SCRIPT, how to check, whether changes are made correctly. In the Script, if I go to Utilities-> There is no print preview, there is only print option.
    I am working on the CITRIX, I can't take the print locally,
    It's going to Client place..
    Any advice,
    Thanks,
    Kal Chand

  • How to find out the Correct Controlfile script Trace .trc file in /bdump

    Hi Guys
    This is the most childish queries in this forum ..
    I wanna know how to Find out the correct trace file when we Issue alter database backup controlfile to trace at sqlprompt for Creating controlfile script.
    As i find it a bit confusing to go through the same Date & almost same time .trc files out of hundreds of trace file in /bdump directory to find the correct one.
    if we 've to find the Alert log file in /bdump directory $ ls -l al* & we get the alert log file .... if there is any similar way to find out the controlfile script Trace file ?
    Thanks & regards
    MZ

    MZ_AppsDBA wrote:
    Hi Guys
    This is the most childish queries in this forum ..
    I wanna know how to Find out the correct trace file when we Issue alter database backup controlfile to trace at sqlprompt for Creating controlfile script.
    As i find it a bit confusing to go through the same Date & almost same time .trc files out of hundreds of trace file in /bdump directory to find the correct one.
    if we 've to find the Alert log file in /bdump directory $ ls -l al* & we get the alert log file .... if there is any similar way to find out the controlfile script Trace file ?
    Thanks & regards
    MZcreation of the does not happen automatically. What script, and when does it run, do you have that creates the control file trace? Look for files in that time frame. Better, modify that script to specifically name the file .. BACKUP CONTROLFILE TO TRACE AS ....

  • How to find out web content files linked in folio through scripting

    Hi all,
    Please suggest me, how to find out web content files linked in folio through scripting.
    Regards,
    Moorthy

    @Moorthy – can you tell us a bit more? By mentioning "folio", I think you are referring to Adobe Digitial Publishing Suite (ADPS or short: DPS). If yes:
    1. Do you want to analyze Folio files *.folio and get the linked web content files?
    2. Or do you want to check an InDesign file with an overlay and check what files are linked as web content?
    3. Or something else?
    Where is your base problem?
    Packaging the InDesign files and copy/relinking the web content files after the packaging process?
    Uwe

  • How to find out which lists are using email enabled feature in my SP 2010? Any script? Anything else?

    Hi there,
    How to find out which lists are email enabled in my SP 2010?
    Any script? Anything else?
    Thank you.

    Hi frob,
    check this script that is stated on this link
    $SPwebApp = Get-SPWebApplication "http://migration.Company.com"
    <# If it is MOSS 2007, You can use:
    $SPWebApp = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup(http://sharepoint.com)
    To get SPWebApplication Object
    #>
    #create a CSV file
    "E-Mail,List,Site" > "EMail-Enabled.txt" #Write the Headers in to a text file
    foreach ($SPsite in $SPwebApp.Sites) # get the collection of site collections
    foreach($SPweb in $SPsite.AllWebs) # get the collection of sub sites
    foreach ($SPList list in $SPweb.Lists)
    if ( ($splist.CanReceiveEmail) -and ($SPlist.EmailAlias) )
    # WRITE-HOST "E-Mail -" $SPList.EmailAlias "is configured for the list "$SPlist.Title "in "$SPweb.Url
    $SPList.EmailAlias + "," + $SPlist.Title +"," + $SPweb.Url >> EMail-Enabled.txt #append the data
    http://www.sharepointdiary.com/2011/06/find-all-incoming-email-enabled-lists.html
    Kind Regards, John Naguib Technical Consultant/Architect MCITP, MCPD, MCTS, MCT, TOGAF 9 Foundation. Please remember to mark the reply as answer if it helps.

  • How to find out the script for the table using SQL

    Hi,
    Could any one tell me that how to find out the script for the table using SQL.
    Thanks,
    kamal

    Kamal,
    You can find the SQL query in Advanced tab of Answers
    Thanks,
    Balaa...

  • How to find out existing Reports and sap scripts and smartforms ?

    Dear Friends ,
    How to find out existing Reports and sap scripts and smartforms ?
    ( e.g: how many existing reports and SAP scripts are available in MM or SD module , What is the procedure to find out ? )
    Thanking you.
    Regards,
    Subash.

    scripts r stored in TNAPR TABLES

  • How to find out which objects are at the end of the datafiles

    My Scenario is having a tablespace of 65G but the data is 5G and that is at the end of datafile for that we are not able to resize the datafile our though is to find out what are the objects at that end of datafiles and will either alter move <owner.tablename> move or alter index <owner.index> rebuld online.
    For that how to find out which objects are at the end of the datafiles.

    >
    My Scenario is having a tablespace of 65G but the data is 5G and that is at the end of datafile for that we are not able to resize the datafile our though is to find out what are the objects at that end of datafiles and will either alter move <owner.tablename> move or alter index <owner.index> rebuld online.
    For that how to find out which objects are at the end of the datafiles.
    >
    You may want to copy this and add it to your toolkit
    See 'What's at the End of the File?' in this Tom Kyte article from the Sept 2004 Oracle Magazine
    http://www.oracle.com/technetwork/issue-archive/o54asktom-086284.html
    And this AskTom blog shows you how to generate a script containing ALTER statements toresize your datafiles to the smallest possible. You can 'pick and choose' from the ALTER statements to do what you want.
    Then of course, you can use techniques from this article by Oracle ACE, and noted author, Jonathan Lewis
    http://jonathanlewis.wordpress.com/2010/02/06/shrink-tablespace/

  • How to find out selected AssignedStory or Link?

    Hello to all,
    can anyone pls. explain how to find out which assigned story or link is selected at the time the script is fired.
    My problem is this: I would like to place an image into selected rectangle which is exported into .icml. So, for example, you have few exported rectangles and you would like to place an image into the one which is selected (through link or assignment panel). Because you can not select a rectangle in InCopy like you can in InDesign I tried to take a look through assigned stories...
                       For aCounter As Integer = 1 To myDocument.Assignments.Count
                            Dim myAssignment As InCopy.Assignment = myDocument.Assignments.Item(aCounter)
                            For sCounter As Integer = 1 To myAssignment.AssignedStories.Count
                                Dim myAssignedStory As InCopy.AssignedStory = myAssignment.AssignedStories.Item(sCounter)
                                Dim myStoryRef As Object = myAssignedStory.StoryReference
                                find out if assigned story or story reference is selected
                                'Rectangle
                                If TypeName(myStoryRef) = "Rectangle" Then
                                    Dim myObjectRectangle As InCopy.Rectangle = myStoryRef
                                    If myObjectRectangle.Graphics.Count = 0 And myObjectRectangle.Images.Count = 0 Then
                                        'CheckOut if needed
                                        'Place Media
                                    End If
                                End If
                            Next
                        Next
    Kind regards,
    Marko

    Well,
    I couldn't solve this without using a placeholder image. I found that you need to check if the selection is an image and than replace that image... So something like this below:
                    'Check if there is a selected image for relink
                    If myDocument.Selection.Count = 1 Then
                        If TypeName(myDocument.Selection.Item(1)) = "Image" Then
                            myImage = myDocument.Selection.Item(1)
                            myImageLink = myImage.ItemLink
                            Dim msgRet As MsgBoxResult = MsgBox("Would you like to relink selected image?", MsgBoxStyle.YesNoCancel, "Relink seleceted image?")
                            If msgRet = MsgBoxResult.Yes Then
                                        ' DO some action
                                        Dim MediaLink As String = something...
                                                'CheckOut action
                                                If myCheckOutMenu.AssociatedMenuAction.Enabled() Then
                                                    myCheckOutMenu.AssociatedMenuAction.Invoke()
                                                End If
                                                myImageLink.Relink(fileLink)
                                                Try
                                                    myImageLink.Update()
                                                Catch
                                                End Try
    Hope this helps.
    Regards,
    Marko

  • How to find out the RasterItem(embedded) links name?

    How to find out the RasterItem(embedded) links name which appeared in Links menu(Window->Links) via scripting for illustrator cs3. Please advise me the possibilities.
    Thanks for looking into this.

    Thanks for your support. From your code i got the filename(embedded) with pathname(if the embedded image in that location). If the embedded image not in that location at that time it throws error message. Is it possible to find out the name of the embedded image, if the corresponding image not in that location. Kindly advise me the possiblitities.
    Thanks for looking into this.

  • How to find out the save as setting information in illustrator cs3?

    How to find out the save as setting information in illustrator cs3 through programmatically. I saved the file using the setting like Overprint, EmbedAllFonts, IncludeDocumentThumbnails throgh scripting. But i don't know how to find out the save as setting information(Overprint, EmbedAllFonts, IncludeDocumentThumbnails) whether the checkbox true or not through scripting. Kindly advice me.

    Thanks for your response. Some time the operator will set the wrong "save as setting" in the eps file . So i need to check wheather the operator set the correct save as setting or not. If the operator set the wrong save as setting,  i need to inform while running the script. So please advice me how to find out the save as setting information of the active document file, and then inform to the operator if any improper "save as setting" occured.

  • How to find out the image size?

    How to find out the image size values(Width and height) in illustrator CS3 using any script. I tried but i got only the document height and width. I need to find out the image BoundingBox value of width and height. Kindly advice me.

    Try this.
    tell application "Adobe Illustrator"
    set heightImage to get height of raster item 1 of current layer of current document
    set widthImage to get width of raster item 1 of current layer of current document
    display dialog (heightImage & " X " & widthImage) as string
    end tell
    JaiMS

Maybe you are looking for

  • Data  not available in infocube

    hi all, I havae an Infocube for which data is coming from the ods. yesterday i found the data is not available for an info object in ods for which data is there in source system. then I manually enter the data in the ods and today morning when i chec

  • How do I report to a human being at iTunes that they have the wrong art?

    I had iTunes download art for my library and in some cases it associated the incorrect art with albums. I can't find anywhere to report that. Help?

  • Complex datatypes for webservices

    Hello all, Question from customer: "...Its not possible to user webservices in htmldb, that user complex types for paramater or return. Creation htmldb webservice formulars work only with literal soap data types. But soap xsd support complex types or

  • Loosing memory in jms ??

    Hi,           Here are the details:           OS: RHEL 4           JVM: BEA WebLogic JRockit(TM) 1.4.2_08 JVM R24.5.0-61 Version ari-49095-20050826-1856-linux-ia32 from BEA Systems, Inc.           WLS: 8.1.4 (Clustered, 1 Admin, 2 Managed)           

  • Insert HTML.Tag attributes?

    Hey, How would I insert html attributes? I am making a HTML Editor. The following are some valid java html attributes. How would I insert it properly? HTML.Tag.P, HTML.Tag.BLOCKQUOTE, HTML.Tag.CENTER, HTML.Tag.CITE, HTML.Tag.CODE, HTML.Tag.H1, HTML.T