Call .exe with parameters?

by Cancerous at 2012-10-10 16:58:14

Trying to set up a script to call wsname.exe (http://mystuff.clarke.co.nz/MyStuff/wsname.asp) which renames the computer and reboots.

In batch, the script looks like
c:\wsname.exe /N:$SERIALNUM /REBOOT
and it is run at startup.

If I run this in powershell, it does nothing. I’ve read a bit about parameters in external commands using the & operator, but that doesn’t seem to work for me either.

Any help is appreciated.
by JeffH at 2012-10-10 18:57:14
Try:

Invoke-Expression -command "&c:\wsname.exe /N:$SERIALNUM /REBOOT"
by Cancerous at 2012-10-10 20:04:46
[quote=“JeffH”]Try:

Invoke-Expression -command “&c:\wsname.exe /N:$SERIALNUM /REBOOT”[/quote]Still nothing :</blockquote>by coderaven at 2012-10-11 03:48:37
To run the above code you may need to escape the $ with a `,see Get-Help about_Escape_Characters, or put the entire thing in ticks ‘&C:…’ the ampersand is telling PowerShell to just run the command.

I would also consider running WMI to rename the computer.
Something like:
invoke-wmimethod -Class Win32_ComputerSystem -Name Rename -ArgumentList (Get-WmiObject -Class Win32_BIOS).SerialNumber

Make sure you test the WMI method call of you want to use it.
by nohandle at 2012-10-11 06:38:51
Hello,
starting with Powershell v3 there will be --% operator avalilable, that stops parsing until end of line.

&c:\wsname.exe --% /N:$SERIALNUM /REBOOT
by willsteele at 2012-10-12 16:30:30
[quote=“nohandle”]Hello,
starting with Powershell v3 there will be --% operator avalilable, that stops parsing until end of line.

&c:\wsname.exe --% /N:$SERIALNUM /REBOOT[/quote]

I am curious about this. Do you have any links talking about this new operator? I am guessing it’s an operator.
by DonJ at 2012-10-12 16:41:38
A over pointed it out at TechEd, but I have not seen it in any docs yet. Probably hiding. :wink: