【发布时间】:2017-11-21 21:28:44
【问题描述】:
我需要一些指令来滚动服务器列表、远程编辑每个服务器的一些注册表项并将每个注册表项更新的输出保存在 .csv 文件中。 我尝试了我的脚本,它们似乎可以工作,但我无法过滤结果并仅(并且准确地)保存我在 .csv 中需要的内容:
脚本 1:
$Invocation = (Get-Variable MyInvocation -Scope 0).Value
$LocalDir = Split-Path $Invocation.MyCommand.Path
$Computers = Get-Content $LocalDir'\HostsList.txt'
$Results = foreach ($Computer in $Computers) {
Invoke-Command -ComputerName $Computer -FilePath $LocalDir'\autologon_editor.ps1' -ArgumentList $Computer
}
$Results | Export-Csv -NoTypeInformation -Path $LocalDir'\ResultsAutologon.csv'
脚本 2:
Param(
[Parameter(Mandatory=$true,
ValueFromPipeline=$true)]
[string[]]$Computer
)
$Path = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon'
$Property1 = 'DefaultUserName'
$Property2 = 'DefaultPassword'
$Value1 = 'NewUserName-new4'
$Value2 = 'NewPassword-new4'
if (Test-Connection -ComputerName $Computer -Count 1 -Quiet) {
try {
Set-ItemProperty -Path $Path -Name $Property1 -Value $Value1 -ErrorAction 'Stop'
Set-ItemProperty -Path $Path -Name $Property2 -Value $Value2 -ErrorAction 'Stop'
$Status = 'Username and password set ok'
} catch {
$Status = 'Username or password set ko'
}
} else {
$Status = 'Unreachable'
}
Get-ItemProperty -Path $Path
RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters ,1 ,True
$Properties = @{
'Computer' = $Computer;
'Status' = $Status
}
$Record = New-Object -TypeName PSObject -Property $Properties
问题
我的过滤器不起作用:.csv 文件不包含“计算机”和“状态”字段,但包含以下列表:
“Userinit”、“LegalNoticeText”、“Shell”、“LegalNoticeCaption”、“DebugServerCommand”、“ForceUnlockLogon”、“ReportBootOk”、“VMApplet”、“AutoRestartShell”、“PowerdownAfterShutdown”、“ShutdownWithoutLogon”、“Background” 、“PreloadFontFile”、“PasswordExpiryWarning”、“CachedLogonsCount”、“WinStationsDisabled”、“PreCreateKnownFolders”、“DisableCAD”、“scremoveoption”、“ShutdownFlags”、“AutoLogonSID”、“LastUsedUsername”、“DefaultUserName”、“DefaultPassword”、“ PSPath"、"PSParentPath"、"PSChildName"、"PSDrive"、"PSProvider"、"PSComputerName"、"RunspaceId"、"PSShowComputerName"
【问题讨论】:
标签: powershell csv registry