select-object

Powershell: Export a custom object to a CSV file - extract a single property value with Select-Object

非 Y 不嫁゛ 提交于 2019-11-26 11:40:04
问题 I wrote a script that constructs a custom object and exports it to a CSV file: $reg = Get-ItemProperty HKLM:\\SOFTWARE\\McAfee\\DLP\\Agent | Select-Object agentversion $date = Get-ItemProperty \'C:\\Program Files\\McAfee\' | Select-Object {$_.LastWriteTime} $date86 = Get-ItemProperty \'C:\\Program Files (x86)\\McAfee\'| Select-Object {$_.LastWriteTime} New-Object -TypeName pscustomobject -Property @{ \"Number1\"=$reg \"Number2\"=$date86 \"Number3\"=$date } | export-csv -Path C:\\****\\desktop

How do I write the value of a single property of a object?

笑着哭i 提交于 2019-11-26 05:30:03
This is how my current script looks like: $cpu = Get-WmiObject win32_processor | select LoadPercentage logwrite $cpu The output of the file is: @{LoadPercentage=4} I want it to be only the number so that I can make calculations. That is a pretty simple fix. Instead of selecting the LoadPercentage when running Get-WmiObject just select the property when calling your function. This will write only the number to your log file. $cpulogpath = "C:\Monitoring\$date.csv" function logwrite { param ([string]$logstring) add-content $cpulogpath -value $logstring } $cpu = Get-WmiObject win32_processor #don

Create objects with custom properties containing derived filesystem path information and export them to a CSV - calculated properties

 ̄綄美尐妖づ 提交于 2019-11-26 01:29:15
问题 Editor\'s note: The gist of this question is: * How do I add custom properties to objects output by Get-ChildItem that contain derived path information, namely the parent folder path (as Folder and name (as Foldername )? * How do I export the resulting objects to a CSV file? Currently have a script running that I took from StackOverflow and modified for my own use. The purpose of the script is to look at a directory, grab file names, then export them to a directory as a .csv file. I was able

How do I write the value of a single property of a object?

只谈情不闲聊 提交于 2019-11-26 00:44:37
问题 This is how my current script looks like: $cpu = Get-WmiObject win32_processor | select LoadPercentage logwrite $cpu #this fuction writes $cpu into a .txt file The output of the file is: @{LoadPercentage=4} I want it to be only the number so that I can make calculations. 回答1: That is a pretty simple fix. Instead of selecting the LoadPercentage when running Get-WmiObject just select the property when calling your function. This will write only the number to your log file. $cpulogpath = "C: