summaryrefslogtreecommitdiffhomepage
path: root/powershell.html.markdown
diff options
context:
space:
mode:
authorAndrew Ryan Davis <AndrewDavis1191@gmail.com>2020-08-20 00:10:08 -0700
committerAndrew Ryan Davis <AndrewDavis1191@gmail.com>2020-08-20 12:30:32 -0700
commitfc9b23f3571f8b3f67c83ad7814ec3c579ece22e (patch)
treed838a5c6a77b8b1b5c85bf2988776a3666b875b1 /powershell.html.markdown
parentc0a8574825e24a924a693c8b74941a65f25683ec (diff)
Adding in escape chars and more info on call operator with exe's
escape chars like newlines, tabs, negating affects call operator and dot-sourcing for paths to exes with spaces in them and arguments passed.
Diffstat (limited to 'powershell.html.markdown')
-rw-r--r--powershell.html.markdown28
1 files changed, 27 insertions, 1 deletions
diff --git a/powershell.html.markdown b/powershell.html.markdown
index da4dcd5c..027320d5 100644
--- a/powershell.html.markdown
+++ b/powershell.html.markdown
@@ -677,6 +677,19 @@ $PSVersionTable
```Powershell
# Calling external commands, executables, and functions with the call operator.
+# Executables with arguments passed create issues
+C:\Program Files\dotnet\dotnet.exe
+The term 'C:\Program' is not recognized as a name of a cmdlet, function, script file, or executable program.
+Check the spelling of the name, or if a path was included, verify that the path is correct and try again
+
+"C:\Program Files\dotnet\dotnet.exe"
+C:\Program Files\dotnet\dotnet.exe # returns the string rather than execute it
+
+&"C:\Program Files\dotnet\dotnet.exe --help" # fail
+&"C:\Program Files\dotnet\dotnet.exe" --help # success
+# Alternatively, you can use dot-sourcing here
+."C:\Program Files\dotnet\dotnet.exe" --help # success
+
# the call operator (&) is similar to Invoke-Expression, but IEX runs in current scope.
# Standard usage of '&' would be to invoke a scriptblock inside of your script.
# Notice the variables are scoped
@@ -693,7 +706,20 @@ $i # => 5
$x=1
&{$x=2};$x # => 1
-. {$x=2};$x # => 2
+.{$x=2};$x # => 2
+
+
+# Escape Characters in Powershell
+# Many languages use the '\', but Windows uses this character for
+# file paths. Powershell thus uses '`' to escape characters
+# Take caution when working with files, as '`' is a
+# valid character in NTFS filenames.
+"Showing`nEscape Chars" # => new line between Showing and Escape
+"Making`tTables`tWith`tTabs" # +> Format things with tabs
+
+# Negate pound sign to prevent comment
+# Note that the function of '#' is removed, but '#" is still present
+`#Get-Process # => Fail: not a recognized cmdlet
# Remoting into computers is easy