PowerShell code to export to CSV -
i have 2 powershell scrips below , different things need them similar things when export csv.
get-childitem c:\users\user\desktop\here -recurse | {!$_.psiscontainer} | select-object * | export-csv -notypeinformation -path c:\users\user\desktop\output\output.csv | % {$_.replace('"','')}
gets me detailed info directory , when open csv in excel in separate columns - perfect.
plink.exe -ssh root@user -pw password -m c:\users\user\desktop\scrips\linuxscriptcommand.txt > c:\users\user\desktop\output\linux.csv
runs df -h
on cloud , returns space left on drives, want, when open csv in excel makes me go through text import wizard other doesn't.
i can't figure out way automate text wizard part, can provide me insight? if have way optimize please let me know too.
change df -h
command output comma separated values:
df -h | awk '{print $1","$2","$3","$4","$5","$6" "$7}'
the issue having saving single cell unix line endings not displaying correctly in windows. can fixed replacing them:
plink.exe -ssh root@user -pw password -m c:\users\user\desktop\scrips\linuxscriptcommand.txt | foreach { if (([regex] "`r`n$").ismatch($_) -eq $false) { $_ -replace "`n", "`r`n" } else { $_ } } | set-content "c:\users\user\desktop\output\linux.csv"
if you're using newer version of powershell can use -file
param return files. makes other command considerably shorter when remove other unnecessary parts:
get-childitem c:\users\user\desktop\here -recurse -file | export-csv c:\users\user\desktop\output\output.csv -notypeinformation
Comments
Post a Comment