How to prevent Powershell Modules being installed into OneDrive - powershell

My $env:PSModulePath has ended up containing OneDrive:
C:\Users\jack\OneDrive\Documents\PowerShell\Modules;C:\Program Files\PowerShell\Modules;c:\program files\powershell\7\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
But I don't want all my Modules being synced to the cloud.
According to the docs:
The user-specific CurrentUser location on Windows is the PowerShell\Modules folder located in the Documents location in your user profile ... Microsoft OneDrive can also change the location of your Documents folder.
So that explains how the Modules ended up there. But how do I fix it?
I can modify $env:PSModulePath but this will only allow pwsh to find more modules I think. It won't change the default path for installing new modules for CurrentUser.
P.S. I face the same problem with the Update-Help when it saves help locally... OneDrive :-(

Perhaps the information in this thread on Reddit, could be of help.
Here's a snip from one of the answers, talking about excluding certain folders:
You can accomplish this by opening the OneDrive settings on your PC.
Go to OneDrive settings
Click the Account tab
Click "Choose Folders" and then cherry pick the folders you want to
exclude.

Related

File Explorer won't display PowerShell Modules directory otherwise visible in $env:psmodulepath

I'm in the process of learning how to create powershell modules through this youtube tutorial https://www.youtube.com/watch?v=yKstEJKdc4o&t=3661s - the video itself is not important.
I learned from learn.microsoft.com that powershell will have the following module directories by default:
$PSHome\Modules (%Windir%\System32\WindowsPowerShell\v1.0\Modules)
$Home\Documents\WindowsPowerShell\Modules (%UserProfile%\Documents\WindowsPowerShell\Modules)
$Env:ProgramFiles\WindowsPowerShell\Modules (%ProgramFiles%\WindowsPowerShell\Modules)
however there is no C:\users\john\Documents\WindowsPowerShell\Modules folder visible in File Explorer, while it's clearly visible in $env:psmodulepath when I run this from PowerShell. I'm able to navigate all the way to C:\Users\john\Documents\WindowsPowerShell but there is no Modules directory. I did enable hidden folders display and did also check Documents folders for OneDrive, Public, Administrator users. This is not a work/school computer, this is my own PC.
Can someone please help me understand why this Modules folder is visible in $env:psmodulepath but not in File Explorer?
Just because a location exists in $env:psmodulepath, doesn't mean it actually has to exists in the file system.
You can add any random location to $env:psmodulepath without it actually existing. PowerShell will just skip any locations that don't exist.
With a fresh Windows account, there isn't even a WindowsPowerShell directory under $env:userprofile\documents, to use a user profile or modules you have to create those directories.
It is fairly easy for a user to create a new directory, but a little bit more tricky to add a new entry to $env:psmodulepath. I guess that is why they already put it in there, even though it may never be used.

AppSrv01 doesnt have write permission

i know that the default profile name when i installed websphere was Appsrv01, I want to create my own AppSrv02 but the location of my IBM Websphere was in C: and i dont have any write permission, i dont have any admin rights also..
using COMMAND-LINE, I want to make my profile folder to be writable, so that my newly created AppSrv02 will be list down in the profile names in my RAD.
Please help me. Thanks
So that's your problem. In order to have a usable profile in WAS, your user must have write permissions. See this link from WAS ND infocenter, it applies to WAS standalone too.
http://www.ibm.com/support/knowledgecenter/SSAW57_8.5.5/com.ibm.websphere.installation.nd.doc/ae/tpro_manage_nonroot.html
If you cannot change the write permissions to this profile, you'll need to create your own. For this, you can either use WAS Profile Management Tool, WAS CLI or you can create your profile using the Configure profiles... link in the WAS server creation wizard you posted. I'd use the RAD way because RAD validates, within the IDE, the proper permissions that you need to create and use the profile within RAD.
First check whether you have admin rights or not if your using User/Guest profile, by creating any new folder in C drive where IBM WAS is installed.
If you have Admin rights, than right click on RAD run as administrator. It should work fine.
If Profile doesnt show up in drop down, Configure new profile and try checking that way.
If you dont have Admin rights better install RAD in any local drive other than C
Running Eclipse with Admin rights and removing the read-only tick for the AppServXX folder/WAS folder couldn't help me... cause I copied the WAS server from another PC :). So for those of you who want to move / migrate your development environment:
I did a search inside the copied WAS, Eclipse and the project's workspace folder for their old paths (with Total Commander, feed the results into a list) and dragged all the files (except the log ones) into my editor (NotePad++) and did a replace in all open documents for the new paths. It's a bit lucrative, but it took only 10 minutes for me and afterwards the WAS server in Eclipse showed the correct profile and it also did start up well.

Where can I put Powershell modules that will be accessed by multiple users?

I used the variable $Env:PSModulePath , It provided two paths.
> C:\Users\My User\Documents\WindowsPowerShell\Modules
> C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
Seems like My User will be accessible only for me. But my module will be used by multiple person and also when uninstalling my application [I am installing my module via msi], even if some other user uninstalls it should be removed.
Can I use "C:\Windows\system32\WindowsPowerShell\v1.0\Modules\" for my application related module? Or is there any other better place ?
Can i use "C:\Windows\system32\WindowsPowerShell\v1.0\Modules\" for my
application related module?
No. That place is not for you as noted in the section "Rules for Installing Modules" of the module installation guidelines.
You can decide yourself where you want to put the modules that are shared for multiple users.
Some options include:
Create new folder in Program Files, and add that path to PSModulePath.
Use a network share (though this means you need to change your execution policy to allow this), as #Rubanov said.
Use the All Users folder for example.
You can also put your psm1 files on a shared drive. Then import the module with
Import-Module -Name "\\SERVERNAME\Use-MyModule.psm1"
You can find more info about adding a path to PSModulePath here.

Is there a good reason why PowerShell uses the Documents folder as a default location for scripts?

Is there a good technical or other reason why the MS hard-coded the Documents folder as the default location for WindowsPowerShell? MS has been criticized for too much configuration over convention in the past (WCF?), but a case can be made for more configuration in PowerShell. I, and I presume most developers, like to keep their development work centralized in a separate folder or volume away from personal and system files.
For instance, if you install PoshGit, it will install itself in C:\Users\Your Name\WindowsPowerShell\Modules. I don't want it to install itself there but in my own development partition d:\Dev\PowerShellScripts. There's no environment variable that controls this location.
Is there a reason for this or I just don't get it?
Can you explain yourself a bit more.
According to my understanding PowerShell.exe interpreter base directory is the one defined by $env:HOMEDRIVE, $env:HOMEPATH, that can be change using the user profile.
As shown in the screen shots here under :
Edited :
Ok, the screenshot comes from the user property in Active Directory MMC, you've got a simplest one in your windows seven user properties. But this has nothing to do with your problem.
Your problem is around the module installation. The think that you have to know is that Modules can be installed quite everywhere (even on a shared directory with some tricks). By default the environnement variable $env:PSModulePath points to the paths where Get-Module -ListAvailable look for them. So you can add d:\Dev\PowerShellScripts\Modules in this path and then copy the subfolder of C:\Users\Your Name\WindowsPowerShell\Modules created by PoshGit inside your Modules directory and it should work. Modules as opposite to Snapins don't need to be registered.
Now the reason why PoshGit choose to put module in user profile, raser than let you choose the place is PoshGit installer problem.
For more explanations read about Modules and about_environment_variables.

MyDocuments from current User, buildin variable in Wix?

i need to install some file to C:\Documents and Settings\currentUser\SomeFolder.
I can't find some buildin function/variable for it.
Can someone help/tell me the <DirectoryRef Id="TARGETDIR"> structure or the solution for my problem?
Thanks.
First, are you sure that you want to do this? You will get a behavior where each user who logs in and starts up your program will attempt to do a repair and ask for the original install if not found. Also when you uninstall you won't be able to clean up all the users profiles.
Many people prefer the "first run" pattern where you have the installer install to C:\Documents and Settings\All Users\ and when you run your program it copies the files to the current user profile if needed ( usually only if you are overriding something that is set for all users ).
Otherwise, here is a list of available directories in Windows Installer / WiX
System Folder Properties:
http://msdn.microsoft.com/en-us/library/aa370905(v=VS.85).aspx#system_folder_properties
You'll want to choose from AppDataFolder, LocalAppDataFolder and CommonAppDataFolder.