运行我的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
答案 0 :(得分:0)
The network name cannot be found.
您正在远程(网络)文件夹上执行Get-ChildItem
:名称查找失败。也许服务器不可用或无法访问。
答案 1 :(得分:0)
$fldr
是一个文件夹,即:。
$fldr = \\nclient\diskuse
Set-Content "$fldr.htm"
尝试在此路径\\nclient
中保存此文件diskuse.htm