results of find command into list - fish

Is there a compact way to store the output of a find command into a list ?
Something like:
find / -name "mov*.txt" | read var
But in a list in order to store all the paths found.

Related

Remove imported localized data

How do I remove localized data in PowerShell?
Say that I have imported localized strings for a script and then want to remove this to be able to import it again.
I haven't found any cmdlet for it and don't know if this is saved in $host and can be removed there.
The data is imported, with the following:
Import-LocalizedData -BindingVariable msgTable -FileName $SomePSDataFile -BaseDirectory $SomeNeighbouringFolder
If you mean you have imported the strings as variables, you should be able to clear them using the Clear-Variable command.
PowerShell stores its variables on a drive called Variable:. You can treat this like a normal drive and list the variables using a dir or a Get-ChildItem, for example, dir Variable:\ will return all your currently defined variables.
You can then clear the variables you want with the Clear-Variable command. You provide this command with the variable name without the $ sign in front of it.

Get the list of the default system variables

How can I get the list of all the default system variables (automatic variables) when you fresh open Powershell or when open a new tab?
ConfirmPreference
ConsoleFileName
DebugPreference
etc.
I am not talking about Get-Variable to receive all the variables, I just want the default ones.
For example an idea like :
[System.Management.Automation.PSVariable]::GetVariable
Just capture all the variables as the first action in your profile. Something like this:
Get-variable * > Autovars.txt
Get-variable * | Export-csv Autovars.csv
That way you'll get the variables that exist before the rest of your profile runs. The second command captures more of the properties of each variable So later on, you could retrieve the data as follows:
type Autovars.txt
Import-csv Autovars.csv | ft
If you mean something different by "more technical", then you'll just have to explain what you are looking for.

PowerShell Script - Report specific string from filename

I am currently trying to build a simple script that would report back a string from a filename
I have a directory full of files named as follows:
C:\[20141002134259308][302de103-6dc8-4e29-b303-5fdbd39c60c3][U0447744][10.208.15.40_54343][ABC_01].txt
C:\[20141002134239815][302de103-6dc8-4e29-b303-5fdbd39c60c3][U0011042][10.168.40.34_57350][ABC_01].txt
C:\[20141002134206386][302de103-6dc8-4e29-b303-5fdbd39c60c3][u1603381][10.132.171.132_54385][ABC_01].txt
C:\[2014100212260259][302de103-6dc8-4e29-b303-5fdbd39c60c3][U0010217][10.173.0.132_49921][ABC_01].txt
So, I'd like to extract from each filename the user ids that are identified starting with a letter U and seven digits, then create a new txt o csv and have all these Ids listed. That's it.
As Patrice pointed out, you really should try and do it yourself and come to us with the relevant piece of code you tried and the error that you are getting. That said, I'm bored, and this is really easy. I'd use a regex match against the name of the file, and then for each one that matched I'd output the captured string:
Get-ChildItem 'C:\Path\To\Files\*.txt' | Where{$_.Name -match "\[(U\d{7})\]"} | ForEach{$Matches[1]}
That will return:
U0447744
U0011042
u1603381
U0010217
If you want to output it to a file, just pipe that to Out-File, and specify the full path and name of the file you want to save that in.

Powershell implementation to pipe array into command

I'm using the following Powershell command to copy one user's Mercurial.ini file into another user's profile:
> copy $env:USERPROFILE\..\benm\Mercurial.ini $env:USERPROFILE\..\alex\Mercurial.ini
That works well. However, I'd like to write it in such as way so that I can do something like the following, specifying the users up front and piping them in to the copy command:
> "benm","alex" | copy "$env:UserProfile\..\$_[0]\Mercurial.ini" "$env:UserProfile\..\$_[1]\Mercurial.ini"
However, the above doesn't work. Is there an elegant way to achieve what I'm trying to do?
Something like this?
,("benm","alex") |
foreach {copy "$env:UserProfile\..\$($_[0])\Mercurial.ini" "$env:UserProfile\..\$($_[1])\Mercurial.ini"}
The ,("benm","alex") syntax makes the input from the pipeline a 2D array
PS C:\> $x = ,("benm","alex")
PS C:\> $x[0]
benm
alex
PS C:\> $x[0][0]
benm
PS C:\> $x[0][1]
alex
The Powershell pipeline will automatically "unroll" arrays and collections into a stream of objects, but only one level deep for nested arrays. By making it a 2D array, it "unrolls" the first level, and passes the nested array through the pipelile intact.

Powershell: How to capture output from the host

I am using powershell to automate some tasks related to checking out/merging in TFS. When I call
tf get * /recurse
I get a bunch of data scrolling by about the files that are getting checked out. The last line generated by this command (assuming its success) is one telling the checkin number. I would like to parse this out so it can be used later on in my script.
I know that I can do something like
$getOutput = tf get * /recurse
but then the output is suppressed entirely and I want the output of that command to be scrolled in realtime. I would basically like to grab everything that just got sent to the output buffer.
Try something like this:
tf get * /recurse | tee-Object -Variable getOutput
The tee-object in PowerShell 2.0 allows you to pipe results to two sources. If you leave the second source empty, the results go to the console.
ls | tee-object -filePath directoryListing.txt
This will write the directory listing to both the console and a text file.