I am trying to make a simple PowerShell script that copies some registry folders and substrings in these folders to it's own folder on the C:\ drive.
How can I do this? I've tried export command, and Copy-Item -Path command but without luck.
For example copy the files (registry files) in the keys
HKLM\software\Norton
HKLM\software\Wow6432Node\Norton
to the folder C:\backupNorton.
You can do
Get-ChildItem HKLM:\SOFTWARE\Norton
And then export or save the object you get from that - either as plain text or using something like Export-Clixml.
Related
I have folder with lot of files like .txt .exe .jpeg .png etc. I need to copy only media files such as .jpg .png .mp4 etc to another folder. And if file with same name exists then add post fix to file name like img.png then img1.png.
I tried this using powershell shell script.
Copy-Item -Path .\b\*.jpeg -Destination .\a -Recurse
but it overrides the existing file. How can I do this using powershell.
Is it possible to get all files names from a directory in variables ?
Consider this environment :
Dir/File.json
Dir/File7.json
Dir/File58.exe
Is it possible so that i can get File, and File7 (only the file with .json extension) in one or two variables that i'd use later in my code ?
I test dir > test.txt but : It show everything including folder or files with an other extension, and i don't know if i can then use this .txt file to get back the names individualy.
Using PowerShell
$FileNames = Get-ChildItem -Path 'C:\Dir' -Name *.json
This will return all json files in the folder C:\Dir
I'm working upon a PowerShell script, where I have to extract the content out of a .zip archive which extension is removed, so, archive's name is let's say not test.zip but just test, and it is compressed as a .zip archive.
I'm trying to use for this purpose the PowerShell cmdlet Expand-Archive like shown below :
Expand-Archive -LiteralPath "Path to the archive" -DestinationPath "Extraction Path"
But, it doesn't seem to work, is there a possibility of extracting this archive's content with powershell, or it would be better to use a work around like 7zip command line tools, or something similar?
The Expand-Archive cmdlet is designed to explicitly work with a path that has a .zip extension. You can work around this by either creating a copy of your archive with a proper extension using Copy-Item or renaming the archive to have an extension with Rename-Item (using Move-Item may be more desirable if the archive with extension already exists and you want to overwrite it; Rename-Item is not capable of overwriting).
I'm currently trying to streamline the installation process of a few products that require a powershell script to be run each, I've encountered some trouble when trying to write a script to search a directory for these files.
Example: in the directory 'Install' i have four subfolders named 'product1-4' in each of these folders there is a file 'Script.ps1'
The first issue is that the install scripts are all named the same 'script.ps1' which complicated my first idea to pull all the files from the sub-folders into a centralised location and run them all sequentially.
Feel like i'm making this more complicated than it needs to be, any advice?
Get-ChildItem $installFolder -Include *.ps1 -Recurse
That will list the .ps1 files, you could also do the following to then address the files as a single variable.
$ps1Files = Get-ChildItem $installFolder -Include *.ps1 -Recurse
I want to move users home folder to share drive who has left the company but before that I want to ZIP it using powershell script. Could you please suggest me or write me quick powershell script which ZIPs the folder and move to share drive creating a same folder name with zip file also same name in destination folder. For instance if source folder is C:\test and destination is \\share\test\
Thanks in Advance,
There's a few ways to zip a folder:
Creating a zipped/compressed folder in Windows using Powershell or the command line
Creating a new folder is simple:
New-Item c:\folder -type directory
https://technet.microsoft.com/en-us/library/ee176914.aspx
And moving a file is also very simple too:
Move-Item c:\source\file.zip c:\destination
https://technet.microsoft.com/en-us/library/ee176914.aspx