Erwin Pombett
asked on
i'm learning powershell modules. So far i've created a module, i can see it in the list when Get-Module -listavailable, but there's no ExportedCommands ? how can i track the error ?
Hello everyone,
I'm working on powershell, i'm working on modules as i'd like to have my code cleany wrote in modules.
So far i know how to list the available modules, and lucky me : my module is visible in that list that point to the "program files/windowPowerShell/Mod ules folder".
So my .psm1 file and my psd1 files are correct and in a folder having the same name.
So then i can import it with "Import-module -Name <modulename>"
On "Get-Module -ListAvalaible" The column with ExportedCommands is empty for my module.
then i can not launch my cmdlets or functions, they dont exist in the session.
My Questions :
- how to check the problem i dont know what to do in order to have more infos ?
- is the code ? is the module ? .....
Get-Command -Module mymodule <- gives me no output as if my module has no functions.
Thanks for your help.
toshi
I'm working on powershell, i'm working on modules as i'd like to have my code cleany wrote in modules.
So far i know how to list the available modules, and lucky me : my module is visible in that list that point to the "program files/windowPowerShell/Mod
So my .psm1 file and my psd1 files are correct and in a folder having the same name.
So then i can import it with "Import-module -Name <modulename>"
On "Get-Module -ListAvalaible" The column with ExportedCommands is empty for my module.
then i can not launch my cmdlets or functions, they dont exist in the session.
My Questions :
- how to check the problem i dont know what to do in order to have more infos ?
- is the code ? is the module ? .....
Get-Command -Module mymodule <- gives me no output as if my module has no functions.
Thanks for your help.
toshi
ASKER
hello Subsun , first of every thing : A Happy New Year.
the verbose attribut wont give me more infos.
here's my module file:
Write-Host "Loading tshr package with utilities" -ForegroundColor Green
#Write-Host "from C:\Program Files\WindowsPowerShell\Mo dules\Tshr .GetDataOu tOfFile" -ForegroundColor Green
function tshr-TestMethod() {
return "Hello"
}
#function tshr-GetMachinesNames_OutO fDataFile_ InArray( [string]$aFilePath="M:\PS_ scripts\ma chinesTest .otl" )
#function tshr-GetMachinesNames-OutO fDataFile- InArray( [string]$aFilePath="M:\PS_ scripts\ma chinesTest .otl" )
function tshr-GetMachinesNamesOutOf DataFileIn Array( [string]$aFilePath="M:\PS_ scripts\ma chinesTest .otl" )
{
<#
.SYNOPSYS
Will return all machines under test in an array
.EXAMPLE
first param can be a file with csv content. First column should be machine names
#>
$linesWithData = Get-Content $aFilePath
# ^ if no paramt received, will collect machines from default paramter.
$machinesNames = @()
# ^ return an array of string
foreach($aLine in $linesWithData){
$machinesNames += $aLine.Split(";")[0].ToStr ing().Trim ();
}
return $machinesNames;
}
#function tshr-GetMachineAndTestUser _ForMachin e( [string]$aFilePath="M:\PS_ scripts\ma chinesTest .otl" )
#function tshr-GetMachineAndTestUser -ForMachin e( [string]$aFilePath="M:\PS_ scripts\ma chinesTest .otl" )
function tshr-GetMachineAndTestUser ForMachine ( [string]$aFilePath="M:\PS_ scripts\ma chinesTest .otl" )
{
<#
.SYNOPSYS
will return objects with two members: machine name and test user for the machine
.EXAMPLE
we are going to display ....
#>
$linesWithInfos = Get-Content $aFilePath
# ^ if no paramt received, will collect machines from default paramter.
$oMyCouples = @()
# ^ return an array of string
foreach($lineOneMachine in $linesWithInfos)
{
$hostname = $lineOneMachine.Split(";") [0].Trim() ;
$username = $lineOneMachine.Split(";") [1].Trim() ;
$oMyCouples +=
@{
hostname="$hostname";
username="$username";
}
}
return $oMyCouples;
}
function tshr-testInclusionOfFile()
{
Write-Host "ok, the file is in the sript"
}
thank in adavance
toshi
the verbose attribut wont give me more infos.
here's my module file:
Write-Host "Loading tshr package with utilities" -ForegroundColor Green
#Write-Host "from C:\Program Files\WindowsPowerShell\Mo
function tshr-TestMethod() {
return "Hello"
}
#function tshr-GetMachinesNames_OutO
#function tshr-GetMachinesNames-OutO
function tshr-GetMachinesNamesOutOf
{
<#
.SYNOPSYS
Will return all machines under test in an array
.EXAMPLE
first param can be a file with csv content. First column should be machine names
#>
$linesWithData = Get-Content $aFilePath
# ^ if no paramt received, will collect machines from default paramter.
$machinesNames = @()
# ^ return an array of string
foreach($aLine in $linesWithData){
$machinesNames += $aLine.Split(";")[0].ToStr
}
return $machinesNames;
}
#function tshr-GetMachineAndTestUser
#function tshr-GetMachineAndTestUser
function tshr-GetMachineAndTestUser
{
<#
.SYNOPSYS
will return objects with two members: machine name and test user for the machine
.EXAMPLE
we are going to display ....
#>
$linesWithInfos = Get-Content $aFilePath
# ^ if no paramt received, will collect machines from default paramter.
$oMyCouples = @()
# ^ return an array of string
foreach($lineOneMachine in $linesWithInfos)
{
$hostname = $lineOneMachine.Split(";")
$username = $lineOneMachine.Split(";")
$oMyCouples +=
@{
hostname="$hostname";
username="$username";
}
}
return $oMyCouples;
}
function tshr-testInclusionOfFile()
{
Write-Host "ok, the file is in the sript"
}
thank in adavance
toshi
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot for your wild guess, you were right.
the thing is that when i just started playing with the module i could see the ExportedCommands column filled with the functions names......i did not pay attention when i lost them...
i didn't know the relation was necessary as they both are in the module folder. I 'll discover that soon ;)
thanks a lot again
the thing is that when i just started playing with the module i could see the ExportedCommands column filled with the functions names......i did not pay attention when i lost them...
i didn't know the relation was necessary as they both are in the module folder. I 'll discover that soon ;)
thanks a lot again
You are welcome!
Open in new window
Did you see the command in ExportedCommands section when you use Get-Module -ListAvailableIf not you can post the module which you are using so we can try to figure out the issue..