术语“'不被识别为已识别的cmdlet的名称

时间:2015-01-15 15:05:58

标签: multithreading powershell powershell-v3.0

我已经看到很多这些项目,但似乎没有用户定义的功能。

我是PowerShell的新手,并创建了一个脚本来运行net view命令,然后测试我是否可以访问该目录:

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
}
}

这些是我加载的4个函数,当我在单个主机上运行它们时它们工作但是当我尝试多线程它们时,我得到一个错误“”运行'netviewall'一词不被识别为cmdlet,函数,脚本文件或可操作程序。

任何帮助将不胜感激。上面的一些脚本是在线获得的,并略微编辑以满足我的需求,但它们都有效。您可以提供任何帮助。

仅供参考我尝试了4种不同的多线程,他们都给了我这个错误。我确信它很简单,我不知道

谢谢, 乔恩

0 个答案:

没有答案