我最近从PowerShell开始,我一直在尝试尽可能多地使用它,但是我感到非常沮丧。我有这样的代码,可以做我想要的,但是日志不起作用,但我不会遇到错误:
Function logWrite
{
param ([string]$logstring)
$Computer = gc env:computername
$date = $(Get-Date -UFormat "%d-%m-%Y")
$Logfile = C:WindowsTempKey-KB-Testing-$Computer-$date.log
Add-content -Path $Logfile -Value $logstring
}
$Stamp = (Get-Date).toString("dd/MM/yyyy HH:mm:ss")
logWrite "Testing KB3142037"
$KB3142037result= gwmi -cl win32_reliabilityRecords -filter "sourcename = 'Microsoft-Windows-WindowsUpdateClient'" | where { $_.message -match 'KB3142037'} | select -Expand Message
logWrite $Stamp
logWrite "Testing KB3142033"
$KB3142033result= gwmi -cl win32_reliabilityRecords -filter "sourcename = 'Microsoft-Windows-WindowsUpdateClient'" | where { $_.message -match 'KB3142033'} | select -Expand Message
logWrite $Stamp
$Key = Get-ItemProperty HKLM:SOFTWAREWow6432NodeMicrosoft.NetFrameworkv4.0.30319 -Name SchUseStrongCrypto | Select-Object -ExpandProperty SchUseStrongCrypto
$arquitecture = (gwmi win32_computersystem).SystemType
If ($arquitecture -eq "x32-based PC")
{
If ($Key -eq $true)
{
logWrite "The key exist and the value is '$Key'"
if ($Key -ne "0")
{
Set-ItemProperty -Path 'HKLM:SOFTWAREWow6432NodeMicrosoft.NetFrameworkv4.0.30319' -Name 'SchUseStrongCrypto' -Value '0' -Type DWord -ErrorAction SilentlyContinue -Verbose
logWrite "The key has been modified"
logWrite $Stamp
}
}
Else {
logWrite "There is no key. New registry key will be created"
New-ItemProperty -Path HKLM:SOFTWAREMicrosoft.NetFrameworkv4.0.30319 -Name SchUseStrongCrypto -PropertyType DWord -Value 0 -ErrorAction SilentlyContinue -Verbose
logWrite $Stamp
logWrite "The Key has been created"
}
}
Else
{
If ($Key -eq $true)
{
logWrite "The key exist and the value is '$Key'"
if ($Key -ne "0")
{
Set-ItemProperty -Path 'HKLM:SOFTWAREWow6432NodeMicrosoft.NetFrameworkv4.0.30319' -Name 'SchUseStrongCrypto' -Value '0' -Type DWord -ErrorAction SilentlyContinue -Verbose
logWrite "The key has been modified"
logWrite $Stamp
}
}
Else {
logWrite "There is no key. New registry key will be created"
New-ItemProperty -Path HKLM:SOFTWAREWow6432NodeMicrosoft.NetFrameworkv4.0.30319 -Name SchUseStrongCrypto -PropertyType DWord -Value 0 -ErrorAction SilentlyContinue -Verbose
logWrite $Stamp
logWrite "The Key has been created"
}
}
任何帮助,链接或指导都会有所帮助。
事先感谢您的时间。
问候
尝试
$Logfile = "C:WindowsTempKey-KB-Testing-$Computer-$date.log"