I have environment variable ARTEMIS_HOME set to c:\artemis.
PS C:\artemis_brokers> $env:ARTEMIS_HOME
C:\artemis
Under this directory I have a folder called bin that contains an artemis.cmd script. How can I run this script from anywhere in my PowerShell using the system variable?
I have tried the following with no success:
PS C:\artemis_brokers> $env:ARTEMIS_HOME/bin/artemis
At line:1 char:19
+ $env:ARTEMIS_HOME/bin/artemis
+ ~
You must provide a value expression following the '/' operator.
At line:1 char:19
+ $env:ARTEMIS_HOME/bin/artemis
+ ~~~~~~~~~~~
Unexpected token 'bin/artemis' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ExpectedValueExpression
PS C:\artemis_brokers> ./$env:ARTEMIS_HOME/bin/artemis
./$env:ARTEMIS_HOME/bin/artemis : The term './$env:ARTEMIS_HOME/bin/artemis'
is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
At line:1 char:1
+ ./$env:ARTEMIS_HOME/bin/artemis
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (./$env:ARTEMIS_HOME/bin/artemis:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS C:\artemis_brokers> ./$env:ARTEMIS_HOME/bin/artemis.cmd
./$env:ARTEMIS_HOME/bin/artemis.cmd : The term './$env:ARTEMIS_HOME/bin/
artemis.cmd' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At line:1 char:1
+ ./$env:ARTEMIS_HOME/bin/artemis.cmd
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (./$env:ARTEMIS_HOME/bin/artemis.cmd:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS C:\artemis_brokers> ./"$env:ARTEMIS_HOME/bin/artemis.cmd"
./$env:ARTEMIS_HOME/bin/artemis.cmd : The term './$env:ARTEMIS_HOME/bin/
artemis.cmd' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At line:1 char:1
+ ./"$env:ARTEMIS_HOME/bin/artemis.cmd"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (./$env:ARTEMIS_HOME/bin/artemis.cmd:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS C:\artemis_brokers> .\$env:ARTEMIS_HOME/bin/artemis
.\$env:ARTEMIS_HOME/bin/artemis : The term '.\$env:ARTEMIS_HOME/bin/artemis'
is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
At line:1 char:1
+ .\$env:ARTEMIS_HOME/bin/artemis
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (.\$env:ARTEMIS_HOME/bin/artemis:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS C:\artemis_brokers> .\$env:ARTEMIS_HOME/bin/artemis.cmd
.\$env:ARTEMIS_HOME/bin/artemis.cmd : The term '.\$env:ARTEMIS_HOME/bin/
artemis.cmd' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At line:1 char:1
+ .\$env:ARTEMIS_HOME/bin/artemis.cmd
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (.\$env:ARTEMIS_HOME/bin/artemis.cmd:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS C:\artemis_brokers> .\"$env:ARTEMIS_HOME/bin/artemis.cmd"
.\$env:ARTEMIS_HOME/bin/artemis.cmd : The term '.\$env:ARTEMIS_HOME/bin/
artemis.cmd' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At line:1 char:1
+ .\"$env:ARTEMIS_HOME/bin/artemis.cmd"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (.\$env:ARTEMIS_HOME/bin/artemis.cmd:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
You need to expand the variable and concatenate the rest of the path into a string before you try to execute. To execute the resulting string, use &, the call operator:
& "$env:ARTEMIS_HOME/bin/artemis.cmd"
Try:
& $env:ARTEMIS_HOME\bin\artemis.cmd
Related
Im trying to do an invoke command inside a function, but having difficulty getting defined variables to pass through.
function Set-RemoteLocalAdmin {
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[string]$ComputerName,
[String] $UserId
)
$sb = {
param($userid)
add-LocalGroupMember -Group "Administrators" -Member "$UserId"}
Invoke-Command -ComputerName $ComputerName -Scriptblock $sb -argumentlist $userid
}
Errors:
The term '' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
+ CategoryInfo : ObjectNotFound: (:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
+ PSComputerName : COMPUTERNAME-1
The term 'param' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
+ CategoryInfo : ObjectNotFound: (param:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
+ PSComputerName : COMPUTERNAME-1
Member BUILTIN\ was not found in group Administrators.
+ CategoryInfo : ObjectNotFound: (BUILTIN:String) [Add-LocalGroupMember], MemberNotFoundException
+ FullyQualifiedErrorId : MemberNotFound,Microsoft.PowerShell.Commands.AddLocalGroupMemberCommand
+ PSComputerName : COMPUTERNAME-1
What am I missing here?
Thanks in advance.
So I typed the command 'help' in windows Powershell but I'm getting the following error:
more.com : The term 'more.com' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:9 char:19
+ } else { $input | more.com }
+ ~~~~~~~~
+ CategoryInfo : ObjectNotFound: (more.com:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
When i tried run this PS Script :
" Get-ObjectAcl -SamAccountName delegate -ResolveGUIDs | ? {$_.ActiveDirectoryRights -eq "GenericAll"} "
i got error like that:
Get-ObjectAcl : The term 'Get-ObjectAcl' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
Get-ObjectAcl -SamAccountName delegate -ResolveGUIDs | ? {$_.ActiveDi ...
+ CategoryInfo : ObjectNotFound: (Get-ObjectAcl:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I searched but i can't find how can i use module Add-ObjectAcl and Get-ObjectAcl
I have a script that collects error messages, and it calls another script with the error string so my other script can email me about the error. However, invoke-expression seems to be looking within the string I pass, and reporting errors. I tried cleaning unusual characters from within the string in case that was the issue, but I'm out of characters to remove that seem like they would be an issue. So, we are debugging the call to invoke-expression, not the error message I am posting below. I already know that I commented out the step that creates the directory it is missing.
This is my error string:
Could not find a part of the ph 'EDisasterBackuptoLoc_20190123PrivilegesPrivileges_HH_Bakcsv'Exception No such ph EDisasterBackuptoLoc_20190123PrivilegesPrivileges_HH_Bakcsv Exception SystemManagementAutomionItemNotFoundException Cannot find ph 'EDisasterBa
ckuptoLoc_20190123PrivilegesPrivileges_HH_Bakcsv' because it does not exist
SystemManagementAutomionLocionGlobberExpandMshGlobPhString ph Boolean allowNonexistingPhs PSDriveInfo drive ContainerCmdletProvider provider CmdletProviderContext context
SystemManagementAutomionLocionGlobberResolveDriveQualifiedPhString ph CmdletProviderContext context Boolean allowNonexistingPhs CmdletProvider providerInstance
SystemManagementAutomionLocionGlobberGetGlobbedMonadPhsFromMonadPhString ph Boolean allowNonexistingPhs CmdletProviderContext context CmdletProvider providerInstance
SystemManagementAutomionLocionGlobberGetGlobbedProviderPhsFromMonadPhString ph Boolean allowNonexistingPhs CmdletProviderContext context ProviderInfo provider CmdletProvider providerInstance
SystemManagementAutomionSessionSteInternalCopyItemString phs String copyPh Boolean recurse CopyContainers copyContainers CmdletProviderContext context
MicrosoftPowerShellCommandsCopyItemCommandProcessRecordException No such ph EDisasterBackuptoLoc_20190123PrivilegesPrivileges_EDC_Bakcsv Exception SystemManagementAutomionItemNotFoundException Cannot find ph 'EDisasterBackuptoLoc_20190123PrivilegesPrivi
leges_EDC_Bakcsv' because it does not exist
SystemManagementAutomionLocionGlobberExpandMshGlobPhString ph Boolean allowNonexistingPhs PSDriveInfo drive ContainerCmdletProvider provider CmdletProviderContext context
SystemManagementAutomionLocionGlobberResolveDriveQualifiedPhString ph CmdletProviderContext context Boolean allowNonexistingPhs CmdletProvider providerInstance
SystemManagementAutomionLocionGlobberGetGlobbedMonadPhsFromMonadPhString ph Boolean allowNonexistingPhs CmdletProviderContext context CmdletProvider providerInstance
SystemManagementAutomionLocionGlobberGetGlobbedProviderPhsFromMonadPhString ph Boolean allowNonexistingPhs CmdletProviderContext context ProviderInfo provider CmdletProvider providerInstance
SystemManagementAutomionSessionSteInternalCopyItemString phs String copyPh Boolean recurse CopyContainers copyContainers CmdletProviderContext context
MicrosoftPowerShellCommandsCopyItemCommandProcessRecordException No such ph EDisasterBackuptoLoc_20190123PrivilegesPrivileges_SMH_Bakcsv Exception SystemManagementAutomionItemNotFoundException Cannot find ph 'EDisasterBackuptoLoc_20190123PrivilegesPrivi
leges_SMH_Bakcsv' because it does not exist
SystemManagementAutomionLocionGlobberExpandMshGlobPhString ph Boolean allowNonexistingPhs PSDriveInfo drive ContainerCmdletProvider provider CmdletProviderContext context
SystemManagementAutomionLocionGlobberResolveDriveQualifiedPhString ph CmdletProviderContext context Boolean allowNonexistingPhs CmdletProvider providerInstance
SystemManagementAutomionLocionGlobberGetGlobbedMonadPhsFromMonadPhString ph Boolean allowNonexistingPhs CmdletProviderContext context CmdletProvider providerInstance
SystemManagementAutomionLocionGlobberGetGlobbedProviderPhsFromMonadPhString ph Boolean allowNonexistingPhs CmdletProviderContext context ProviderInfo provider CmdletProvider providerInstance
SystemManagementAutomionSessionSteInternalCopyItemString phs String copyPh Boolean recurse CopyContainers copyContainers CmdletProviderContext context
MicrosoftPowerShellCommandsCopyItemCommandProcessRecord
This is a portion of my script:
#cleanse string and add to global string
function CleanseString($tempStr){
$temp2Str = $tempStr -replace "\-"
$temp3Str = $temp2Str -replace "\:"
$temp4Str = $temp3Str -replace "\/"
$temp5Str = $temp4Str -replace "\,"
$temp6Str = $temp5Str -replace "\."
$temp7Str = $temp6Str -replace "\*"
$temp8Str = $temp7Str -replace "\\"
$temp9Str = $temp8Str -replace "\("
$temp10Str = $temp9Str -replace "\)"
$temp11Str = $temp10Str -replace "\+"
$temp12Str = $temp11Str -replace "\["
$temp13Str = $temp12Str -replace "\]"
$temp14Str = $temp13Str -replace "\-"
$temp15Str = $temp14Str -replace "\&" #replace space with nothing
$temp16Str = $temp15Str+"`r`n" #add newline to error log so it's readable
$temp17Str = $temp16Str -replace "\#" #replace at symbol with nothing
$temp18Str = $temp17Str -replace "AT"#, "location" #replace AT with location
$temp19Str = $temp18Str -replace "at"#, "location" #replace at with location
return $temp19Str
}
[string] $errorCodeAsString = ""
foreach ($item in $global:ErrorStrings){
$errorCodeAsString += $item
}
if($errorCodeAsString -ne "")
{
$errorCodeAsString = CleanseString($errorCodeAsString)
write-output $errorCodeAsString
#$errorCodeAsString = "Error in Privilege script. Length error $errorCodeAsString.length " + $errorCodeAsString
$ScriptPath = Split-Path $MyInvocation.InvocationName
$ScriptPathFilename = Join-Path -Path $ScriptPath -Child "\EmailAlertFailure.ps1"
Invoke-Expression "$ScriptPathFilename $errorCodeAsString"
#Invoke-Expression "& `"$ScriptPath\EmailAlertFailure.ps1`" $errorCodeAsString"
Exit 99
}
Exit 0
This is the error message I get when I step over the invoke-expression line:
SystemManagementAutomionLocionGlobberExpandMshGlobPhString : The term 'SystemManagementAutomionLocionGlobberExpandMshGlobPhString' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if
a path was included, verify that the path is correct and try again.
At line:2 char:5
+ SystemManagementAutomionLocionGlobberExpandMshGlobPhString ph Boo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (SystemManagemen...MshGlobPhString:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
SystemManagementAutomionLocionGlobberResolveDriveQualifiedPhString : The term 'SystemManagementAutomionLocionGlobberResolveDriveQualifiedPhString' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of
the name, or if a path was included, verify that the path is correct and try again.
At line:3 char:5
+ SystemManagementAutomionLocionGlobberResolveDriveQualifiedPhStrin ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (SystemManagemen...alifiedPhString:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
SystemManagementAutomionLocionGlobberGetGlobbedMonadPhsFromMonadPhString : The term 'SystemManagementAutomionLocionGlobberGetGlobbedMonadPhsFromMonadPhString' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:4 char:5
+ SystemManagementAutomionLocionGlobberGetGlobbedMonadPhsFromMonadP ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (SystemManagemen...omMonadPhString:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
SystemManagementAutomionLocionGlobberGetGlobbedProviderPhsFromMonadPhString : The term 'SystemManagementAutomionLocionGlobberGetGlobbedProviderPhsFromMonadPhString' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:5 char:5
+ SystemManagementAutomionLocionGlobberGetGlobbedProviderPhsFromMon ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (SystemManagemen...omMonadPhString:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
SystemManagementAutomionSessionSteInternalCopyItemString : The term 'SystemManagementAutomionSessionSteInternalCopyItemString' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a
path was included, verify that the path is correct and try again.
At line:6 char:5
+ SystemManagementAutomionSessionSteInternalCopyItemString phs Stri ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (SystemManagemen...lCopyItemString:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
MicrosoftPowerShellCommandsCopyItemCommandProcessRecordException : The term 'MicrosoftPowerShellCommandsCopyItemCommandProcessRecordException' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the
name, or if a path was included, verify that the path is correct and try again.
At line:7 char:5
+ MicrosoftPowerShellCommandsCopyItemCommandProcessRecordException ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (MicrosoftPowerS...RecordException:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
SystemManagementAutomionLocionGlobberExpandMshGlobPhString : The term 'SystemManagementAutomionLocionGlobberExpandMshGlobPhString' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if
a path was included, verify that the path is correct and try again.
At line:8 char:5
+ SystemManagementAutomionLocionGlobberExpandMshGlobPhString ph Boo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (SystemManagemen...MshGlobPhString:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
SystemManagementAutomionLocionGlobberResolveDriveQualifiedPhString : The term 'SystemManagementAutomionLocionGlobberResolveDriveQualifiedPhString' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of
the name, or if a path was included, verify that the path is correct and try again.
At line:9 char:5
+ SystemManagementAutomionLocionGlobberResolveDriveQualifiedPhStrin ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (SystemManagemen...alifiedPhString:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
SystemManagementAutomionLocionGlobberGetGlobbedMonadPhsFromMonadPhString : The term 'SystemManagementAutomionLocionGlobberGetGlobbedMonadPhsFromMonadPhString' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:10 char:5
+ SystemManagementAutomionLocionGlobberGetGlobbedMonadPhsFromMonadP ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (SystemManagemen...omMonadPhString:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
SystemManagementAutomionLocionGlobberGetGlobbedProviderPhsFromMonadPhString : The term 'SystemManagementAutomionLocionGlobberGetGlobbedProviderPhsFromMonadPhString' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:11 char:5
+ SystemManagementAutomionLocionGlobberGetGlobbedProviderPhsFromMon ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (SystemManagemen...omMonadPhString:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
SystemManagementAutomionSessionSteInternalCopyItemString : The term 'SystemManagementAutomionSessionSteInternalCopyItemString' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a
path was included, verify that the path is correct and try again.
At line:12 char:5
+ SystemManagementAutomionSessionSteInternalCopyItemString phs Stri ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (SystemManagemen...lCopyItemString:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
MicrosoftPowerShellCommandsCopyItemCommandProcessRecordException : The term 'MicrosoftPowerShellCommandsCopyItemCommandProcessRecordException' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the
name, or if a path was included, verify that the path is correct and try again.
At line:13 char:5
+ MicrosoftPowerShellCommandsCopyItemCommandProcessRecordException ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (MicrosoftPowerS...RecordException:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
SystemManagementAutomionLocionGlobberExpandMshGlobPhString : The term 'SystemManagementAutomionLocionGlobberExpandMshGlobPhString' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if
a path was included, verify that the path is correct and try again.
At line:14 char:5
+ SystemManagementAutomionLocionGlobberExpandMshGlobPhString ph Boo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (SystemManagemen...MshGlobPhString:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
SystemManagementAutomionLocionGlobberResolveDriveQualifiedPhString : The term 'SystemManagementAutomionLocionGlobberResolveDriveQualifiedPhString' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of
the name, or if a path was included, verify that the path is correct and try again.
At line:15 char:5
+ SystemManagementAutomionLocionGlobberResolveDriveQualifiedPhStrin ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (SystemManagemen...alifiedPhString:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
SystemManagementAutomionLocionGlobberGetGlobbedMonadPhsFromMonadPhString : The term 'SystemManagementAutomionLocionGlobberGetGlobbedMonadPhsFromMonadPhString' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:16 char:5
+ SystemManagementAutomionLocionGlobberGetGlobbedMonadPhsFromMonadP ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (SystemManagemen...omMonadPhString:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
SystemManagementAutomionLocionGlobberGetGlobbedProviderPhsFromMonadPhString : The term 'SystemManagementAutomionLocionGlobberGetGlobbedProviderPhsFromMonadPhString' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:17 char:5
+ SystemManagementAutomionLocionGlobberGetGlobbedProviderPhsFromMon ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (SystemManagemen...omMonadPhString:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
SystemManagementAutomionSessionSteInternalCopyItemString : The term 'SystemManagementAutomionSessionSteInternalCopyItemString' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a
path was included, verify that the path is correct and try again.
At line:18 char:5
+ SystemManagementAutomionSessionSteInternalCopyItemString phs Stri ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (SystemManagemen...lCopyItemString:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
MicrosoftPowerShellCommandsCopyItemCommandProcessRecord : The term 'MicrosoftPowerShellCommandsCopyItemCommandProcessRecord' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At line:19 char:5
+ MicrosoftPowerShellCommandsCopyItemCommandProcessRecord
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (MicrosoftPowerS...ndProcessRecord:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Before I removed at or AT from the string parameter, the error message was telling me that AT is a deprecated command or something. The problem is that invoke-expression is looking into the string I'm passing and trying to execute the parameter, $errorCodeAsString. I tried the line for invoke-expression with the &, but the error message complains about & for that version.
I've been looking into the call command , but I'm not sure if I can use that instead of invoke-expression with a parameter. I'd also be open to suggestions of a better way to email my error message to myself.
*update:
I tried using
Invoke-Expression "&'$ScriptPathFilename $errorCodeAsString' "
with single quote, and get this error message:
& : The term 'C:\Users\me\Documents\2018\powershellFiles\EmailAlertFailure.ps1 Could not find a part of the ph ' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:2
+ &'C:\Users\me\Documents\2018\powershellFiles\EmailAlertFailure. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Users\me...part of the ph :String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I got it working with the following, using call operator:
& $ScriptPathFilename $errorCodeAsString
Using PowerShell ISE,
If I open the file below by clicking on the .ps1 file in windows explorer, when I run it with the green arrow, it works.
If use File->Open the same file, when I click the green arrow I get errors.
If I open it by clicking and then load it, it's fine, so something (the path?) is getting set when I double click that is not the other way...
Let me clarify... If I open the file one way(double click) it 'compiles' fine, if I open it the other way (file->Open) the exact same file does not 'compile'. I'm hoping to figure out why this is. My guess is that the path variable it uses to find the other files needed is set different via the two methods of opening (because many of the errors are 'not found')
here is the code of the file (it basically just calls a bunch of external stuff)
###########################################################
# RUN (hit the green arrow) TO INITIALIZE
############################################################
############################################################
# set defaults
$path = Get-Location
$ProjectName = $path.Path
$ProjectName = $ProjectName.Replace("D:\Project Files\", "")
$ProjectName = $ProjectName.Replace("\_Powershell", "")
$ProjectName = $ProjectName.Replace("\WebApp", "")
$ProjectName = $ProjectName.Replace("\Webapp", "")
write-host "Project Name found: " $ProjectName
$Project = $ProjectName
$RootPath = 'D:\Project Files\' + $Project + '\WebApp'
$ModulePath = 'D:\Project Files\' + $Project + '\WebApp\_PowerShell'
############################################################
# call this one to remove and reload the modules (if modules are modified)
function ReloadTemplates {
RemoveLoadedModule WPK
RemoveLoadedModule JcdcAddFileToProjectGui
RemoveLoadedModule JcdcEoAndMap
RemoveLoadedModule JcdcEoAndMapGui
RemoveLoadedModule JcdcDal
RemoveLoadedModule JcdcDalGui
RemoveLoadedModule JcdcBll
RemoveLoadedModule JcdcBLLGui
RemoveLoadedModule JcdcView
RemoveLoadedModule JcdcViewGui
RemoveLoadedModule JcdcController
RemoveLoadedModule JcdcControllerGui
RemoveLoadedModule JcdcAutoMap
RemoveLoadedModule JcdcAutoMapGui
RemoveLoadedModule JcdcReport
RemoveLoadedModule JcdcReportGui
RemoveLoadedModule JcdcCv
RemoveLoadedModule JcdcCvGui
RemoveLoadedModule ReadWriteXML
# load the Templates
LoadTemplates
}
function RemoveLoadedModule {
param($PathAndName)
if(Get-Module -name $PathAndName)
{
Remove-Module $PathAndName
}
}
############################################################
# call this one to load the modules
function LoadTemplates {
Import-Module WPK
Import-Module "$ModulePath\JcdcAddFileToProjectGui.psm1"
Import-Module "$ModulePath\JcdcEoAndMap.psm1"
Import-Module "$ModulePath\JcdcEoAndMapGui.psm1"
Import-Module "$ModulePath\JcdcDal.psm1"
Import-Module "$ModulePath\JcdcDalGui.psm1"
Import-Module "$ModulePath\JcdcBll.psm1"
Import-Module "$ModulePath\JcdcBLLGui.psm1"
Import-Module "$ModulePath\JcdcView.psm1"
Import-Module "$ModulePath\JcdcViewGui.psm1"
Import-Module "$ModulePath\JcdcController.psm1"
Import-Module "$ModulePath\JcdcControllerGui.psm1"
Import-Module "$ModulePath\JcdcAutoMap.psm1"
Import-Module "$ModulePath\JcdcAutoMapGui.psm1"
Import-Module "$ModulePath\JcdcReport.psm1"
Import-Module "$ModulePath\JcdcReportGui.psm1"
Import-Module "$ModulePath\JcdcCv.psm1"
Import-Module "$ModulePath\JcdcCvGui.psm1"
Import-Module "$ModulePath\ReadWriteXML.psm1"
Initialize-AddFileToProject $RootPath $Project
Initialize-EOMAPGui $RootPath $Project
Initialize-DALGui $RootPath $Project
Initialize-BLLGui $RootPath $Project
Initialize-ViewGui $RootPath $Project
Initialize-ControllerGui $RootPath $Project
Initialize-AutoMapGui $RootPath $Project
Initialize-ReportGui $RootPath $Project
Initialize-CVGui $RootPath $Project
Initialize-XMLArguments
}
############################################################
# load the Templates on Run (when green arrow is clicked)
ReloadTemplates
############################################################
# Type one of the following in the command window
#Select-A + <tab> = Select-AddFileToProject -To create file to add to project
#Select-B + <tab> = Select-BLLWhatToBuild -To add a BLL
#Select-C + <tab> = Select-ControllerWhatToBuild -To add a Controller
#Select-D + <tab> = Select-DALWhatToBuild -To add a DAL
#Select-E + <tab> = Select-EoAndMapBuild -To add a Eo and Map
#Select-M + <tab> = Select-MapBuild -To add a AutoMap
#Select-R + <tab> = Select-ReportWhatToBuild -To add a Report
#Select-Vi + <tab> = Select-ViewWhatToBuild -To add a View
#Select-Vm + <tab> = Select-VmCvOrExcel -To add a CV, VM, D:\PowerShellTemplatesArgsor Excel
Here are the errors
PS U:\> D:\Project Files\CIS3G\Webapp\_Powershell\ManualRun.ps1
Project Name found: U:\
Import-Module : The specified module 'D:\Project Files\U:\\WebApp\_PowerShell\JcdcAddFileToProjectGui.psm1' was not loaded because no valid module file was found in any module direc
tory.
At D:\Project Files\CIS3G\Webapp\_Powershell\ManualRun.ps1:61 char:18
+ Import-Module <<<< "$ModulePath\JcdcAddFileToProjectGui.psm1"
+ CategoryInfo : ResourceUnavailable: (D:\Project File...ProjectGui.psm1:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Import-Module : The specified module 'D:\Project Files\U:\\WebApp\_PowerShell\JcdcEoAndMap.psm1' was not loaded because no valid module file was found in any module directory.
At D:\Project Files\CIS3G\Webapp\_Powershell\ManualRun.ps1:62 char:18
+ Import-Module <<<< "$ModulePath\JcdcEoAndMap.psm1"
+ CategoryInfo : ResourceUnavailable: (D:\Project File...dcEoAndMap.psm1:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Import-Module : The specified module 'D:\Project Files\U:\\WebApp\_PowerShell\JcdcEoAndMapGui.psm1' was not loaded because no valid module file was found in any module directory.
At D:\Project Files\CIS3G\Webapp\_Powershell\ManualRun.ps1:63 char:18
+ Import-Module <<<< "$ModulePath\JcdcEoAndMapGui.psm1"
+ CategoryInfo : ResourceUnavailable: (D:\Project File...oAndMapGui.psm1:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Import-Module : The specified module 'D:\Project Files\U:\\WebApp\_PowerShell\JcdcDal.psm1' was not loaded because no valid module file was found in any module directory.
At D:\Project Files\CIS3G\Webapp\_Powershell\ManualRun.ps1:64 char:18
+ Import-Module <<<< "$ModulePath\JcdcDal.psm1"
+ CategoryInfo : ResourceUnavailable: (D:\Project File...ll\JcdcDal.psm1:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Import-Module : The specified module 'D:\Project Files\U:\\WebApp\_PowerShell\JcdcDalGui.psm1' was not loaded because no valid module file was found in any module directory.
At D:\Project Files\CIS3G\Webapp\_Powershell\ManualRun.ps1:65 char:18
+ Import-Module <<<< "$ModulePath\JcdcDalGui.psm1"
+ CategoryInfo : ResourceUnavailable: (D:\Project File...JcdcDalGui.psm1:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Import-Module : The specified module 'D:\Project Files\U:\\WebApp\_PowerShell\JcdcBll.psm1' was not loaded because no valid module file was found in any module directory.
At D:\Project Files\CIS3G\Webapp\_Powershell\ManualRun.ps1:66 char:18
+ Import-Module <<<< "$ModulePath\JcdcBll.psm1"
+ CategoryInfo : ResourceUnavailable: (D:\Project File...ll\JcdcBll.psm1:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Import-Module : The specified module 'D:\Project Files\U:\\WebApp\_PowerShell\JcdcBLLGui.psm1' was not loaded because no valid module file was found in any module directory.
At D:\Project Files\CIS3G\Webapp\_Powershell\ManualRun.ps1:67 char:18
+ Import-Module <<<< "$ModulePath\JcdcBLLGui.psm1"
+ CategoryInfo : ResourceUnavailable: (D:\Project File...JcdcBLLGui.psm1:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Import-Module : The specified module 'D:\Project Files\U:\\WebApp\_PowerShell\JcdcView.psm1' was not loaded because no valid module file was found in any module directory.
At D:\Project Files\CIS3G\Webapp\_Powershell\ManualRun.ps1:68 char:18
+ Import-Module <<<< "$ModulePath\JcdcView.psm1"
+ CategoryInfo : ResourceUnavailable: (D:\Project File...l\JcdcView.psm1:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Import-Module : The specified module 'D:\Project Files\U:\\WebApp\_PowerShell\JcdcViewGui.psm1' was not loaded because no valid module file was found in any module directory.
At D:\Project Files\CIS3G\Webapp\_Powershell\ManualRun.ps1:69 char:18
+ Import-Module <<<< "$ModulePath\JcdcViewGui.psm1"
+ CategoryInfo : ResourceUnavailable: (D:\Project File...cdcViewGui.psm1:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Import-Module : The specified module 'D:\Project Files\U:\\WebApp\_PowerShell\JcdcController.psm1' was not loaded because no valid module file was found in any module directory.
At D:\Project Files\CIS3G\Webapp\_Powershell\ManualRun.ps1:70 char:18
+ Import-Module <<<< "$ModulePath\JcdcController.psm1"
+ CategoryInfo : ResourceUnavailable: (D:\Project File...Controller.psm1:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Import-Module : The specified module 'D:\Project Files\U:\\WebApp\_PowerShell\JcdcControllerGui.psm1' was not loaded because no valid module file was found in any module directory.
At D:\Project Files\CIS3G\Webapp\_Powershell\ManualRun.ps1:71 char:18
+ Import-Module <<<< "$ModulePath\JcdcControllerGui.psm1"
+ CategoryInfo : ResourceUnavailable: (D:\Project File...trollerGui.psm1:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Import-Module : The specified module 'D:\Project Files\U:\\WebApp\_PowerShell\JcdcAutoMap.psm1' was not loaded because no valid module file was found in any module directory.
At D:\Project Files\CIS3G\Webapp\_Powershell\ManualRun.ps1:72 char:18
+ Import-Module <<<< "$ModulePath\JcdcAutoMap.psm1"
+ CategoryInfo : ResourceUnavailable: (D:\Project File...cdcAutoMap.psm1:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Import-Module : The specified module 'D:\Project Files\U:\\WebApp\_PowerShell\JcdcAutoMapGui.psm1' was not loaded because no valid module file was found in any module directory.
At D:\Project Files\CIS3G\Webapp\_Powershell\ManualRun.ps1:73 char:18
+ Import-Module <<<< "$ModulePath\JcdcAutoMapGui.psm1"
+ CategoryInfo : ResourceUnavailable: (D:\Project File...AutoMapGui.psm1:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Import-Module : The specified module 'D:\Project Files\U:\\WebApp\_PowerShell\JcdcReport.psm1' was not loaded because no valid module file was found in any module directory.
At D:\Project Files\CIS3G\Webapp\_Powershell\ManualRun.ps1:74 char:18
+ Import-Module <<<< "$ModulePath\JcdcReport.psm1"
+ CategoryInfo : ResourceUnavailable: (D:\Project File...JcdcReport.psm1:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Import-Module : The specified module 'D:\Project Files\U:\\WebApp\_PowerShell\JcdcReportGui.psm1' was not loaded because no valid module file was found in any module directory.
At D:\Project Files\CIS3G\Webapp\_Powershell\ManualRun.ps1:75 char:18
+ Import-Module <<<< "$ModulePath\JcdcReportGui.psm1"
+ CategoryInfo : ResourceUnavailable: (D:\Project File...cReportGui.psm1:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Import-Module : The specified module 'D:\Project Files\U:\\WebApp\_PowerShell\JcdcCv.psm1' was not loaded because no valid module file was found in any module directory.
At D:\Project Files\CIS3G\Webapp\_Powershell\ManualRun.ps1:76 char:18
+ Import-Module <<<< "$ModulePath\JcdcCv.psm1"
+ CategoryInfo : ResourceUnavailable: (D:\Project File...ell\JcdcCv.psm1:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Import-Module : The specified module 'D:\Project Files\U:\\WebApp\_PowerShell\JcdcCvGui.psm1' was not loaded because no valid module file was found in any module directory.
At D:\Project Files\CIS3G\Webapp\_Powershell\ManualRun.ps1:77 char:18
+ Import-Module <<<< "$ModulePath\JcdcCvGui.psm1"
+ CategoryInfo : ResourceUnavailable: (D:\Project File...\JcdcCvGui.psm1:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Import-Module : The specified module 'D:\Project Files\U:\\WebApp\_PowerShell\ReadWriteXML.psm1' was not loaded because no valid module file was found in any module directory.
At D:\Project Files\CIS3G\Webapp\_Powershell\ManualRun.ps1:78 char:18
+ Import-Module <<<< "$ModulePath\ReadWriteXML.psm1"
+ CategoryInfo : ResourceUnavailable: (D:\Project File...adWriteXML.psm1:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
The term 'Initialize-AddFileToProject' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was includ
ed, verify that the path is correct and try again.
At D:\Project Files\CIS3G\Webapp\_Powershell\ManualRun.ps1:80 char:29
+ Initialize-AddFileToProject <<<< $RootPath $Project
+ CategoryInfo : ObjectNotFound: (Initialize-AddFileToProject:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
The term 'Initialize-EOMAPGui' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, veri
fy that the path is correct and try again.
At D:\Project Files\CIS3G\Webapp\_Powershell\ManualRun.ps1:81 char:24
+ Initialize-EOMAPGui <<<< $RootPath $Project
+ CategoryInfo : ObjectNotFound: (Initialize-EOMAPGui:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
The term 'Initialize-DALGui' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
At D:\Project Files\CIS3G\Webapp\_Powershell\ManualRun.ps1:82 char:22
+ Initialize-DALGui <<<< $RootPath $Project
+ CategoryInfo : ObjectNotFound: (Initialize-DALGui:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
The term 'Initialize-BLLGui' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
At D:\Project Files\CIS3G\Webapp\_Powershell\ManualRun.ps1:83 char:22
+ Initialize-BLLGui <<<< $RootPath $Project
+ CategoryInfo : ObjectNotFound: (Initialize-BLLGui:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
The term 'Initialize-ViewGui' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verif
y that the path is correct and try again.
At D:\Project Files\CIS3G\Webapp\_Powershell\ManualRun.ps1:84 char:23
+ Initialize-ViewGui <<<< $RootPath $Project
+ CategoryInfo : ObjectNotFound: (Initialize-ViewGui:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
The term 'Initialize-ControllerGui' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included,
verify that the path is correct and try again.
At D:\Project Files\CIS3G\Webapp\_Powershell\ManualRun.ps1:85 char:29
+ Initialize-ControllerGui <<<< $RootPath $Project
+ CategoryInfo : ObjectNotFound: (Initialize-ControllerGui:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
The term 'Initialize-AutoMapGui' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, ve
rify that the path is correct and try again.
At D:\Project Files\CIS3G\Webapp\_Powershell\ManualRun.ps1:86 char:26
+ Initialize-AutoMapGui <<<< $RootPath $Project
+ CategoryInfo : ObjectNotFound: (Initialize-AutoMapGui:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
The term 'Initialize-ReportGui' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, ver
ify that the path is correct and try again.
At D:\Project Files\CIS3G\Webapp\_Powershell\ManualRun.ps1:87 char:25
+ Initialize-ReportGui <<<< $RootPath $Project
+ CategoryInfo : ObjectNotFound: (Initialize-ReportGui:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
The term 'Initialize-CVGui' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
At D:\Project Files\CIS3G\Webapp\_Powershell\ManualRun.ps1:88 char:21
+ Initialize-CVGui <<<< $RootPath $Project
+ CategoryInfo : ObjectNotFound: (Initialize-CVGui:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
The term 'Initialize-XMLArguments' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included,
verify that the path is correct and try again.
At D:\Project Files\CIS3G\Webapp\_Powershell\ManualRun.ps1:89 char:28
+ Initialize-XMLArguments <<<<
+ CategoryInfo : ObjectNotFound: (Initialize-XMLArguments:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Is there some way to set the path when I do a file open so this does not occur?
There are different versions of this folder and file for each project, as it's used to generate project specific code...
so the solution needs to work for that scenerio too please.
Not sure to understand your question, but if you want to really begin at the location of your script, you can use $MyInvocation automatic var.
$MyInvocation.MyCommand.Path will give you the path of your script (.PS1 file) and then you can use Split-Path to find its directory location. I think that in your case Get-Location does not always return the path you think about.
$ModulePath = 'D:\Project Files\' + $Project + '\WebApp\_PowerShell'
Import-Module "$ModulePath\JcdcAddFileToProjectGui.psm1"
Results in
'D:\Project Files\U:\WebApp_PowerShell\JcdcAddFileToProjectGui.psm1'
Windows does not allow more than one drive letter in a single path. Yours has U: in it. $Project = 'U:' at the time $ModulePath was evaluated. That is your starting working directory for PowerShell.
Bottom line is that you're using paths relative to where the script is run. When you open powershell, it sets starting location from your profile, or default location if you don't have one in your profile. When you launch from a file, it uses that file's location.
You seem to be hard coding a separate set of script + modules, etc., for each project, but they have defined names that are consistent across the range of projects. I suggest you hardcode the module locations in each script.
I'd also suggest that you reconsider this style of coding. It must be a nightmare to change something. What if you created a single script that loads a single module. Then create a config file for each project and a shortcut to your script that loads the main script with the customized parts read from the config file.
The modules lay in same directory like a script? If it true, then reason of issue is in curent directoty. Add folowing line in begin or before you operate with modules:
Set-Location "<...>"
and lets type path to the folder with your script instead <...>.
I personally like using the default Var $PSScriptRoot
In your case I would have started the script
Set-Location $PSScripRoot
this will set the location to where ever your script is this should make it so either a double click or an open file location and press play will excute your script
you can either add my line in front of $path = Get-Location or you can eliminate the $path line entirely and just use the $PSScriptRoot line but then you also need to replace the $path variable with $PSScriptRoot in your entire script
As others have said when you double click your script Powershell uses that path if you open manually via ISE it does not (it uses whatever the last path u set in ISE instead)
what the line Set-Location $PSScriptRoot does is take the local path of your script always regardless how you choose to start it
I hope this helps!