Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 534 Vote(s) - 3.45 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Useful PowerShell one liners

#11
I don't like complicated applications for counting lines of code, especially because I consider it to be a bogus metric in the first place. I end up using a PS one-liner instead:

PS C:\Path> (dir -include *.cs,*.xaml -recurse | select-string .).Count

I just include the extensions of the files I want to include in the line count and go for it from the project's root directory.
Reply

#12
I found it useful to show values of environment variables

dir env:

And you can copy an env value as well to the clipboard

$env:appdata | % { [windows.forms.clipboard]::SetText($input) }

(you need to have windows.forms loaded before the call: Add-Type –a system.windows.forms; and run PowerShell with -STA switch)
Reply

#13
Copy some to the desktop:

Copy-Item $home\*.txt ([Environment]::GetFolderPath("Desktop"))
Reply

#14
List all the files that I've updated today:

dir | ?{$_.LastWriteTime -ge [DateTime]::Today}

Use it so often that I've actually created a little function in my profile:

function Where-UpdatedSince{
Param([DateTime]$date = [DateTime]::Today,
[switch]$before=$False)
Process
{
if (($_.LastWriteTime -ge $date) -xor $before)
{
Write-Output $_
}
}
}; set-item -path alias:wus -value Where-UpdatedSince


So I can say:

dir | wus
dir | wus "1/1/2009"

To see stuff updated before today:

dir | wus -before
Reply

#15
Suppress Visual Studio 2012 ALL CAPS Menus - The very first thing I do after installing VS2012.

Set-ItemProperty -Path HKCU:\Software\Microsoft\VisualStudio\11.0\General -Name SuppressUppercaseConversion -Type DWord -Value 1


Thanks to [Richard Banks][1] who discovered the registry value.


[1]:

[To see links please register here]

Reply

#16
List all Windows Providers in alpha order:

get-winevent -listprovider microsoft-windows* | % {$_.Name} | sort

Actually you can use this with a wildcard for any specific group of Providers:

get-winevent -listprovider microsoft-windows-Securit* | % {$_.Name} | sort
Reply

#17
pipe the output of something to the clipboard

ls | clip
Reply

#18
Generate some pseudo random bytes in a file.

[Byte[]]$out=@(); 0..9 | %{$out += Get-Random -Minimum 0 -Maximum 255}; [System.IO.File]::WriteAllBytes("random",$out)

The Get-Random algorithm takes a seed from the system clock, so don't use this for serious cryptographic needs.
Reply

#19
cls
Get rid of all the intractable, -verbose red marks after each of my attempted commands, letting me resume with a nice posh clear looking screen.
Reply

#20
I hesitate to enumerate my list of PowerShell one-liners one by one as the list numbers just about 400 entries at present! :-) But here are a few of my favorites, to pique your interest:

- List all type accelerators (requires [PSCX][1]): `[accelerators]::get`
- Convert a string representation of XML to actual XML: `[xml]"<root><a>...</a></root>"`
- Dump an object (increase depth for more detail): `$PWD | ConvertTo-Json -Depth 2`
- Recall command from history by substring (looking up earlier 'cd' cmd): `#cd`
- Access C# enum value: `[System.Text.RegularExpressions.RegexOptions]::Singleline`
- Generate bar chart (requires Jeff Hicks' [cmdlet][2]): `ls . | select name,length | Out-ConsoleGraph -prop length -grid`

The whole collection is publicly available in a 4-part series published on Simple-Talk.com -- I hope that these will be useful to SO readers!

- Part 1: [Help, Syntax, Display and Files][3]
- Part 2: [Variables, Parameters, Properties, and Objects][4]
- Part 3: [Collections and Hash Tables][5]
- Part 4: [Files and Data Streams][6]

I wanted to call the series *"Do Anything in One Line of PowerShell"* but my editor wanted something more terse, so we went with *PowerShell One-Liners*. Though in the interests of full disclosure, only 98% or so are really one-liners in the true spirit of the term; I thought that was close enough with rounding... :-)


[1]:

[To see links please register here]

[2]:

[To see links please register here]

[3]:

[To see links please register here]

[4]:

[To see links please register here]

[5]:

[To see links please register here]

[6]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through