运行我的 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