我是 Powershell 的新手,但我已经尽力了。我正在尝试创建一个脚本来将文件复制到阵列中所有 XP 计算机的所有用户桌面。该脚本基本上是说“如果机器可 ping 通,则复制文件,如果不是,则不复制。” 然后我想将此信息导出到 CSV 文件中以供进一步分析。
我已经设置了一切,但无论我做什么,它都只会导出它运行的最后一台电脑。它似乎运行在所有 PC 上(通过输出到 txt 文件进行测试),但它不会将所有计算机记录到 CSV。任何人都可以提供任何建议吗?
$ArrComputers = "PC1", "PC2", "PC3"
foreach ($Computer in $ArrComputers) {
$Reachable = Test-Connection -Cn $Computer -BufferSize 16 -Count 1 -ea 0 -quiet
$Output = @()
#Is the machine reachable?
if($Reachable)
{
#If Yes, copy file
Copy-Item -Path "\\servername\filelocation" -Destination "\\$Computer\c$\Documents and Settings\All Users\Desktop\filename"
$details = "Copied"
}
else
{
#If not, don't copy the file
$details = "Not Copied"
}
#Store the information from …Run Code Online (Sandbox Code Playgroud) 我在处理 csv 导出时遇到了一个小问题,其中包含像 ä,ö,ü(德语元音变音)这样的变异元音
我只是导出
Get-WinEvent -FilterHashtable @{Path=$_;ID=4627} -ErrorAction SilentlyContinue |export-csv -NoTypeInformation -Encoding Default -Force ("c:\temp\CSV_temp\"+ $_.basename + ".csv")
Run Code Online (Sandbox Code Playgroud)
这工作正常。我的 csv 文件中有 ä,ö,ü 正确。
之后我做了一些排序:
Get-ChildItem 'C:\temp\*.csv' |
ForEach-Object { Import-Csv $_.FullName } |
Sort-Object { [DateTime]::ParseExact($_.TimeCreated, $pattern, $culture) } |
Export-Csv 'C:\temp\merged.csv' -Encoding Default -NoTypeInformation -Force
Run Code Online (Sandbox Code Playgroud)
我尝试了所有编码、ASCII、BigEndianUnicode、UniCode,但都没有成功。
导出和排序时如何保留特殊字符 ä,ö,ü 等?
我是 vuetify 的新手,在将 v-data-table 导出为 excel、csv 格式时遇到问题。我该怎么做。任何建议或推荐。太感谢了。
我正在尝试从我的 Powershell 脚本启动此操作:
Import-Csv -Path $filecur -Delimiter ";" | Export-Csv -Path $filenext -Delimiter ";" -NoTypeInformation -Encoding Unicode -UseQuotes Never
Run Code Online (Sandbox Code Playgroud)
但执行 Powershell 脚本命令 promt 后显示下一条文本:
Export-Csv : A parameter cannot be found that matches parameter name 'UseQuotes'.
At C:\Users\vad\Desktop\QuatesDeleter.ps1:4 char:116
+ ... ilenext -Delimiter ";" -notypeinfo -Encoding Unicode -UseQuotes Never
+ ~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Export-Csv], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.ExportCsvCommand
Run Code Online (Sandbox Code Playgroud)
我怎么解决这个问题?我的计算机运行在 Windows 7、SP1、X64 下,PowerShell 版本是 5.1.14409.1005。
在微软文档中我找不到有关此问题的一些信息
我正在获取我需要的信息,尽管在导出信息时出现错误。
当我运行此代码时:
get-process | Export-csv -Path "C:\export.csv" -NoTypeInformation
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Export-csv : Access to the path 'C:\export.csv' is denied.
At line:1 char:14
+ get-process | Export-csv -Path "C:\export.csv" -NoTypeInformation
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Run Code Online (Sandbox Code Playgroud)
如何导出为 CSV?
我有很多时间试图理解为什么这个脚本没有按预期工作。这是一个简单的脚本,我试图在其中导入 CSV,选择我想要的几列,然后导出 CSV 并复制自身。(基本上我们已经归档了数据,由于内存大小限制,我只需要从另一个项目中提取几列数据)。这个脚本非常简单,它显然与它不起作用时造成的挫败感成反比关系......现在最终结果是我最终得到一个空的 csv 而不是一个只包含我选择的列的 csv与选择对象。
$RootPath = "D:\SomeFolder"
$csvFilePaths = Get-ChildItem $RootPath -Recurse -Include *.csv |
ForEach-Object{
Import-CSV $_ |
Select-Object Test_Name, Test_DataName, Device_Model, Device_FW, Data_Avg_ms, Data_StdDev |
Export-Csv $_.FullName -NoType -Force
}
Run Code Online (Sandbox Code Playgroud) 这是 PowerShell 的后续问题| EVTX | 将消息与数组进行比较(例如)
\n我稍微改变了策略,现在我正在收集所有已安装的服务,
\n$7045 = Get-WinEvent -FilterHashtable @{ Path="1system.evtx"; Id = 7045 } | select \n@{N=\xe2\x80\x99Timestamp\xe2\x80\x99; E={$_.TimeCreated.ToUniversalTime().ToString(\'yyyy-MM-ddTHH:mm:ssZ\')}},\nId, \n@{N=\xe2\x80\x99Machine Name\xe2\x80\x99; E={$_.MachineName}},\n@{N=\xe2\x80\x99Service Name\xe2\x80\x99; E={$_.Properties[0].Value}},@{N=\xe2\x80\x99Image Path\xe2\x80\x99;E=$_.Properties[1].Value}},\n@{N=\xe2\x80\x99RunAsUser\xe2\x80\x99; E={$_.Properties[4].Value}},@{N=\xe2\x80\x99Installed By\xe2\x80\x99; E={$_.UserId}}\nRun Code Online (Sandbox Code Playgroud)\n现在,我匹配每个对象的任何可疑特征,如果找到,我会添加一个值为“是”的“可疑”列。这是因为我想将决定权留给分析师,并且非常确定坏人可能会使用我们以前从未见过的东西。
\nforeach ($Evt in $7045)\n{\nif ($Evt.\'Image Path\' -match $sus)\n {\n\n $Evt | Add-Member -MemberType NoteProperty -Name \'Suspicious\' -Value \'Yes\'\n\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n现在,我无法让 PowerShell 显示所有列,除非我特别指定Select它们
$7045 | Format-Table\nRun Code Online (Sandbox Code Playgroud)\nCSV 导出也是如此。前两个不包括Suspicious列,但第三个包括,但那是因为我明确要求它这样做。
$7045 | select * | Export-Csv -Path test.csv -NoTypeInformation\n$7045 …Run Code Online (Sandbox Code Playgroud) 为什么我在这里得到一个空白文件?当我在export-csv之前运行它时,我得到的所有记录都显示在控制台中.

所以这是我正在使用的代码
$path = "C:\test"
Get-ChildItem -Path $path -Include *.edi, *.x12, *.filename, *.dat, *.log, *.mdn, *.req -Recurse -Force |
Where-Object {!$_.PSIsContainer -and ((get-date)-$_.LastWriteTime).days -gt 30 } |
Remove-Item -force -whatif | export-csv D:\output.csv #also I try out-file D:\output.txt
Run Code Online (Sandbox Code Playgroud) export-csv ×8
powershell ×6
csv ×2
export ×2
import-csv ×1
output ×1
v-data-table ×1
vue.js ×1
vuetify.js ×1
windows ×1
windows-7 ×1