Windows PowerShell default open location - windows

I have been googling and trying different options but I didn't really find anything useful or that worked.
My question is how to set default open location for windows PowerShell, I want it to always open c:/programming/ folder when I start it from like start menu, instead what it opens now.
I'm using windows 10.
Thnx for help

the usual way to tell PoSh where to start up at is to add a Set-Location line to one of your powershell profile files. i added ...
Set-Location D:\Data\Scripts
... to my CurrentUserCurrentHost file. you can learn more about profiles with ...
Get-Help about_Profiles
you can find your version of the profile i used thus ...
$profile |
Select-Object -Property *
please note that none of these files exist by default. you will likely need to make one. if you do be sure it is a plain text file, not a .doc file! [grin]

Related

how to make a Powershell script avaiable from anywhere

I have a Powershell script I would like to make "public", meaning I want to be able to execute the script from any folder as you can do from the command prompt.
Is this possible?
You can also add an alias in your local powershell profile
Alias Example in profile
Set-Alias hello C:\scriptlocation\script.ps1
Now anytime you type hello, the script.ps1 will run.
More info on the various profiles that the alias can be saved to.
https://devblogs.microsoft.com/scripting/understanding-the-six-powershell-profiles/
You can explore the use of your powershell profile to achieve this. See: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles.
If the script is just a function or some variables, you can copy and paste the content into your profile.
Alternatively, if the script represents a standalone unit of code you want to keep separate, you could import it into your main profile as such:
get-content -path C:\blahblahblah\scriptName.ps1 -raw | invoke-expression
Finally, if you are writing an "advanced" powershell function, or are trying to do things officially, you could investigate the use of powershell modules as a way to export your function. See: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_modules
#Lee_Dailey's answer of adding the script to your path is also viable. If you want to add a lot of scripts, one way to do that is to add a folder like C:/PowershellScripts/, to your path, save your scripts there, and then you'll be able to invoke your .PS1 file from anywhere.
Name the script something meaningful ie: awesome.bat Save it in a dir and add the dir to windows env. Command awesome will be globally available.

How do you find a corresponding registry value to a setting in gpedit.msc?

My question is, how do I find the location of the registry value that corresponds to a gpedit.msc setting. I know that there are some references on technet, but they are outdated.
For instance, if I were to try to modify the setting, configure automatic updates, through regedit, how would I be able to find the location of its value in the windows registry? Is there some kind of area in gpedit that will tell me its location?
I had the same problem and the solution I found was using PowerShell with the
PolicyFileEditor module. As far as PowerShell goes this is quite simple so don't worry about that. Taking it step by step this is what you have to do:
Start PowerShell in administrator mode
#Look up the module paths (you will probably get 3)
PS> $env:PSModulePath
#make sure you have the NuGet package
PS> Install-PackageProvider -Name NuGet -Force
#Enter the path with your username in it at the <path>
#(This only works if you have
PS> Save-Module -Name PolicyFileEditor -Path <path>
#Install the module
PS> Install-Module -Name PolicyFileEditor
#Get the machine policy registry value's
Get-PolicyFileEntry -Path "$env:windir\system32\GroupPolicy\Machine\registry.pol" -all
#Get the user policy registery valeu's
Get-PolicyFileEntry -Path "$env:windir\system32\GroupPolicy\User\registry.pol" -all
If this all works correctly than you should get something like this (Depend on gpedit settings):
The PolicyFileEditor is quite handy as it can also export the gpedit registry settings and then import them, look here for more information.
For more information on PowerShell itself I recommend the Microsoft virtual academe course.
There is however one problem with the PolicyFileEditor module and that is that while you can edit the registry these changes do not show up in the gpedit and you have to restart the computer for the changes to take effect (try testing with windows defender or something similar)
EDIT: after testing some more the LPG settings started showing up (After restart), i don't know what is up but you will have to test it for yourself.
Good luck.
There are different locations in registry for different settings in gpedit (Group Policies).
For the setting, "Configure Automatic updates", following registry gets edited.
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Group Policy Objects\<GUID key>
I realize now, but there's a really simple way to figure this out. Just go to the directory %windir%\System32\GroupPolicy\Machine and then look for the file Registry.pol. It will give you the registry keys that correspond to group policy items.
Instead of having to restart the computer, you can try the following command:
echo N | gpupdate.exe /target:Computer /force

