Posts tagged ‘Powershell’

Copy Directory Files and Create Random Names In PowerShell

I had a need to take an existing directory with a specific set of files and create new copies of those files, but with new random names. These new files would test a process which needed a lot of files to be loaded and the files had to be of a specific format and data such as a zip archive.

gci {TargetDirectory} -file  | Copy-Item -Destination { "$([System.IO.Path]::GetRandomFileName()).{Target Extension}" } -whatif

  • This operation copies the file to the current directory.
  • The GetRandomFileName will generate both random text and random lettered extensions.

I needed my files to be all of the same type so I this is the format I used:

gci C:\Test\Initial -file  | Copy-Item -Destination { "$([System.IO.Path]::GetRandomFileName()).zip" } -whatif


Verify All Multiple Downloaded Files’ Checksum In Powershell

I ran into this need while downloading the Oracle VirtualBox Image for its Developer Database which was 7ziped into 14 files. I wanted a way to view all the checksums using Windows 10 certutil program without having to type it into the command line. Here is the command used from the directory.:

     gci  | foreach { certutil -hashfile $_.fullname MD5 }

I had other files in the directory so I wanted to filter only on those files:

     gci -filter *.ova.7z.0** | foreach { certutil -hashfile $_.fullname MD5 }


PowerShell: Kill VPN Related Processes And Launch IE to Companies Website

While working for a company which used a browser based VPN which needed to have different pinned components in memory. That caused difficulties when having to mostly re-login due to their startup script. I created this PowerShell script to kill specific processes, if running, and launch IE to my companies’ web page.

Get-Process | where {      
                     -or $_.Name -like "Juniper*"`__abENT__lt;code__abENT__gt;-or $___abENT__#95;__abENT__#95;abENT__abENT__#95;__abENT__#95;#46;Name -like __abENT__#95;__abENT__#95;abENT__abENT__#95;__abENT__#95;quot;dsHostChecker*__abENT__#95;__abENT__#95;abENT__abENT__#95;__abENT__#95;quot;__abENT__lt;__abENT__#8260;code__abENT__gt;`
                     -or $_.Name -like "iisexpress"`__abENT__lt;code__abENT__gt;-or $___abENT__#95;__abENT__#95;abENT__abENT__#95;__abENT__#95;#46;Name -like __abENT__#95;__abENT__#95;abENT__abENT__#95;__abENT__#95;quot;Network*__abENT__#95;__abENT__#95;abENT__abENT__#95;__abENT__#95;quot;__abENT__lt;__abENT__#8260;code__abENT__gt;`
                 -or $_.Name -like "dsNcService*"`__abENT__lt;code__abENT__gt;}__abENT__lt;__abENT__#8260;code__abENT__gt;`
            | Stop-Process -Verbose -Force

$ie = New-Object -com internetexplorer.application; 
$ie.visible = $true; 

If you have any failures try running this script with admin privileges on the box.