Dear All,
I want to design a module where I want to use it in this way:
import-module my_module
In the same console, later on, I use my_module and start using it. I have built a script:
#*******************************************************************
$filename=read-host Enter hostnames file
Function ping-host {
BEGIN {}
PROCESS {
$results = gwmi -q "SELECT * FROM Win32_Pingstatus WHERE Address = '$_'"
if ($results.statuscode -eq 0){
write-host "$_ is pingable"
}else {
write-host "$_ is not pinging"
}
}
END {}
}
get-content $filename | ping-host
I converted it to module, I execute get-module -listavailable, this ping-host module is visible. When I enter import-module ping-host, it opens the module and waits for the user to enter the servernames file. But I want it in the below way.
I execute import-module ping-host
Now nothing should be executed. Later on, I use, ping-host c:\servernames.txt, ping-host c:\server\servernames.txt then this script should be executed and result should come. But now, when i say import-module ping-host, it says Enter hostnames file.
For ex, check this pause script:
function Pause ($Message="Press any key to continue...")
{
Write-Host -NoNewLine $Message
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Write-Host ""
}
When I convert it to module and execute, import-module pause. nothing happens
later on, in the same console if I execute pause, it says, "press any key" I want my script to work in this way. Hope my doubt is clear... Please help...
Thanks,
Chaitanya.