Saliya's Blogs

Mostly technical stuff with some interesting moments of life

Showing posts with label windows. Show all posts
Showing posts with label windows. Show all posts

Notes on Windows PowerShell

  • Is bit slow and creepy ;) but better than command line
  • Running as administrator helps you overcome many of the access denied situations
  • PowerShell script files are simple text files with .ps1 extension
    • To run a script file,
      • Open a PowerShell instance (preferably as administrator) 
      • Type the path to .ps1 file and hit enter
    • If you get an error due to execution-policy is restricted, try
      set-executionpolicy remotesigned 
    • The above will ask for your permission. To avoid that and force use
       set-executionpolicy remotesigned -force
    • If you want this to be done across a Windows HPC cluster using clusrun command
      $nodes="node1,node2,..,noden"
      clusrun /nodes:$nodes powershell set-executionpolicy remotesigned -force
  • To start a new process through a script - http://technet.microsoft.com/en-us/library/hh849848.aspx
    start-process command "options and args"

    • If you want it to be on the same window and wait for it to complete use
      start-process command "options and args" -NoNewWindow –Wait
  • Invoke a command on a remote machine - http://technet.microsoft.com/en-us/library/hh849719.aspx
  • Invoke-Command -ComputerName $node -ScriptBlock {Start-Service MyService}

    Handling variables

    • Local variables
    • $x=10
      $path="C:\users\dd"

    • Command line parameters
    • $param0=$args[0]
      $param1=$args[1]

    • Environment (User/System) variables
    • $javaBin=$env:JAVA_HOME + "\bin"

      • A better alternative – number 2 indicates system variable. Use number 1 for user variable
      • $javaHome=[Environment]::GetEnvironmentVariable("JAVA_HOME",2)

      • Similarly to set a value – again number 2 is for system level.
      • [Environment]::SetEnvironmentVariable("Path","$tmp",2)

  • String operations (few)

    • Concatenation
    • $name="John"
      $x="hello " + $name + "! How are you ?"

    • Substring
    • $name.Substring(1) // "ohn"
      $name.Substring(1,2) // "oh"

    • StartsWith
    • $name.StartsWith("hello") // true

    • IndexOf
    • $name.IndexOf("ohn") // 1

    • Length
    • $name.Length // 4

    • Join paths
    • $javaHome=$env:JAVA_HOME // e.g. "C:\Program Files\Java\jdk1.7.0_10"
      $javaBinString=join-path -path $javaHome "bin" // e.g. "C:\Program Files\Java\jdk1.7.0_10\bin"

  • Loops – a good tutorial at http://www.powershellpro.com/powershell-tutorial-introduction/logic-using-loops/

    • For loop
    for($i=1;$i -le 10; $i++) {
      //body
    }
      • -le is <=
      • -lt is <
      • -gt is >
      • -eq is == in usual programming language notation

    • Foreach loop
    $jars=ls ($env:TWISTER_HOME + "\lib") *.jar
    foreach ($jar in $jars) {
     $jar=$jar.DirectoryName + "\" +  $jar.Name
     $cp=$jar+";"+$cp
    }
  • .NET runtime directory
  • $([System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory())
This is pretty much I found useful for my work. Feel free to suggest any.

Windows Live Writer: Life Made Easy for Blogging

I've been using Blogger for quite some time and over the years they have improved their Web based blog editor a lot, yet there was some uneasiness always when thinking about editing or adding a post. Anyway, after I got to know about Windows Live Writer I wanted to get it setup with Blogger but it wasn’t successful simply for some reason I couldn't understand “Username or password is incorrect”! I remembered only today that I was using two step verification with Google and that I have to create an application specific password to connect to Blogger. Wish it came to my mind sooner! Anyway, it’s now working fine and if you can read this online that means I made a post successfully with Live Writer.
Few places to note if you are having trouble connecting to Blogger with Live Writer as I did.
  1. Blog URL: Don’t forget to use https instead of http
  2. Username: Remember to add @gmail.com to your user id
  3. Password: As mentioned above, if you are using a two step verification with Google you need to generate application specific password to connect (see http://support.google.com/accounts/bin/answer.py?hl=en&answer=185833)

Copy Path to Clipboard : Another Life Saver

Want to copy the path of a file to clipboard in Windows without having to open properties window? Just try Copy Path to Clipboard v 1.00 (http://www.softpedia.com/get/System/OS-Enhancements/Copy-Path-To-Clipboard-JA.shtml). It's a pretty neat tool that saves quite a bit of human I/O time :D

Note. It works fine with Windows 7 as well.

Windows7 and Ubuntu 9.10

I just wiped out my Dell Insipiron E1505 notebook and installed Windows7 Professional and Ubuntu 9.10. I had enough of the Windows XP Media Center Edition. I thought of moving to Ubuntu 9.10 as well, just feel the fun.

Unlike in the previous experience with Windows, the Windows 7 performs really well. Regarding Ubuntu, it's better than 9.04 (I was happy with 9.04 as well). The only funny thing is that I had to find drivers and manually install my ATI Raedon X1300 VGA for Windows7. Earlier I used to do this for Ubuntu installations :)

For the moment, these two OSs seems to be a great combination if you are planning to get the best of both worlds.

How to Access Linux (Ext2) Partitions from Windows OS

I've been using Explore2fs for sometime to access my Linux partition from Windows OS. But it was very boring to copy files from Ext2 partition all the time when I wanted to access them. So I decided to search for a better option. So here it is, Ext2 installable file system. It's very cool. You can even write to Ext2 partition. Here is the good article where I found these stuff.