Permissions Windows Folder - powershell

I can't seem to figure out how to get full control of my Windows folder.
I want to delete a map in my Windows folder and that map contains other maps and files.
I know how to do it manually but I want to do it in PowerShell but have no idea.
Any ideas?

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.

File selected in WindowsExplorer with Preview Pane locks the file so powershell cannot output to that file

I have a scheduled script that outputs bunch of HTML files with static names to a remote location. I noticed, that if I have one of those files selected in Windows Explorer so that its contents are shown in Preview Pane, then Powershell cannot overwrite that file and skips updating it.
This only happens if output files are in remote location. Works just fine if files are local.
How do I force PowerShell to overwrite remote files in this situation? Lots of users work with those reports and if one of them leaves Windows Explorer window with one of those files highlighted overnight when the script runs, the file is not going to be updated.
Move HTML files to webserver. You will solve your problem entirely. IIS Setup on windows server is Next, Next, Next. You can leave link to a new file location (https://....) in old place, so users can easily navigate to a new place. Possibly this link can be automated (not sure because of modern security standards)
Try [System.IO.File]::Delete($path) just before writing this file. This removes file entry from filesystem, but leaves file open for those who have it open for now. This makes your script to write to a new file with the same name. Old file exists without name (deleted) but leaves open until everyone close it. Check it actually deleted with resresh!
Try [System.IO.File]::Move($path, $someTrashFullName) just before writing this file. $someTrashFullName probably must be on same drive. Same as Delete, but renames file. Some self-updating software use this strategy. File is renamed, but it's still kept open under new name.
Try replace file with shortcut to some file. You can generate files with different names and change shortcut programmatically
HTML files that change location using js ? They read nearby JSON (generated by export script) and lookup there for a new filename. So user opens static unchanged A.html, JS inside lookups at A.json for new name and redirects user to A-2020-08-11.html. I'm not sure browsers allow reading JSON files from JS for files that opened from network drive.
Only way left is to stop network share or\and close open files server-side.
Maybe some fun with to disable preview in this folder \ completely?
Try with -Force. But to me, it seems to be more a permission issue.
Remove-Item -Path '\\server\share\file' -Force

With Unity version 2020 and onwards, how to build for Windows to a single file?

I'm struggling to find any method that works with current Unity.
This for a conventional Windows build (not a Windows Universal via VS).
So, there's the separate data, dll, etc files of a build: how to create a civilian-usable "single exe" for Windows, with current Unity??
As said afaik this was actually always the case.
See e.g. Windows standalone Player build binaries to see a list of resulting output of a build. It exists back until version 2017.2.
So the short answer is:
It is how it is. You will always get multiple files and the data folder as output.
What you can do however is using a pack tool which simply packs all your folder content into one single exe file.
One example is Appacker
=>
BUT unfortunately there is one known issue: Windows Defender recognizes it and every exe created with it as malware. The reason for that is actually mentioned by the author in the link
Spoiler: A self-extracting .exe file? Windows Defender hates that trick!
So either with this tool or any similar one there is no real way around that except you need to trust the tool and your users need to trust you ^^
(The icon is also only used for the process window, not for the exe file itself ^^)
The long and correct way would probably be to create an actual installer for your final app which is then allowed to extract all the files to a certain location.
So in the end the user anyway will again have an exe and according data and dll files e.g. in the Programs folder but get a registered shortcut to the Start Menu which is just how any other application on Windows usually works like.
Just to add to the answer.
In 2020 if it's a game you should just use Steam. Making auto-update way easier for your users.
https://partner.steamgames.com/doc/gettingstarted

Change Directory to Folder Containing PowerShell Script - Regardless of Where That Folder Is Located

I have a script that I've created to prep our customer's servers for a software install. Part of this requires the script to be run as administrator, so just instructing people to click "Run With Powershell" doesn't get the job done. The script is in a folder with a number of .ini files that the script needs to copy to different server locations. If I just right-click the Powershell script and select "Run With Powershell," it is able to find the files and copy them without issue. Unfortunately, if I open the script in ISE, it opens with a default directory of C:\users\user, and I can't seem to copy those .ini files without first running a change directory command to get us to the folder that the script and the .ini files are in. But I'd like our installation techs to be able to run this without worrying about the exact location they initially drop these folders. I'd also like them to not have to worry about changing the directory manually in PowerShell. Some of our customers have multiple drives, and it might make sense to put this stuff on something other than the C drive, so it's hard to tell where this folder might end up. But I'm not sure of a command that will get me to the directory of the *.ps1 file, without knowing where that file is beforehand... Anyone have a suggestion?
You can use $PSScriptRoot that will have the location of the directory where the script is located.
This is referenced in the following post:
How can I get the file system location of a PowerShell script?

Portable Eclipse

I'm trying to port my entire 'workspace' to a USB key (including the Eclipse executable) so that I can carry my work anywhere with me and work off the key directly.
My directory hierarchy is similar to this:
/workspace/eclipse - Where my current eclipse binary is stored
/workspace/codebase - Where I keep the root of all my eclipse projects
/workspace/resources - Where I keep all project files (images, docs, libs, etc.)
It all works perfectly fine on one system. But when I change over to another system, the USB key gets mounted on another drive. For example, on my laptop, I get 'E:\', on my PC, I get 'K:\' and at work I get 'F:\', etc, etc.
This means that because Eclipse (for 'some' reason) seems to only use full path names (including driver letters) in every single one of its configuration files (such as .classpath), nothing ever works when I want to work on another system.
I put a 'libs' directory in the base of every project and populate it with its dependent JAR files. Why doesn't it use relative names instead, so that I could specify something like "../../libs/log4j.jar"?
Anyone know how to fix this problem? Does anyone know of a workaround for this?
Update: 2010.11.09
I've recently discovered Dropbox, which allows you to sync your files online and across your computers automatically with extreme ease. It includes 2GB of free space and you can upgrade to much more if you want (for a yearly fee).
I installed it on my two laptops, my two PC's, my Linux server and my Android phone and then I created a 'workspace' directory within the 'My Dropbox' folder. From the 'workspace' directory, I then installed Eclipse and created/configured all my projects as usual. I can literally work from any computer and everything always stays perfectly in sync. This is way better than any USB key functionality and its hassle!
Have you tried using Eclipse Portable?
The only thing to keep in mind is that when switching the workspace, you need to remember to give it a relative path (like ../../Data/workspace).
You could use the dos command subst to get a consistent drive letter by creating a new virtual drive letter (say x:) that maps to your Eclipse folder on your usb drive, and then make all the config paths reference the drive x:
You could make a little batch file on the usb drive that you click on to create the drive x:
C:\>help subst
Associates a path with a drive letter.
SUBST [drive1: [drive2:]path]
SUBST drive1: /D
drive1: Specifies a virtual drive to which you want to assign a path.
[drive2:]path Specifies a physical drive and path you want to assign to
a virtual drive.
/D Deletes a substituted (virtual) drive.
Type SUBST with no parameters to display a list of current virtual drives.
You could also remap letter for your USB stick in Windows Disk Management (subitem in Computer management) to be smth like 'U:'.
Once done, it will be re-assigned to same stick every time you plug it. Not very universal, since your user need rights to access this setting first time, but it could help in some different scenarios.
You can always use Ant to build your programs, with Ant you can have relative paths... Plus you can also use Ivy to track dependencies in Ant, I do that in every project that I have.
Another alternative is to manually edit your .classpath files to contain relative paths.
It is a bit of a hassle, though, as you'll have to manually update the files whenever Eclipse changes them.