Powershell!

Powershell!
What are you using it for, lets share some examples!

Attached: DPM-POSH-CC01.png (346x270, 6K)

Other urls found in this thread:

pastebin.com/raw/dA2RW2rw
pastebin.com/raw/xVZdUn23
pastebin.com/raw/BXKTxgar
pastebin.com/raw/CTXNqksC
pastebin.com/raw/BXKTxgar|%{
superuser.com/questions/236820/how-do-i-remove-the-same-part-of-a-file-name-for-many-files-in-windows-7/578076
docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/rename-item?view=powershell-5.1
lazywinadmin.com/2013/10/powershell-renaming-bunch-of-folders.html
news.softpedia.com/news/microsoft-replaces-command-prompt-with-powershell-in-latest-windows-10-build-510328.shtml
twitter.com/AnonBabble

Force hard match in AzureAD


$ADUser = "username"
$365User = "[email protected]"
$guid =(Get-ADUser $ADUser).Objectguid
$immutableID=[system.convert]::ToBase64String($guid.tobytearray())
Set-MsolUser -UserPrincipalName "$365User" -ImmutableId $immutableID

>Powershell
Ahahahahahahahhahahahah
ahaahahahwhahahwhahwhwhahahahahahajahahahahahahahagahwqhwhahwhahahwhahahahahau

Can't post company code.

Uploading SSRS reports and downloading data using APi's

okay that was retarded. posting again

Force rename filenames to random. Save as a bat.
@ECHO OFF
powershell -nologo -noninteractive -command "Rename-Item '%~1' -NewName $([io.path]::GetRandomFileName().split('.')[0] + '%~x1') -Force"


Other script I have written is a semi-smart webm converter that auto-adjusts output resolution according to bitrate constraints. Unfortunately it's written really shoddily, doesn't have some useful features, audio can't be disabled. It was more of a try to spend less time manually adjusting resolution. Relies on ffmpeg and mediainfo.
pastebin.com/raw/dA2RW2rw

Another script I use can embed data into an image file and extract it afterwards. Such an image file can be safely posted to Jow Forums and doesn't get detected in any way by the embed scanner. There's also a UI component for embed preview and extraction. Can only be run on Winblowz, but doesn't rely on anything else and is tested against Powershell v2. It's definitely more competently written than the webm crap.
pastebin.com/raw/xVZdUn23

Simple UI to allow multiple users to interact with a big ass list of one-time-use credentials in parallel. Basically done at this point with all the processing and data integrity shit, but no fkn clue how to get user input via a drop list...

PS is awesome for automation (built a step into an old process that creates unique users with strong passwords on a remote ftp with a shit local only cli, took 1 day with testing), but wrapping it up for user interaction is weird

can anyone help me?

pastebin.com/raw/BXKTxgar
I want to remove the duplicated lines because these are identical lines to the same path

So the pastebin above should become like this
pastebin.com/raw/CTXNqksC

And is it possible to cut out certain parts from each line?

pic related, the "duplicated" lines that I want to remove

Attached: 1517564291483.png (1008x972, 143K)

Good Lord I use it for for everything.

Main uses are

A bot in slack (poshbot)
Some internal monitoring of our environment for things like diskspace (and cleanup) services that stopped or crashed, log parsing, API testing, and queue monitoring (rmq). I use it for so many other applications as well.

iwr pastebin.com/raw/BXKTxgar|%{ $_.content -split "`r`n" }|group { [io.path]::GetDirectoryName([io.path]::GetDirectoryName($_)) }|% name


windows likes to insert CR+LF characters so you have to separate them together or else [io.path] goes crazy and refuses to operate.

oh this is awesome, thank you

instead of checking it up on a pastebin, how would I make it search for a text file on my drive?

IF you want first pages shown then simply get the first item of each group
wget pastebin.com/raw/BXKTxgar|%{ $_.content -split "`r`n" }|group { [io.path]::GetDirectoryName([io.path]::GetDirectoryName($_)) }|%{ $_.group[0] }

Is it named specifically? Navigate to root folder and use this:
gci filename.txt -recurse -file

or if the filename contains wildcards or brackets
gci -filter filename.txt -recurse -file

>wget
I think it has to be mentioned wget is an alias for Invoke-Webrequest aka iwr as stupid as that is. Luckily Powershell Core removes these stupid mistakes and neither curl nor wget appear anymore.

Attached: 021.png (450x142, 2K)

I use it for everything I would use vanilla cmd for, because that's apparently what Microsoft wants me to do.

Everything

Use it to basically automate 60% of my sysadmin job. Everything from user account creation/deletion to manipulating apis

Currently moving on to something else due to getting bored due to automating so much lol

gci anthology.txt -recurse -file|%{ $_.content -split "`r`n" }|group { [io.path]::GetDirectoryName([io.path]::GetDirectoryName($_)) }|%{ $_.group[0] }

like this? and the text file should be in the same folder as the script too right?

What I mean you should navigate to any root directory where somewhere deep within it may be the file and run the command from there. For example run the command from the disk where you think the file is.
Secondly that command won't work, because the $_.content simply picks up the text that was fetched from the pastebin. In your case, you need to read the text file which you do with Get-Content. As it automatically separates lines you don't have to split them either.

If you do not want to navigate to the directory you have to input the Path parameter. For example:
gci D:\ -Filter filename.txt -recurse -file

The full command would then be:
gci D:\ -Filter filename.txt -recurse -file|gc|group { [io.path]::GetDirectoryName([io.path]::GetDirectoryName($_)) }|%{ $_.group[0] }

This will read all files that match the filename provided and group their contents based on parent of parent paths.

>gci D:\ -Filter filename.txt -recurse -file
Path is the default parameter so "D:\" gets mapped to it.
If you want to be explicit then use:
gci -Path D:\ -Filter filename.txt -recurse -file

Cheers m8. How do I save the output to a new text file

put Out-File at the end of it with a pipe separation and a filename.

Mainly to open cmd, I should probably set things to default to cmd

gci E:\ -Filter anthology.txt -recurse -file|gc|group { [io.path]::GetDirectoryName([io.path]::GetDirectoryName($_)) }|%{ $_.group[0] } Out-File | anthology-new.txt

this didn't work, did I miss a command

The pipe goes before Out-File, then the filename. I thought you already grasped some of how piping works.

that solved it, thanks m8

mainly for renaming files/folders in bulk

Show us your scripts.

simple crap that i've found online like the following:

superuser.com/questions/236820/how-do-i-remove-the-same-part-of-a-file-name-for-many-files-in-windows-7/578076

docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/rename-item?view=powershell-5.1

lazywinadmin.com/2013/10/powershell-renaming-bunch-of-folders.html

>powershell
>using it
kek

Attached: 4380.HSG-5-28-12-1.jpg (800x624, 77K)

;D
function subliminal_all (){
$files = Get-ChildItem *

foreach ($file in $files){
subliminal download -l en $file
}
}

ITT: Linux fags not understanding, timesink os isn't used in all servers

Out of curiosity, does anyone have a script to extract a zip file where it is currently at, delete the zip file and move on to the next file? Something similar to this webm

Attached: 1520969603681.webm (872x742, 836K)

simple enough to write yourself bruh

I'm a brainlet, I wouldn't mind giving somebody $10 for a script to do it.

Linux boi here

Do people not use Powershell when programmign on wangblows?

What do you use instead, just CMD?

Is it actually a zip file or just randomly compressed?

regular zip, as far as i know

This. I use it as-much as I possibly can. PS is vastly underrated.

Some people cling to the past but by now most windows developers use powershell.

PS is the equivalent of knowing Bash well. CMD is the equivalent of pasting sudo shit from your browser into shell.

Okay then use something like this:
gci -Path C:\ -Filter *.zip -Recurse -File|%{ trap{return}; Expand-Archive -LiteralPath $_.FullName -DestinationPath ( Join-Path $_.DirectoryName $_.BaseName ); Remove-Item -LiteralPath $_.FullName }

Put the root directory from where to recurse under -Path. Though to be mega-careful you may want to wrap it into a function and have WhatIf flags.
function Extract-ZippedManga {
param (
[parameter( MANDATORY = $true )]
[string]$Path,
[switch]$RemoveAfterwards,
[switch]$WhatIf
)
gci -Path $Path -Filter *.zip -Recurse -File|%{
trap { return }
Expand-Archive -LiteralPath $_.FullName -DestinationPath ( Join-Path $_.DirectoryName $_.BaseName ) -WhatIf:$WhatIf
if ( $RemoveAfterwards ) {
Remove-Item -LiteralPath $_.FullName -WhatIf:$WhatIf
}
}
}

Here RemoveAfterwards flag tells to remove the source file, 'trap' makes sure to not continue executing on error, so if expand-archive fails, removing doesn't happen even if you specify it. WhatIf flag tells to not do any action but to rather print what would be done. It's useful to test critical scenarios like deleting stuff.

Is it supposed to be like this, also will it remove the zip after it has successfully extracted it before moving on to the next zip? I have almost no space left on this storage device

gci -Path G:\ -Filter *.zip -Recurse -File|%{ trap{return}; Expand-Archive -LiteralPath $_.FullName -DestinationPath ( Join-Path $_.DirectoryName $_.BaseName ); Remove-Item -LiteralPath $_.FullName }

function Extract-ZippedManga {
param (
[parameter( MANDATORY = $true )]
[string]$Path,
[switch]$RemoveAfterwards,
[switch]$WhatIf
)
gci -Path $Path -Filter *.zip -Recurse -File|%{
trap { return }
Expand-Archive -LiteralPath $_.FullName -DestinationPath ( Join-Path $_.DirectoryName $_.BaseName ) -WhatIf:$WhatIf
if ( $RemoveAfterwards ) {
Remove-Item -LiteralPath $_.FullName -WhatIf:$WhatIf
}
}
}

No, those are two separate commands.
Ok just run this:
function Extract-ZippedManga {
param (
[parameter( MANDATORY = $true )]
[string]$Path,
[switch]$RemoveAfterwards,
[switch]$WhatIf
)
gci -Path $Path -Filter *.zip -Recurse -File|%{
trap { return }
Expand-Archive -LiteralPath $_.FullName -DestinationPath ( Join-Path $_.DirectoryName $_.BaseName ) -WhatIf:$WhatIf
if ( $RemoveAfterwards ) {
Remove-Item -LiteralPath $_.FullName -WhatIf:$WhatIf
}
}
}

Extract-ZippedManga -Path C:\ -RemoveAfterwards -WhatIf

This will load the function and then run it as a test scenario, you can then verify what it does, what gets extracted, what gets removed.
If you're satisfied then run this, this will replicate the events, extracting and removing as it goes through the directory tree:
Extract-ZippedManga -Path C:\ -RemoveAfterwards

Change the -Path C:\ to the directory you need, say -Path D:\manga in both cases

bump

Literally nothing. Cmder + CYGWIN + Linux Subsystem for Windows >>>>>>>> Powershell

You boys ever used Ping before?

I use it to start bash

I like powershell except to run executables you have to type ./blahblah.exe or some shit. Why can't I just do it like normal.

God damn, you again?!?

At this point it would have been quicker for you to extract all your zip files and then delete the zip files yourself, you lazy motherfucker.

$filelist = dir *.zip;
foreach $file in $filelist {
\pathtoyourfavoritecliunzipprogram\unzip -whateverparameters $file
delete $file
}


Now, go away, douche.

If the binary directory is part of your PATH variable, then those additional "current directory" characters are not necessary. Otherwise use tab completion so powershell inserts those characters automatically. Also install PsReadline if you're not on Windows 10, makes command line navigation, copying and pasting considerably easier. CTRL+SPACE shows a list of parameters or files currently available or what automcomplete can result in based on current input.

what does this do and how does it differ from command prompt? i clicked the wrong button accidentally once and i dont understand

news.softpedia.com/news/microsoft-replaces-command-prompt-with-powershell-in-latest-windows-10-build-510328.shtml

It's a differnet command line shell to regular command prompt, has different keywords, commands, syntax, it works differently as well. It's a more modern approach to shell interaction compared to command prompt, though all old commands such as "ping" or "ipconfig" still work. It's built on top of .NET so the scripting possibilities are way more powerful than what was possible before on a default Windows install. A lot of system management nowadays only happens with Powershell, so command prompt is slowly going away.

why is he a douche

he spams this post

your code isn't even reall, and you called him a douche though

I didn't post code ITT I only answered your question, nigger

...

go back to Jow Forums and calm your autism instead of shitting up threads on Jow Forums, you dumb cunt

Stop-Computer -ComputerName "localhost"
So I can install Linux and purge microsoft cancer from my drive.

>he spams this post
No, I called him a douche because he doesn't know the rules of this board. To paraphrase a line in the sticky, "We are not your fucking tech support team".

As I mentioned in one of your previous threads, you need to download a cli unzip program. The only line of my code that doesn't work is "\pathtoyourfavoritecliunzipprogram\unzip -whateverparameters $file". I wrote it like that to emphasize that you need to find and use your own cli unzip program.

Everything else in my code snippet works.

I think this is the wrong thread for you friend

>asks OT
>blames other people for shitting up thread
k, brown breed pajeet

>paraphrase with quotation marks
>paraphrase
>quotation marks on 4chinz

To uninstall Microsoft UWP bloat

Despite being a *NIXfag, I like using it at work. Makes pulling data from the AD easier.