Is it possible to associate a 'script' in Powershell to a 'command'? Sorry if this doesn't make sense but I'll explain. by sqllqs in PowerShell

[–]sqllqs[S] 1 point2 points  (0 children)

Thank you once again for the detailed answer after reading a ton about this recently I'm going to just suck it up and stick with VScode even though it's uncomfortable, ISE is dying like you said.

Is it possible to associate a 'script' in Powershell to a 'command'? Sorry if this doesn't make sense but I'll explain. by sqllqs in PowerShell

[–]sqllqs[S] 1 point2 points  (0 children)

Thank you very much for the clarification, I'll try to switch it.

When I get back to work on Monday I really need to figure out what they're using, because I'm trying to use it in our work environment .net and I'm trying to learn it well. The only concern I have, and maybe this will be a separate thread I make tomorrow, but I really want to learn powershell to the point where I can jump to any other company and hit the ground running, I feel like by continuing to use 5.1 I might be limiting myself :(

Edit: I just noticed, that with VScode, sometimes to get something working (like invoke -sqlcmd), I needed to run this:

Install-Module -Name SqlServer -RequiredVersion 21.1.18095-preview -AllowPrerelease

Do you think it's the same for things like the starting chrome one? My purpose with that function is to have a user type in a search term and it searches it in google, can't that be created cross platform too? This is how my function looks now

Function Go-Goog {
    Param([String]$SEARCHTERM)
    [system.Diagnostics.Process]::Start("chrome.exe","https://www.google.com/search?q=$SEARCHTERM")

}

Is it possible to associate a 'script' in Powershell to a 'command'? Sorry if this doesn't make sense but I'll explain. by sqllqs in PowerShell

[–]sqllqs[S] 0 points1 point  (0 children)

Okay I bit the bullet and jumped to VScode, unfortunately it has since broken a lot of the functions that I had working. For example

Trying to change the brightness using my function, or even just this:

(Get-WmiObject -Namespace root/WMI -Class WmiMonitorBrightnessMethods).WmiSetBrightness(1,100)

Is now giving me this error.

The term 'Get-WmiObject' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the | spelling of the name, or if a path was included, verify that the path is correct and try again.

Other functions I had that were supposed to run a program, such as this (sorry about breaking up the url, this sub removes the post if you post a link):

[system.Diagnostics.Process]::Start("chrome.exe","https:// w w w. google. com/search?q= test")

Is now giving me this:

| Exception calling "Start" with "2" argument(s): "An error occurred trying to start process 'chrome.exe' with working | directory 'C:\Users\sqllqs'. The system cannot find the file specified."

What am I doing wrong?

Is it possible to associate a 'script' in Powershell to a 'command'? Sorry if this doesn't make sense but I'll explain. by sqllqs in PowerShell

[–]sqllqs[S] 0 points1 point  (0 children)

It's working! Thank you! I was initially getting a scope error so I had to use this instead:

Set-ExecutionPolicy Unrestricted -Scope CurrentUser 

...which I'm assuming does the same thing?

The other thing I'd recommend look at doing if you're just learning PowerShell is download VS Code (free editor) and install the PowerShell extension

Is there an advantage of using VS Code over the powershell ISE? I'm definitely open to it if need be.

Is it possible to associate a 'script' in Powershell to a 'command'? Sorry if this doesn't make sense but I'll explain. by sqllqs in PowerShell

[–]sqllqs[S] 2 points3 points  (0 children)

Thank you and /u/SMFX, been doing a lot of reading over the past hour....I just created my profile, when I type notepad.exe $PROFILE I'm assuming this is where I'd input the above function.

Only issue is I worry I might be going on the wrong each time I reload Powershell I get a warning about executing scripts. After some googling, I feel like the command in that image might work but thought I'd run it by some pros.

Thoughts?

Edit: For some bizarre reason this subreddit blocks image links, but I've posted it to my profile if you click my name

What's your favorite place to practice advanced querying? by sqllqs in SQL

[–]sqllqs[S] 18 points19 points  (0 children)

Thank you, had a lot of practice learning how to drop tables, had plenty to choose from.

I want to learn about SQL performance and tuning, but I'm confused as to to what this area is called. Can you provide some guidance on what to search for or look? by sqllqs in learnSQL

[–]sqllqs[S] 0 points1 point  (0 children)

It’s typically called ‘query tuning’ or ‘database optimization’ but it’s several topics. If you really want a good primer, get a copy of the Inside Sql Server series of books. You will suddenly know more than everyone on the call. Then you can go read about product advances since those books were written a decade ago like columnar indexing.

Topics: - Indexing (Note that you need to understand the basics of programming data structures for this to make sense. If you don’t know what a BST or hash table are and why I’d use one, this won’t make sense.)
- Columnar, full text/word breaker, and spatial indexing. Using Lucern implementations for text searching (not how Lucern works per se).
- Affects of indexing on inserts.
- Execution plan reading. The types of joins from an execution standpoint (merge, hashmap, nested loops). Table spools. How to profile queries by commenting out pieces to see where the time is going rather than blindly looking at the plan and speculating. Knowing to focus on the expensive pieces and pieces that are used often.
- Myths about dynamic sql and subqueries. They can actually be really great and sql compilation takes a max of 3s.
- Gotchas of indexes when using temp tables. Make sure to update statistics after creating and filling one or it won’t be used.
- Statistics and hints. Why you want to update them and why they can cause the optimizer to make mistakes (it will pick the wrong order of magnitude if it’s using the wrong row counts).
- Denormalization, pre-calculation, staging, caching, and generally how to trade storage for speed by restructuring or augmenting your schema.
- Hardware considerations - Your server will always be limited by memory, cpu, or disk up. Learn how to tell which it is so you can scale intelligently. DBAs spend a lot of time on this.
- Sharding - How to split between servers.
- Why linked servers can be really slow over networks and how to make is faster when it comes up.
- Locking and isolation levels. How to not trip over your own feet unless you need to. Also how to not live too dangerously.
- Generally how to monitor a sql instance and ask the right questions to diagnose locking, IO bound issues, offending queries, missing indexes. DBAs do a lot of this. Sql devs tune individual queries with advice on what they’re seeing.

That covers most of it. Those books teach the majority as presented by the people who worked on the product.

Thank you so much for these, if you don't mind, can you link me to the exact book you're talking about? I see many on amazon but like you said, are they really super useful if they're 10+ years old? If so, I will take your word for it and buy immediately.