Mark Minasi's Tech Forum
Sign up Calendar Latest Topics
 
 
 


Reply
  Author   Comment  
timwiser

New Friend (or an Old Friend who Built a New Account)
Registered:
Posts: 20
Reply with quote  #1 
Hi guys,

I've got a really quick and (probably) easy Powershell question.  I'm trying to get to the bottom of why a third party's script doesn't work as expected and have found that some commands that it contains are prefixed with the ampersand '&' character.  Can anyone tell me why this might be?  For example:


# Server 2008
Write-Host "FSRM not found.. Installing (2008).."
&servermanagercmd -Install FS-FileServer FS-Resource-Manager


TIA,
Tim.
0
Infradeploy

Avatar / Picture

Senior Member
Registered:
Posts: 186
Reply with quote  #2 
The ampersand indicates that powershell needs to treat the rest as a command.

"c:\windows\system32\cmd.exe" displays a string
&"c:\windows\system32\cmd.exe" starts the command prompt



__________________
Have SpaceSuit, Will Travel

0
wkasdo

Avatar / Picture

Administrator
Registered:
Posts: 241
Reply with quote  #3 
The ampersand is the call operator, forcing Powershell to treat the arguments as an external command (after alias expansion). In this case, there seems no need for this. OTOH, I don't quite see why the & should be a problem here.  

Perhaps the reason is that you are executing this script on Windows Server 2012 or higher, where "servermanagercmd" does not exist anymore?

__________________
[MSFT]; Blog: https://blogs.technet.microsoft.com/389thoughts/
0
timwiser

New Friend (or an Old Friend who Built a New Account)
Registered:
Posts: 20
Reply with quote  #4 
The command was just a quick off-the-top-of-my-head dummy command, so don't worry about that [smile]
Thanks for the information guys!
0
donoli

Senior Member
Registered:
Posts: 598
Reply with quote  #5 
A double && will work as a pipe between 2 commands. 

cd \ && dir  is the same as
cd \ | dir

That goes for Unix & Linux as well.
0
Infradeploy

Avatar / Picture

Senior Member
Registered:
Posts: 186
Reply with quote  #6 
That does not work in Powershell Don.


__________________
Have SpaceSuit, Will Travel

0
donoli

Senior Member
Registered:
Posts: 598
Reply with quote  #7 
You are correct. I only tested it at a command prompt thinking that it would work in PS as well.
0
Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Easily create a Forum Website with Website Toolbox.