Thanks to #DavidBrabant for helping me with my first question, it helped me immensely.
https://stackoverflow.com/a/25546642/3985581
Was hoping somebody could look at the code at the above link and advise how I could go about writing some information about the copy process to a csv file?
Thank you.
Chris
Thanks for the help thus far guys, #DavidBrabant and #chthonicdaemon
It would have been helpful to get some ideas on how to dynamiclly capture the values as they are written, at this stage, I haven't worked this out. So I thought about it and just thought I would gather all the details AFTER the copy process.
I just used the conventional method of reading the copied directory structure using:
Get-ChildItem -Path $destination -Recurse |
foreach{ $var = $_.Parameter | Select-Object #{n="column heading";e={$var} | Export-Csv $destination\Results.csv -NoTypeInformation
This gives me an output as follows..
FilePath ____________________________Name_______Size_______Type
C:\folder script\test\aabd1612\QuotaSize.nsf____QuotaSize_____663552_____.nsf
Related
I am using Powershell 4 and trying to parse an archived event log into a csv file that includes all of the data and has headers associated with them. The closest I have been able to come is by using the following command:
Get-WinEvent -Path .\Security.evtx |Select-Object TimeCreated, ProviderName, Id, Message, Level, Keyword, UserID, Data, Subject, SubjectUserSid, SubjectUserName, SubjectLogonId, ComputerName | Export-Csv .\Logging.csv
This gives me all the header information for all of the fields in the csv file but the only fields that contain data are TimeCreated, ProviderName, ID, Level, & Message. I am trying to get the missing data into columns also but not succeeding. So what am I doing wrong here?
This was copied from an edit to the question itself, and should be credited to the original question author
Ok, I finally figured it out...At least for what I need to accomplish. Hopefully this will help someone.
Get-WinEvent -Path .\Security.evtx | select TimeCreated, ProviderName, Id, #{n='Message';e={$_.Message -replace '\s+', " "}} | Export-Csv .\Logging.csv
This code allows you to export the archived eventlog into csv with headers and puts the whole message body into one cell, which allows import into a database with ease when you have no tools to work with.
Trying to determine if the $pwd is in Powershell's directory stack.
I"m getting the stack like this:
$stack = Get-Location -Stack
and trying to search like this:
$found = $stack | Select-String "$pwd"
I have tried single quote, double quote, tried '$pwd.ProviderPath'.
Is there a better filter than Select-String for this? Am I using Select-String incorrectly? Thanks for any insights...
Try using a Simple Match.
get-location -stack |select-string -SimpleMatch "$pwd"
I need to make changes to to the following Powershell script, but am having a dickens of a time getting the resulting files to write to a different path...let's call it $destPath.
Consider:
Get-ChildItem $sourcePath | % { [system.io.file]::Move($_.fullname, ($_.FullName -replace '\[|\]|-|,|\(|\)', '') ) }
Based on my understanding of move syntax, $_.fullname is my original file, and $_.FullName -replace... is the NEW filename. Hoever, when I try to use $destPath.FullName -replace I get an error that an empty filename is not legal. Obviously, Powershell is not recognizing that as a valid pathname for the move command.
What am I missing?
Since you did not mention $destPath in context - maybe you did not define the variable $destPath at all? It is quite unlikely but just trying to narrow things down.
Another way to make this work:
Rename child-items first at original location. Then move them.
get-childitem *.txt | rename-item -newname {$_.name -replace 'o','O'}
get-childitem *.txt | % {move-item -path $_.fullname -destination .\Test-files}
But I prefer your one liner:)
Is it possible to get the path to the php.ini file with a php script and save this path to a variable? I know I can call phpinfo() to find out the path, but it prints a lot of info and I only need the path to php.ini file and no output at all. Thank you in advance.
Sure, there are two functions related to what you would like to do. The first one is exactly what you're looking for, the second one shows the bigger picture that there can be more than one ini file:
php_ini_loaded_fileDocs - Retrieve a path to the loaded php.ini file.
php_ini_scanned_filesDocs - Return a list of .ini files parsed from the additional ini dir.
Next to that, mind the gap with .user.ini files, they don't show up in php_ini_scanned_files nor phpinfo.
You could exec("php -i | grep php.ini"), and grab that output.
Or you could use outputbuffering (ob_start()), run phpinfo(), get the contents of the outputbuffer (ob_get_contents()) and search trough that (preg_match) to find the php.ini file...
This works on the command line, might also work for the CGI:
ob_start(); phpinfo();
if ( preg_match( '#>(.+)/php.ini#', ob_get_clean(), $matches ) ) {
echo 'php.ini location: ' . trim( $matches[1] ) . '/php.ini';
}
I have a command that formats it's output in the form of CSV. I have a list of machine this command will run against using a foreach loop. in the below example $serverlist is automatically generated with an AD Query.
foreach ($server in $serverlist) {
$outputlist = mycommand
}
what I would like to do is somehow end up with objects from the resulting CSV so I can then only select certain objects for a report. However the only way I can see to do this is using import-csv, which only seems to want to work with files and not variable: ie.
Import-Csv output.csv | ft "HostName","TaskName" |
Where-object {$_.TaskName -eq 'Blah'}
I'd like to be able to have import-csv $outputlist instead. doing this causes import-csv to have a hissyfit :)
Can anyone point me in the right direction on how to achieve this?
Cheers
The command you want is called ConvertFrom-CSV. The syntax is shown below.
NAME
ConvertFrom-CSV
SYNOPSIS
Converts object properties in comma-separated value (CSV) format into CSV
versions of the original objects.
SYNTAX
ConvertFrom-CSV [[-Delimiter] <char>] [-InputObject] <PSObject[]> [-Header <string[]>] [<CommonParameters>]
ConvertFrom-CSV -UseCulture [-InputObject] <PSObject[]> [-Header <string[]>] [<CommonParameters>]