Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


MSH Code

 
Logged in as: Guest
arrSession:exec spGetSession 2,5,29999
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Windows PowerShell >> MSH Code
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 MSH Code - 1/17/2006 8:14:47 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
I've decided to start posting snippets of MSH code here. I think I will try to stick with one-liners for the time being but I may do larer snippets if they are especailly useful.

dir | where {test-path $_ -type leaf} | foreach {([io.path]::GetFileNameWithoutExtension($_.name) + "_FOO" + $_.extension)}
This one will rename all of the files (and only files) in the directory to XXX_FOO.yyy where XXX is the original file name and yyy is the original file extension.



< Message edited by ebgreen -- 1/18/2006 4:33:38 AM >


_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm
 
 
Post #: 1
 
 RE: MSH Code - 1/18/2006 4:33:49 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
[System.IO.Directory]::GetDirectories("C:\Test") | foreach {write-host $_ remove-item $_}
This will remove all of the subdirectories of c:\test


_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ebgreen)
 
 
Post #: 2
 
 RE: MSH Code - 1/18/2006 5:34:25 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
get-process | where {$_.ProcessName -eq "EXCEL"} | Kill
    Kills all Excel processes

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: MSH Code - 1/24/2006 1:04:41 AM   
  crazymatt

 

Posts: 295
Score: 0
Joined: 3/4/2005
From:
Status: offline
Nice :)

Been starting to look into monad a bit as well, have started to convert my simpliest vbscript to msh scripts just to learn how things works.
Only done WMI questions so far, not sure in what way you can modify data ie. in the file structure or in Active Directory or in the registry.



_____________________________

-There is only 10 sorts of people, those who understand binary and those who dont.

(in reply to ebgreen)
 
 
Post #: 4
 
 RE: MSH Code - 1/24/2006 6:32:48 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Well, here is a registry script I found that includes changing registry values:

      

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to crazymatt)
 
 
Post #: 5
 
 RE: MSH Code - 1/24/2006 7:58:15 PM   
  crazymatt

 

Posts: 295
Score: 0
Joined: 3/4/2005
From:
Status: offline
Hmm intressting.

I dont quite understand the code though.

$key = ls HKLM:\SOFTWARE\Classes\Directory\shell\MSH\command -ea silentlycontinue
What does the "ls" part in the beginning mean? and why dont you need "" when there are spaces in the string?

if (! $key)  {
What does ! mean?
$new=New-item HKLM:\SOFTWARE\Classes\Directory\shell\MSHSHell\command
Does $new=New-item mean that it creates a regkey? How do you specify if the key should be a word/binary/dword and so on?
$set=Set-item HKLM:\SOFTWARE\Classes\Directory\shell\MSHShell\command "C:\Program Files\Microsoft Command Shell\msh.exe -Noexit -Nologo -
Command Set-Location '%L'"
Guess this means it sets the registrykey to a sertian value :)
}


Do you know anywhere where one can find info about these commands (New-item,Set-item and so on)? I cant find any on microsofts site.



_____________________________

-There is only 10 sorts of people, those who understand binary and those who dont.

(in reply to ebgreen)
 
 
Post #: 6
 
 RE: MSH Code - 1/24/2006 10:20:55 PM   
  crazymatt

 

Posts: 295
Score: 0
Joined: 3/4/2005
From:
Status: offline
http://www.informit.com/guides/content.asp?g=windowsserver&seqNum=210&rl=1

That might be a good place to find some info about and understand editing the registry in MSH.

_____________________________

-There is only 10 sorts of people, those who understand binary and those who dont.

(in reply to crazymatt)
 
 
Post #: 7
 
 RE: MSH Code - 1/25/2006 3:24:13 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
What does the "ls" part in the beginning mean?

ls is an alias for get-children. dir is an alias for the same command. So ls basically means list the contents of (ls is the name of the unix equivalent of the dos dir command)

why dont you need "" when there are spaces in the string?

Well there really aren't any spaces in the string that is being passed to the ls command.
HKLM:\SOFTWARE\Classes\Directory\shell\MSH\command is the path to list. -ea is the name of a parameter to pass to the ls comman. It is the ErrorAction parameter and the value that is passed into this parameter is silentlycontinue. So, it does not need "" for the same reason that Dir /s c:\Temp would not need "" in a DOS command.

What does ! mean?

! is the logical negation symbol or 'not'.




_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to crazymatt)
 
 
Post #: 8
 
 RE: MSH Code - 1/25/2006 7:54:08 PM   
  crazymatt

 

Posts: 295
Score: 0
Joined: 3/4/2005
From:
Status: offline
Doh, should have understood most of that :)

But know i know better.

Did some reading up yesterday on the msh basic, got most of my questions answered there.
So i guess i should have RTFM in the first place ;)

/CM

_____________________________

-There is only 10 sorts of people, those who understand binary and those who dont.

(in reply to ebgreen)
 
 
Post #: 9
 
 RE: MSH Code - 2/1/2006 6:06:42 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
it seems very javascript'ish to me, language wise

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to crazymatt)
 
 
Post #: 10
 
 RE: MSH Code - 2/1/2006 6:55:09 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
It pulls from lots of scripting languages. You can see concepts from Perl, Python, *nix shells, etc. in it.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to kirrilian)
 
 
Post #: 11
 
 RE: MSH Code - 2/2/2006 2:31:41 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
i've downloaded it and am gonna play with it a bit

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to ebgreen)
 
 
Post #: 12
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Windows PowerShell >> MSH Code Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts