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!