TomRiddle
-
Total Posts
:
620
- Scores: 12
-
Reward points
:
0
- Joined: 2/7/2008
- Location: Australia
-
Status: offline
|
Powershell Beginner
Sunday, May 23, 2010 11:27 PM
( permalink)
I am now on a mission to learn powershell and am working through the powershell2 for dummies book. I have got to a spot that has stumped me. I put this into the powershell_ise as a profile startup script function My-Custom-Function { Write-Host "Running my custom function!" } $psISE.CustomMenu.Submenus.Add("Run Custom Function",{My-Custom-Function},"Shift+Ctrl+f") And get the following error You cannot call a method on a null-valued expression. At line:5 char:31 + $psISE.CustomMenu.Submenus.Add <<<< ("Run Custom Function",{My-Custom-Function},"Shift+Ctrl+f") + CategoryInfo : InvalidOperation: (Add:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull I have googled trhe error and just can't work out what the expression is that is null? Any hints anyone? the code is copy and pasted straight from book. BTW i have inbstalled PowerShell2 onto XP SP3 and get this. $psVersionTable Name Value ---- ----- CLRVersion 2.0.50727.3603 BuildVersion 6.0.6002.18111 PSVersion 2.0 WSManStackVersion 2.0 PSCompatibleVersions {1.0, 2.0} SerializationVersion 1.1.0.1 PSRemotingProtocolVersion 2.1 But it has installed into this folder C:\WINDOWS\SYSTEM32\WindowsPowerShell\v1.0\
-join([int[]][char[]]'Ut|jwXmjqq%Wzqjx'|%{[char]($_-5)})
|
|
|
|
ebgreen
-
Total Posts
:
8227
- Scores: 98
-
Reward points
:
0
- Joined: 7/12/2005
-
Status: offline
|
Re:Powershell Beginner
Monday, May 24, 2010 1:54 AM
( permalink)
Well, the SubMenus collection is most likely what is null. I would try: $psISE.CustomMenu.Submenus.Items.Add("Run Custom Function",{My-Custom-Function},"Shift+Ctrl+f") But that is just a guess. As for the install directory, that is how it does it. Confusing I know.
|
|
|
|
TomRiddle
-
Total Posts
:
620
- Scores: 12
-
Reward points
:
0
- Joined: 2/7/2008
- Location: Australia
-
Status: offline
|
Re:Powershell Beginner
Tuesday, May 25, 2010 12:38 AM
( permalink)
-join([int[]][char[]]'Ut|jwXmjqq%Wzqjx'|%{[char]($_-5)})
|
|
|
|
ebgreen
-
Total Posts
:
8227
- Scores: 98
-
Reward points
:
0
- Joined: 7/12/2005
-
Status: offline
|
Re:Powershell Beginner
Tuesday, May 25, 2010 2:07 AM
( permalink)
Glad you figured it out. I never use the ISE.
|
|
|
|
TomRiddle
-
Total Posts
:
620
- Scores: 12
-
Reward points
:
0
- Joined: 2/7/2008
- Location: Australia
-
Status: offline
|
Re:Powershell Beginner
Tuesday, May 25, 2010 10:53 AM
( permalink)
if anything the ISE seems handy as an editor and for testing code snipits, i.e. you can copy and paste using CTL+C and CTL+V whereas powershell you have to type it or use edit from the console application bar icon menu
-join([int[]][char[]]'Ut|jwXmjqq%Wzqjx'|%{[char]($_-5)})
|
|
|
|
ebgreen
-
Total Posts
:
8227
- Scores: 98
-
Reward points
:
0
- Joined: 7/12/2005
-
Status: offline
|
Re:Powershell Beginner
Wednesday, May 26, 2010 1:01 AM
( permalink)
Right click the powershell icon and make sure Quick Edit is turned on. Then you can right click to copy or paste.
|
|
|
|
TomRiddle
-
Total Posts
:
620
- Scores: 12
-
Reward points
:
0
- Joined: 2/7/2008
- Location: Australia
-
Status: offline
|
Re:Powershell Beginner
Wednesday, May 26, 2010 10:18 PM
( permalink)
Thanks again ebgreen, that works a treat.
-join([int[]][char[]]'Ut|jwXmjqq%Wzqjx'|%{[char]($_-5)})
|
|
|
|