gpt4 book ai didi

powershell - 找不到类型[System.Net.Webutility]

转载 作者:行者123 更新时间:2023-12-02 23:54:06 25 4
gpt4 key购买 nike

我正在尝试在Windows 2008 Server上运行脚本,但是不确定是否可以运行它。我收到以下错误消息:
Unable to find type [System.Net.Webutility]: make sure that the assembly containing this type is loaded.
如前所述,我试图在2008 Server上运行它。根据System.Net.Webutility文档,自Windows 8开始提供。是SOL还是可以解决?

下面是我的代码:

#account of the Shared Mailbox
$account = "MyAccount@myaddress.com"

#date to append to new file name
$date = Get-Date -Format yyyyMMdd

#Formatted date to search Inbox
$searchDate = Get-Date -Format M/dd/yyyy
Write-Host "Searching for $searchDate..."

#file to save attachment as
$newFileName = "Record_Import_$date.html"

#file name for the XML File
$newXMLFileName = "Record_Import_$date.xml"

#File paths Main directory, HTML, HTML Record and Raw folders
$newFilePath = "\\PathA\"
$newHTMLPath = "\\PathB\"
$newHTMLRecordPath = "\\PathC\"
$rawFilePath = "\\PathD\"

#Go into Outlook and get the MAPI
$mail = New-Object -ComObject outlook.application
$mailNS = $mail.GetNamespace("MAPI")

#print out Accounts in MAPI
foreach($email in $mailNS.Folders)
{
Write-Host $email.Name
}

Write-Host "---"

#get the account and Inbox we want
$myAcount = $mailNS.Folders | ? {$_.Name -eq $account}

#Print out folders in Shared Inbox
foreach($folder in $myAcount.Folders)
{
Write-Host $folder.Name
}

#Get the inbox of the account
$myInbox = $myAcount.Folders | ? {$_.Name -eq "Inbox"};

#loop through the Inbox and get any Attachments with the extension of ".EXCEL"
foreach ($f in $myInbox)
{
foreach($i in $f.Items)
{

if($i.ReceivedTime.Date -eq $searchDate)
{

Write-Host "---"
Write-Host "Checking "$i.Subject"..."
Write-Host "---"

foreach($a in $i.Attachments)
{
if($a.FileName -like "*.MYFILETYPE")
{
#Move the attachment to the desired directory and save the raw file in the Raw directory
$a.SaveAsFile((Join-Path $newHTMLPath $newFileName))
$a.SaveAsFile((Join-Path $rawFilePath $a.FileName))
Write-Host $a.FileName " Saved as HTML"

#Open the HTML file and parse it
$htmlString = Get-Content (Join-Path $newHTMLPath $newFileName)
[xml]$html = [System.Net.WebUtility]::HtmlDecode($htmlString);

#Get the date of the HTML File
$dateSpan = $html.DocumentElement.SelectSingleNode('//tr[2]/td[2]').InnerText

#Reset the newXMLFileName and newFileName variables to include the new date
$newXMLFileName = "BAI_Import_$dateSpan.xml"
$newFileName = "BAI_Import_$dateSpan.html"
$a.SaveAsFile((Join-Path $newHTMLRecordPath $newFileName))

Write-Host "Date for XML is $dateSpan"

$xml = @'
<?xml version="1.0" encoding="utf-8" ?>
<Date>
'@;
$xml = $xml += $dateSpan
$xml = $xml += @'
</Date>
<Cash Activities>

'@;
$rows = $html.DocumentElement.SelectNodes('//tr');
$pastVariance = $false
foreach ($row in $rows)
{
if ($row.GetAttribute('class') -eq 'c12')
{
$xml += "`t<Cash Activity>`n";
$spans = $row.SelectNodes('.//descendant::span[@class]');
if ($spans.Count -eq 2)
{
$spanCheck = $spans[0].InnerText.Trim();
Write-Host $spanCheck

if($pastVariance)
{
$xml += "`t`t<Activity>Unknown Cash Activity</Activity>`n";
} Else
{
$xml += "`t`t<Activity>$($spans[0].InnerText.Trim())</Activity>`n";
}
$xml += "`t`t<Balance>$($spans[1].InnerText.Trim())</Balance>`n";

#check to make sure that this line was a Variance
if($spanCheck -match "Variance")
{
$pastVariance = $true
}

}
$xml += "`t</Cash Activity>`n";
}
}


$xml += @'
</Cash Activities>
'@;
Write-Host $xml
$xml | Out-File (Join-Path $newFilePath $newXMLFileName)
Write-Host $i.Subject " Exported to XML File"
}#End of EXCEL Check
}
}

}
}

最佳答案

.NET Framework 1.1 之后,就可以使用System.Web.HttpUtility.HtmlDecode了,因此您可以选择完成以下相同的操作:

Add-Type -AssemblyName System.Web;

$encoded = '<span class="c2">FRIDAY&nbsp;&nbsp;</span>';
[System.Web.HttpUtility]::HtmlDecode($encoded);

关于powershell - 找不到类型[System.Net.Webutility],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50162793/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com