Simon's SQL

SQL,DBA,tuning,Trouble Shooting,Performance

Archive for August, 2014

Introduce Desired State Configuration in Windows Server 2012

Posted by Simon Cho on 08/08/2014

http://channel9.msdn.com/Events/TechEd/NorthAmerica/2013/MDC-B302

Advertisements

Posted in Common | Tagged: , | Leave a Comment »

Basic powershell function call

Posted by Simon Cho on 08/08/2014

http://stackoverflow.com/tags/powershell/info

 

Common Gotchas

Executing EXEs via a path with spaces requires quoting the path and the use of the call operator – &

C:\PS> & 'C:\Program Files\Windows NT\Accessories\wordpad.exe'

Calling PowerShell functions does not require parenthesis or comma separated arguments. PowerShell functions should be called just like a cmdlet. The following examples demonstrates the problem caused by this issue e.g.:

C:\PS> function Greet($fname, $lname) {"My name is '$lname', '$fname' '$lname'"}
C:\PS> Greet('James','Bond') # Wrong way to invoke this function!!
My name is '', 'James Bond' ''

Note that both ‘James’ and ‘Bond’ are packaged up as a single argument (an array) that is passed to the first parameter. The correct invocation is:

C:\PS> Greet James Bond
My name is 'Bond', 'James' 'Bond'

Note that in PowerShell 2.0, the use of Set-StrictMode -version 2.0 will catch this type of problem.

Posted in Common | Tagged: , | Leave a Comment »