locked
How to debug shell scripts in Windows Power Shell? RRS feed

  • Question

  • Hi guys,

    I am new in shell scripts.

    Do you have any idea to debug shell script?

    my .ps1 code is:

    Function Checkout-Document($SiteURL, $FileRelativeURL, $Credentials)
    {
     
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Credentials
     
        Try {
            #Try to get the file from URL
            $File = $Ctx.web.GetFileByServerRelativeUrl($FileRelativeURL)
            $Ctx.Load($File)
            $Ctx.ExecuteQuery()
            
            #check if the file is already checked out
            If($File.CheckOutType -ne "None")
            {
                #Add-Type -AssemblyName System.Windows.Forms
                $a = new-object -comobject wscript.shell
                $b = $a.popup("CRT File is already checked-out!",3,"Admin",1)
                #[System.Windows.Forms.MessageBox]::Show('File is already checked-out!', 'Admin', 'OK', 'Information') | Out-Null
                $CheckoutSuccess = "Status=99"
                $CheckoutSuccess > "C:\WeeklyReportAutomate\log.txt"
                Return $CheckoutSuccess
                break
            }
            #Checkout the document
            $File.CheckOut()
            $Ctx.ExecuteQuery()
            $a = new-object -comobject wscript.shell
            $b = $a.popup("CRT Document has been checked-out successfully!",3,"Admin",1)
            #Add-Type -AssemblyName System.Windows.Forms
            #[System.Windows.Forms.MessageBox]::Show('Document has been checked-out successfully!', 'Admin', 'OK', 'Information') | Out-Null
            $CheckoutSuccess = "Status=1"
            $CheckoutSuccess > "C:\WeeklyReportAutomate\log.txt"

        }
        Catch {
            Add-Type -AssemblyName System.Windows.Forms
            [System.Windows.Forms.MessageBox]::Show('Error checking out CRT Document! '+ $_.Exception.Message, 'Admin', 'OK', 'Information') | Out-Null
            $CheckoutSuccess = "Status=999"
            $CheckoutSuccess > "C:\WeeklyReportAutomate\log.txt"
            exit
        }
        Return $CheckoutSuccess
    }

    I want to put some breakpoint to debug this. Any idea pls?

    Tuesday, December 4, 2018 7:05 AM

All replies

  • use ISE Powershell than you can debug it.


    Chris

    Tuesday, December 4, 2018 6:41 PM
  • You can debug in PS console or ISE

    help *debug*

    Search for "powershell debug" to find many articles on debugging.


    \_(ツ)_/

    Tuesday, December 4, 2018 6:52 PM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Tuesday, December 11, 2018 6:42 AM
  • Hi,

    Was your issue resolved? 
    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,
    Lee


    Just do it.

    Monday, December 24, 2018 6:14 AM