Skip to main content

Posts

Showing posts from July, 2013

PowerShell to Create a random Music Playlist in VLC

This is a trick which got famous at the PowerShell Bangalore User Group (PSBUG) session. Little trick to play a single random song provided VLC (or any other player) is set as default player for the .mp3 files:     Posh (0002) >    Get-ChildItem -Path 'F:\songs\movies neew' -Include *.mp3 -Recurse | Get-Random -Count 1 | Invoke-Item  But this won't create a playlist for you if you simply increased the count for Get-Random..try this     Posh (0003) >    Get-ChildItem -Path 'F:\songs\movies neew' -Include *.mp3 -Recurse | Get-Random -Count 2 | Invoke-Item Let's try creating a playlist this time ( have to set VLC as  the default player for .mp3 files , thus creating filetype associations for .mp3 files)  You need get all the possible list values for mp3 extension.I read this excellent article by David Moravec at  PowerShellMagazine  to list all possible verb values for a particular extension....

using throw inside param() block

Recently I had to write  a very restrictive script which takes few arguments like a filename, computername etc. These parameters need to be compulsory otherwise the script should not run... Below is the first function I came up with(nothing fancy): function   Test-AdvancedFunction   {      [CmdletBinding()]         param (            [Parameter(Position   = 0, Mandatory   = $true   )]            [ValidateScript({Test-path $_})]            [   System.String ]               $FileName      )       $Name       ## Normal Script Code goes here      } In the a...

Drop to PowerShell using Remotely Anywhere

This is just basics but something I came across recently ,   remotely anywhere  is a remote administration tool which our Enterprise uses. Most of the time User face some issues with installation of applications , so Remotely anywhere helps in assisting them using the remote desktop using a web interface Remotely anywhere also listens on port 22 the name of the service is "RemotelyAnywhere SSH Server". Sojust connect to a remote machine using putty and then you are droppped to a  cmd shell  and then start PowerShell from there. The best part is it doesn't prompt for the User confirmation :) The pre-requisite is that Remotely Anywhere be installed on the remote machine and listening on port 22. So open up a putty console and connect on port 22. After that you need to authenticate yourself, I am logging into a machine in Enterprise (running AD) so I used my domain credentials to log in and you do need to After that you are dropped to a command pr...