你好,我希望你们能帮我解决一个困扰我几天的问题。当我将脚本的结果导出到csv文件时,我无法得到正确的输出。
function Get-ScheduledTask { [CmdletBinding()] param( [Parameter( Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] [String[]]$ComputerName, [Parameter(Mandatory=$false)] [String[]]$RunAsUser, [Parameter(Mandatory=$false)] [String[]]$TaskName, [parameter(Mandatory=$false)] [alias("WS")] [switch]$WithSpace ) Begin { $Script:Tasks = @() } Process { $schtask = schtasks.exe /query /s $ComputerName /V /FO CSV | ConvertFrom-Csv Write-Verbose "Getting scheduled Tasks from: $ComputerName" if ($schtask) { foreach ($sch in $schtask) { if ($sch."Run As User" -match "$($RunAsUser)" -and $sch.TaskName -match "$($TaskName)") { Write-Verbose "$Computername ($sch.TaskName).replace('\','') $sch.'Run As User'" $sch | Get-Member -MemberType Properties | ForEach -Begin {$hash=@{}} -Process { If ($WithSpace) { ($hash.($_.Name)) = $sch.($_.Name) } Else { ($hash.($($_.Name).replace(" ",""))) = $sch.($_.Name) } } -End { $script:Tasks += (New-Object -TypeName PSObject -Property $hash) } } } } } End { $Script:Tasks } } $ComputerName = "SE94ABH02" $ServiceAccounts = Get-Content "D:\Scripts\Test-Peter\Testing\ServiceAccounts.txt" $obj = New-Object –TypeName PSObject $obj | Add-Member -MemberType NoteProperty -Name ServerName -Value $ComputerName $obj | Add-Member -MemberType NoteProperty -Name TaskName -Value ([string]::Join(",",(@()))) $obj | Add-Member -MemberType NoteProperty -Name ScheduledTaskState -Value ([string]::Join(",",(@()))) $obj | Add-Member -MemberType NoteProperty -Name LogonMode -Value ([string]::Join(",",(@()))) $obj | Add-Member -MemberType NoteProperty -Name Author -Value ([string]::Join(",",(@()))) $obj | Add-Member -MemberType NoteProperty -Name RunAsUser -Value ([string]::Join(",",(@()))) $obj | Add-Member -MemberType NoteProperty -Name ServiceName -Value ([string]::Join(",",(@()))) $obj | Add-Member -MemberType NoteProperty -Name StartName -Value ([string]::Join(",",(@()))) $SCHTSk = Get-ScheduledTask $ComputerName | Where-Object {$_.RunAsUser -like "NLKVKF94*"} | Select TaskName,ScheduledTaskState,LogonMode,Author,RunAsUser If ($SCHTSK) { $TEMP = @() foreach ($TskItem in $SCHTSK) { If ($TskItem -match "NLKVKF94") { $TEMP += $TskItem $info = @{ 'TaskName'=$TEMP.TaskName; 'ScheduledTaskState'=$TEMP.ScheduledTaskState; 'LogonMode'=$TEMP.LogonMode; 'Author'=$TEMP.Author; 'RunAsUser'=$TEMP.RunAsUser } } } $tskobj = New-Object -TypeName PSObject -Property $info $obj.TaskName += $tskobj.TaskName $obj.ScheduledTaskState += $tskobj.ScheduledTaskState $obj.LogonMode += $tskobj.LogonMode $obj.Author += $tskobj.Author $obj.RunAsUser += $tskobj.RunAsUser } $WmiObjectResultaat = Get-WmiObject -Class win32_service -computer $ComputerName | select-object __SERVER,Name,StartName If ($WmiObjectResultaat) { $TEMP = @() foreach ($item in $WmiObjectResultaat) { if ($ServiceAccounts -contains $Item.StartName) { $TEMP += $Item $info = @{ 'Name'=$TEMP.Name; 'Startname'=$TEMP.Startname } } } $Srvobj = New-Object -TypeName PSObject -Property $info $obj.ServiceName += $Srvobj.Name $obj.StartName += $Srvobj.Startname } $obj | Export-Csv -Path "D:\Scripts\Test-Peter\Testing\lalala.csv" -NoTypeInformation
您创建了一个对象$obj
来保存所有任务详细信息,而不是单个任务的集合:
$obj = New-Object –TypeName PSObject
$obj | Add-Member -MemberType NoteProperty -Name ServerName -Value $ComputerName
$obj | Add-Member -MemberType NoteProperty -Name TaskName -Value ([string]::Join(",",(@())))
# ... and so on
同样,不是将单个任务添加到数组/集合中,而是将每个属性的值添加到$obj
的相同属性中:
$tskobj = New-Object -TypeName PSObject -Property $info
$obj.TaskName += $tskobj.TaskName
$obj.ScheduledTaskState += $tskobj.ScheduledTaskState
$obj.LogonMode += $tskobj.LogonMode
$obj.Author += $tskobj.Author
$obj.RunAsUser += $tskobj.RunAsUser
您只需将$obj
更改为空集合,并将任务分配给它:
$obj = @()
foreach($Task in (Get-ScheduledTask)){
$TaskProperties = @{
'TaskName'=$Task.TaskName;
'ScheduledTaskState'=$Task.ScheduledTaskState;
'LogonMode'=$Task.LogonMode;
'Author'=$Task.Author;
'RunAsUser'=$Task.RunAsUser
}
$obj += New-Object psobject -Property $TaskProperties
}
$obj | Export-Csv "output.csv"
我正在使用OpenNLP处理诸如“在洛杉矶工作的医生”和“住在好莱坞并在圣莫尼卡工作的女性”之类的查询。对于理解人类的英语来说,这些句子很明显,主题是“医生”和“女性”。然而,当我使用opennlp时,它将句子标记为 [女性生活][好莱坞] 这是另一个句子“住在圣莫尼卡、在马里布工作和踢足球的人”被处理为 为什么OpenNLP的POS标记器错误地标记了它们?这些句子有最简单的语法结构。如果最先进的
本文向大家介绍Windows Powershell导出管道结果,包括了Windows Powershell导出管道结果的使用技巧和注意事项,需要的朋友参考一下 可以将管道的结果转换成文本输出,默认是Out-Default。可以通过Get-Command -verb out查看Powershell都有哪些输出的命令。 吸收输出结果 有的命令无论执行成功或失败都会有输出,有时不需要这些输出时可以使用
我正在尝试执行X和(y或z)的查询,我需要得到代理是列表代理还是销售代理的所有已售出的属性。 只有bool才能得到9324个结果。当我添加bool should时,我得到了相同的结果集9324。ID为140699的代理应该只有大约100个结果。我也尝试过一个布尔过滤器,但没有成功。当用过滤器替换should时,结果就像另一个bool must一样,我只得到代理是列表代理和销售代理的结果
没有人回答相关的经历,我来做第一个嘿嘿 笔试:很简单的行测题(属于我从来没刷过题都能做的)当时以为要开摄像头所以计算题心算奈何垃圾选错了(一面的时候面试官还问我为啥丢分了哈哈哈哈哈好丢人) 一面:业务面,业务官非常有礼貌,问的问题都在运营常规问题内,感觉很聊得来,果然面完2个小时就收到通知通过了约了第二天的群面 二面(终面):群面,各个岗位的同学们,其中不乏优秀的大佬。主要三个环节:自我介绍,估算
扫描仪sc=新扫描仪(系统输入);字符串A=sc.nextLine();