[英]Powershell I don't get the log to work
我最近开始使用Powershell,并且一直在尝试尽可能多地使用它,但是我感到非常沮丧。 我有这段代码可以满足我的要求,但是日志不起作用,但是我没有收到错误:
Function logWrite
{
param ([string]$logstring)
$Computer = gc env:computername
$date = $(Get-Date -UFormat "%d-%m-%Y")
$Logfile = C:\Windows\Temp\Key-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:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.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:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.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:\SOFTWARE\Microsoft\.NetFramework\v4.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:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.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:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319 -Name SchUseStrongCrypto -PropertyType DWord -Value 0 -ErrorAction SilentlyContinue -Verbose
logWrite $Stamp
logWrite "The Key has been created"
}
}
任何帮助,链接或指导都会有所帮助。
在此先感谢您的时间。
问候
尝试
$Logfile = "C:\Windows\Temp\Key-KB-Testing-$Computer-$date.log"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.