Windows 7 Forums Search
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows 7. The Windows 7 forum also covers news and updates and has an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7 - Powershell - problem calling functions



 
02-04-2010   #1


Windows 7 x64 - Professional
 
 

Powershell - problem calling functions

Dear members,

I am an absolute powershell newb and I'm trying to write a script. For the most part this works splendid, but I cannot get it to call functions in ways I think I'm supposed to be calling them.

this link (Windows PowerShell Tip: The String?s the Thing) suggests the following call if you want to get a substring from a string.
Call
$volume_number = $temp.Substring(7,2)
Result
Method invocation failed because [Microsoft.PowerShell.Commands.MatchInfo] doesn't contain a method named 'Substring'.
At E:\Merlijn\Documents\Workspace\testscript.ps1:6 char:37
+$volume_number = $temp.Substring <<<< (7,2)
+ CategoryInfo : InvalidOperation: (Substring:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound

Since this didn't work, I started trying things at random using conventions I found all over the internet. I know that's not the most sensible, but if the sensible thing doesn't work and all the googling you do doesn't give you the right answer, all you're left with are insensible options.

Call

$volume_number = [string]::substring($temp, 7,2)
Result
Method invocation failed because [System.String] doesn't contain a method named 'substring'.
At E:\Merlijn\Documents\Workspace\testscript.ps1:6 char:41
+$volume_number = [string]::substring <<<< ($temp, 7,2)
+ CategoryInfo : InvalidOperation: (substring:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound


Call
$volume_number = ($temp | substring 7 2)
Result
The term 'substring' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the s
pelling of the name, or if a path was included, verify that the path is correct and try again.
At E:\Merlijn\Documents\Workspace\testscript.ps1:6 char:40
+$volume_number = ($temp | substring <<<< 7 2)
+ CategoryInfo : ObjectNotFound: (substring:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Now I hope that someone among you can help me making the right calls. Substring is just an example, this happens for many commandlets that I have tried, so it's getting difficult to script anything. I think the commandlets may not be registered right or in the wrong location, but I have no clue how to check that. Thanks in advance for any help offered!

My System SpecsSystem Spec
Reply

Powershell - problem calling functions problems?



Thread Tools



Similar Threads for: Powershell - problem calling functions
Thread Forum
Facebook video calling Browsers & Mail
Solved Facebook Video Calling Chillout Room
Calling home General Discussion
Calling all experts!! Very unusual problem here. General Discussion
So, what's calling the wake up timer? General Discussion


All times are GMT -5. The time now is 03:38 AM.



Windows 7 Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows 7" and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30