get only shorcut files from desktop in powershell

my power shell version is
5.0
In windows 10, to get all files from desktop, i use
Get-ChildItem C:\Desktop\
This returns only the files but i want to get only the short-cut icons name in that directory.
I also use this
Get-ChildItem C:\Desktop\ -force| where {$_.extension -eq ".lnk"}
but it also does not work.
Is that possible or is there any better way or is there any administrator or security issue?
Thanks in advance.
The earlier you filter your results the better and quicker your query will be, so I'd use:
Get-ChildItem C:\Desktop\ -Filter *.lnk
Your path should also probably be c:\users\'username'\desktop or "$($env:userprofile)\desktop"

Invoke Windows copy from PowerShell

I am busy with creating a PowerShell script where a folder needs to be copied to another folder as a part of the script.
For this I would like to use the standard Windows copy interface and leverage from the prompts and selections like “There is already a file with the same name in this location.”, “Do you want to merge this folder”, “Do this for all”, etc. instead of programming this all myself.
I investigated a view directions:
Using the IFileOperation::CopyItem method as e.g. HowTo: Display progress dialog using IFileOperation but I could find any hint of how to embed this in PowerShell
Using Verbs() Copy/Paste but although the example Invoke-FileSystemVerb -Path "C:\TestDir -Verb Cut; Invoke-FileSystemVerb -Path "\\server\share" -Verb Paste” suggests otherwise, I can paste files that are manually copied/cut but could not copy/cut files with using the CmdLet or simply using the Verb.DoIt() method (I suspect this for a security reason).
Simulate a drag-drop?
But could not find any working solution.
Any suggestion how to do this from PowerShell?
I use this to extract from ZIP files which seems to come up with all the prompts and progress bar:
$shell = New-Object -Com Shell.Application
$folder = $shell.NameSpace(“$path\Folder”)
$shell.NameSpace($otherpath).CopyHere($folder)

How do I check, at user logon, if a Firefox plugin exists?

I want to check if the users on our domain have a certain Firefox plugin installed. Maybe we can have a script that checks if the folders created by the plugin exist. And if not raise some sort of alert to the user.
An example of the plugin folder is below. There are randomly generated parts that will probably make it more complicated.
C:\Documents and Settings\username\Application Data\Mozilla\Firefox\Profiles{random}.{profile name (“default”)}\ {random-id}#jetpack\resources{same random-id}-at-jetpack-pluginname-data\
I have NO clue about Windows scripting, this is the first time I'm even thinking about it
This question is a bit of a "please do it for me" because of 1.
Is this possible? Definitely. I'm not sure the best method, but I'll attack this from the PowerShell angle.
It might be difficult to use PowerShell because you need to verify that everyone has PowerShell installed. If you can verify that, it's a pretty simple request.
Use
$firefoxfiles = Get-ChildItem -Path ($env:appdata + "\Mozilla\Firefox\Profiles") -Recurse
This will give you a list of all the files in that directory... treat all of the code in this answer as an example, you'll certainly have to change it.
if (!($firefoxfiles | Where-Object {$_.Name -eq "PluginFileName"} ) {
...code for pop up...}
There's a ton of samples out there for an error dialog from PowerShell.
Good luck!
Here is some PowerShell that will search the appdata directory for all folders containing that special plugin name. On error, you should alert the user and force them to interact with the alert (the Read-Host). When they continue, you can launch Firefox directly to the installer page.
if(-not(Get-ChildItem "$env:appdata\Mozilla\Firefox" -recurse -include "*#jetpack" | ?{ $_.PSIsContainer }))
{
Read-Host "The Firefox 'jetpack' plugin was not found. You will be redirected to the plugin page now. Please install the 'jetpack' plugin. (press any key to continue)"
& 'path\to\firefox.exe' 'http:\\path.to.plugin.com'
}
The output on the console should look something like
The Firefox 'jetpack' plugin was not found. You will be redirected to the plugin page now. Please install the 'jetpack' plugin. (press any key to continue):

Resources