Mark Minasi's Tech Forum
Register Calendar Latest Topics Chat
 
 
 


Reply
  Author   Comment  
jsclmedave

Administrator
Registered:
Posts: 445
Reply with quote  #1 
Per my Manager - "VS Code version 1.11.2 and Powershell 1.0.0 add-on. Just recently I also added a snippet file from Keith Hill based on this blog post -"

https://rkeithhill.wordpress.com/2015/09/12/powershell-snippets-for-visual-studio-code/



PSVersion 5.0.10586.117
VS Code version 1.11.2
Powershell 1.0.0 add-on  --  Per Link Above



In ISE you can highlight some code and run that snippet and the value will be saved to a variable which can be used later in another snippet in the code.

Line by line if you will...

I can run these snippets

Code:

$date = Get-Date -Format yyyy_MM_dd_HHmmss
$Server = 'ServerA' 
$Database = 'SomeDB'


And their values will be saved to be used in the next snippet.
Code:


PS C:\Users\TimBolton> $FilePath = "F:\MyBackup\$($Database)_db_$($date).bak"
PS C:\Users\TimBolton> $FilePath
F:\MyBackup\SomeDB_db_2017_05_17_144437.bak

Then I can use all the above in the last snippet
Code:

Backup-SqlDatabase -ServerInstance $Server -Database $Database -BackupFile $FilePath -Credential (Get-Credential "Some_User")




Example from my Manager -

 

Code:

[CmdletBinding(DefaultParameterSetName='no-creds')]

[OutputType()]

 

Param(

  [Parameter(ParameterSetName='creds')] [String]$credFile="C:\GitHub\Credentials\credFile.xml",

  [Parameter(ParameterSetName='creds')] [switch]$creds,

  [Parameter(ParameterSetName='no-creds')] [switch]$blank

)

Begin {

  import-module MySQL

 

  # Import credentials for Active Directory user account or Get-Credentials

  if( $creds ) {

    $spCreds = Import-Clixml $credFile

  } else {

    $spCreds = Get-Credential -Message "Enter credentials for sharepoint access"

  }

}

Process {

 

    # Do this stuff

 

    # Don't do this stuff

 

    # Do this stuff

 

}

End {

    # Don't do this stuff

}

 

 

"I want to be able to test this script by just running pieces of the script. 

What I normally do at first is run the lines from ‘cmdletbinding’ to the end of the parameter block to make sure my parameters are all declared and setup. 

Then, in the begin block I don’t want to test the $creds in the if statement, just want to run the line to read in my credentials from the credfile. 

The, I may only want to run one part of the script, test it out, and possibly make changes and try that part again. 

My issue with Visual Studio Code is that every time I run some segment of code in my script it ALWAYS starts up a new shell to run it in – so I have to run the whole thing each time. 

Some parts of my script may take 5-15 minutes to run, and I would like to run that once, and then use it over and over again as I fix the rest of the script that uses that data…"





__________________
Tim Bolton @jsclmedave
Email: [string](0..20|%{[char][int](32+('527377347976847978324785847679797514357977').substring(($_*2),2))}) -replace ' '  

New to the forum? Please Read this
0
cj_berlin

Avatar / Picture

Senior Member
Registered:
Posts: 227
Reply with quote  #2 
Hmmm. On my laptop, if I select some code and hit F8, it runs it in the same shell as before...
__________________
Evgenij Smirnov

My personal blog (German): http://www.it-pro-berlin.de/
My stuff on PSGallery: https://www.powershellgallery.com/profiles/it-pro-berlin.de/
0
jsclmedave

Administrator
Registered:
Posts: 445
Reply with quote  #3 
Quote:
Originally Posted by cj_berlin
Hmmm. On my laptop, if I select some code and hit F8, it runs it in the same shell as before...


That exactly what we found last night after discussing with Doug Finke  @dfinke   

He also suggested updating to the newest release 1.12.2 

I'm getting started with it now, so will probably have more questions coming.

Thanks CJ!

__________________
Tim Bolton @jsclmedave
Email: [string](0..20|%{[char][int](32+('527377347976847978324785847679797514357977').substring(($_*2),2))}) -replace ' '  

New to the forum? Please Read this
0
Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Easily create a Forum Website with Website Toolbox.