dot sourcing not working when starting script from desktop

Viewed 76

i have a powershell script which dot sources stuff from 2 other scripts. When i run the script from ISE it works fine, but when i run it from desktop by right click and select "Run with PowerShell" it errors with module not exists etc..

my script sources the two files like this

. c:\SIJ\scripts\userstory_gui_part.ps1
. c:\SIJ\scripts\userstory_function_part.ps1

#region gui events {

$Create.Add_Click( {

$Tbname = $TableNameId.Text

$TbViewName = $TableViewNameID.Text

$CustName = $CustomerNameID.Text

$global:UsrName = $AdUserNameID.Text

$global:usrPasswd = $AdpasswordID.Text

$global:Ticket = $CherwellTicketID.Text

 kunde $($CustName)

$returnValueDataTask = Create-UserStory $UsrName $usrPasswd $Tbname $TbViewName $CustName $Ticket | Out-String

$returnValueErwinTask = Create-ERWIN-UserStory $UsrName $usrPasswd $Tbname $TbViewName $Ticket | Out-String


$b = $returnValueDataTask | Select-String -Pattern '([DWH-]{4}\d{4})'

$global:userstoryid = $b.Matches.Groups[1]

$c = $returnValueErwinTask | Select-String -Pattern '([DWH-]{4}\d{4})'

$global:erwinuserstoryid = $c.Matches.Groups[1]

[System.Windows.MessageBox]::Show("følgende blev oprettet $($returnValueErwinTask) og 
$($returnValueDataTask)", "Oprettelse af Userstories i JIRA")

$CreateFileUploadButton.Enabled = $true

})

 $CreateExitButton.Add_Click( {

 $form.Close()



})



$CreateFileUploadButton.Add_Click( {

Write-Host "Du trykkede upload knappen"



$filename =SelectFileToUpload







Add-Attachment $userstoryid $filename $UsrName $usrPasswd

Add-Attachment $erwinuserstoryid $filename $UsrName $usrPasswd

Write-Host "ok"



})

#endregion events }





#endregion GUI }

[void]$Form.ShowDialog()

How can i ensure that my scripts startup with the environment needed from desktop

there error is

Unable to find type [System.Windows.MessageBox].
At S:\UO4\DWH\SIJ\scripts\create_data_userstory-feature edition.ps1:29 
char:1
+ [System.Windows.MessageBox]::Show("følgende blev oprettet $($returnVa ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: 
(System.Windows.MessageBox:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
0 Answers
Related