0

运行我的 powershell 脚本时出现以下错误。我认为它以前用来炒菜。任何想法可能是个问题!

Set-Content : The network name cannot be found.
At C:\inetpub\IISscripts\SubIndexGenHyperlinksInHtml.ps1:20 char:18
+   } | Set-Content <<<<  "$fldr.htm"
    + CategoryInfo          : WriteError: (\\nclient\diskuse.htm:String) [Set-Content], IOException
    + FullyQualifiedErrorId : GetContentWriterIOError,Microsoft.PowerShell.Commands.SetContentCommand

powershell 代码如下:

$basedir = '\\nclient\diskuse'
$exp     = [regex]::Escape($basedir)
$server  = 'http://nclient/diskuse'

# This is server-side SubIndex page generating code

function Create-HtmlList($fldr) {
  Get-ChildItem $fldr -Force | sort-object -property LastWriteTime -Descending |
    select Name, LastWriteTime, 
    @{n="URL";e={$_.FullName -replace $exp, $server -replace '\\', '/'}} |
  ConvertTo-Html -Fragment URL, Name, LastWriteTime `
    -PreContent '<html><head><style>BODY{background-color:#A987CC;}
    TABLE cellpadding="2"{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;.center { margin:auto; width:70%; };}
    TH{border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color:#99CCFF}
    TD{border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color:PaleGoldenrod}</style><title>User</title></head><body>' `
    -PostContent '</body></html>' |
  % { $_ -replace '<th>.*</th>','<th>SCAN BY DATE</th>' `
         -replace '<td>(.*?)</td><td>(.*?)</td><td>(.*?)</td>',
                  '<td><a href="$1">$2</a> $3</td>'
  } | Set-Content "$fldr.htm"
}

# list files in $basedir:
Create-HtmlList $basedir

# list files in all subfolders of $basedir:
Get-ChildItem $basedir -Recurse -Force |
  ? { $_.PSIsContainer } |
  % {
    Create-HtmlList $_.FullName
  }

我还可以正常运行以下脚本:

$basedir = '\\nclient\diskuse'
$exp     = [regex]::Escape($basedir)
$server  = 'http://nclient/diskuse'


Get-ChildItem $basedir -Force | ? { -not $_.psiscontainer } |
  select Name, LastWriteTime,
    @{n="URL";e={$_.FullName -replace $exp, $server -replace '\\', '/'}} |
  ConvertTo-Html -Fragment URL, Name, LastWriteTime `
    -PreContent '<html><head><style>BODY{background-color:#A987CC;}
    TABLE cellpadding="2"{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;.center { margin:auto; width:70%; };}
    TH{border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color:#99CCFF}
    TD{border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color:PaleGoldenrod}</style><title>User</title></head><body>' `
    -PostContent '</body></html>' |
  % { $_ -replace '<th>.*</th>','<th>COMPUTERS</th>' `
         -replace '<td>(.*?)</td><td>(.*?)</td><td>(.*?)</td>',
                  '<td><a href="$1">$2</a> $3</td>'
  } | Set-Content "\\nclient\diskuse\index.htm"

# this is server-side index page generating code
4

2 回答 2

0

The network name cannot be found.

您正在Get-ChildItem远程(网络)文件夹上执行:名称查找失败。可能服务器不可用或无法访问。

于 2013-09-18T07:59:25.047 回答
0

$fldr是一个文件夹,然后即:

$fldr = \\nclient\diskuse
Set-Content "$fldr.htm" 

尝试\\nclient将此文件保存在此路径中diskuse.htm

于 2013-09-18T09:13:59.400 回答