I have seen a lot of these items out there but none seem to be for a user defined function.
I am new to powershell and have created a script to run the net view command and then test if I have access to the directory:
Function get-netview{
param($hosts)
(net view \\$hosts) | % { if($_.IndexOf(' Disk ') -gt 0){ $_.Split(' ')[0] }}
}
function fastping{
[CmdletBinding()]
param(
[String]$computername = "127.0.0.1",
[int]$delay = 100
)
$ping = new-object System.Net.NetworkInformation.Ping
# see http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ipstatus%28v=vs.110%29.aspx
try {
if ($ping.send($computername,$delay).status -ne "Success") {
return $false;
}
else {
return $true;
}
} catch {
return $false;
}
}
function get-dir{
param($hosts,$dir)
$errors=@()
$i = 0
Get-ChildItem \\$hosts\$dir -ea SilentlyContinue -ErrorVariable +errors | Out-Null
if ($errors.count -gt 0){
$outvar = "Access Denied",$hosts,$dir,"0"
$outvar –join “,” | Out-File .\outfile.txt -append
}
else{
$x = (Get-ChildItem \\$hosts\$dir).count
if ($x -gt 0) {
$outvar = "Access Granted",$hosts,$dir,$x
$outvar –join “,” | out-file .\outfile.txt -append
}
else{
write-host ("Empty Folder",$hosts,$dir,"0") -Separator ","
$outvar = "Empty Folder",$hosts,$dir,"0"
$outvar –join “,” | Out-File .\zzfile.txt -append
}
}
}
function run-netviewall{
param($hosts)
$pings = fastping $hosts 250
if ($pings) {
foreach ($dir in get-netview $hosts) {get-dir $hosts $dir | out-file temtest.txt}
}else{
$hosts | out-file .\notonline.txt
}
}
These are the 4 function I have loaded and they work when i Run them on a single host but when i try to multithread them I get an error that ""The term 'run-netviewall' is not recognized as the name of a cmdlet, function, script file, or operable program.
Any help would be appreciated. Some of the scripts above were obtained online and edited slightly to meet my needs but they work. Any help you can provide would be appreciated.
FYI I have tried 4 different multithreaders and they all give me that error. I'm sure its stomething simple I didn't know about to
Thanks, Jon