Powershell Command Line Extension

Here is the line

There are some examples regarding Powershell 'here-string', but I barely met the extension 'here-string'. so I posted this to help. If you want to add some literal with line breaks, single and double quotes do not need to be escaped, and there is no need for line breaks, for example "`r`n" . "here-strings" comes to the rescue in PowerShell. They should start with

@ "
and line breaks and should end with line breaks
"@

 For example: |Result: | @" | Hello world! 09/25/2014 11:39:56 | Hello world! 09/25/2014 11:39:56 '(this will appear as is)' | '(this will appear as is)' ! | ! "@ | 
+6
source share
2 answers

Here's how to enter CmdLet and a date variable to display the current date as follows:
For example, we want to achieve the following:

 Hello world! 09/25/2014 11:39:56 '(this will appear as is)' ! 

Here's how:

 @" Hello world! $(Get-Date) '(this will appear as is)' ! "@ 

Or with a variable:

 $myDate = Get-Date @" Hello world! ${myDate} '(this will appear as is)' ! "@ 
+7
source

This post is useful, and I landed here from looking for a variable extension inside the current PowerShell row in an SQL query.

The following snapshot will get a list of servers, and then a loop in the Foreach-Object , which allows you to replace the server name for each request!

Thanks to @Matt for the hash table .

 $servers = Get-Content c:\scripts\list.txt $servers | ForEach-Object{ $items = @{} $items.Server = $_ $query = @" WHERE svrName = $($items.Server) "@ } 
0
source

Source: https://habr.com/ru/post/975849/


All Articles