powershell-3.0

Creating Registry Keys with Powershell

随声附和 提交于 2019-12-07 15:57:28
问题 I am trying to check if a key-structure exists in the registry using powershell. If the structure does not exist, I need to create it and then I need to create the keys in the ending folder. If I run the snippets individually to create the keys, they create just fine. But running the block itself (ensuring manually within the registry that the keys don't exist) it won't create the folder structure. Not sure what the issue is. Any help would be appreciate. The code is as follows: $Registry

Compare and merge 2 csv files based on 2 first columns with possible duplicate values

送分小仙女□ 提交于 2019-12-07 15:07:27
I have 2 csv files I'm asked to merge where the values from the first column match. Both files can have the possibility of having duplicate values, and if they do, a new row should be created to support those values. If no match is found, then print the value no match. Except for looking for duplicate values, I am using the following code... Function GetFirstColumnNameFromFile { Param ($CsvFileWithPath) $FirstFileFirstColumnTitle = ((Get-Content $CsvFileWithPath -TotalCount 2 | ConvertFrom-Csv).psobject.properties | ForEach-Object {$_.name})[0] Write-Output $FirstFileFirstColumnTitle }

How to run the .reg file using PowerShell?

浪子不回头ぞ 提交于 2019-12-07 14:41:02
问题 I want to run the .reg file (registry file) using PowerShell Script but I am not able to run it. When i run it manually it creates the respective nodes in registry but i want it execute using powershell script. Below is the code which i tried using but got no results - $PathofRegFile="c:\file.reg" regedit /s $PathofRegFile Another code which i tried was this - Start-Process -filepath "C:\windows\regedit.exe" -argumentlist "/s c:\file.reg" Please Help..! Below is the Content of my .reg file

How to set LastWriteTime property of a file?

99封情书 提交于 2019-12-07 12:51:54
问题 I would like to change the creation date of the files that I generate with this script : $clientname = Read-Host "Enter the client name" $path = Read-Host "Enter the complete path of .bak files" $time = "01-00-00" $space = " " for ($i = 0; $i -lt 7;$i++) { $date = (Get-Date).AddDays(-1-$i).ToString('yyyy-MM-dd') New-Item -ItemType file $path$clientname$space$date$space$time.bak } So it gives me theses files : Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 16/08/2013 16:55

When a commandlet accepts pipeline input, what is the difference between ByPropertyName and ByValue?

痞子三分冷 提交于 2019-12-07 04:56:15
问题 Some PowerShell commandlets accept pipeline input ByProperyName, some do it ByValue, others do it for both. What does this mean? How does it impact our PowerShell scripts? 回答1: The ValueFromPipeline parameter attribute will map the parameter value to whatever object type is passed in from the pipeline. If you use the ValueFromPipelineByPropertyName parameter attribute, then a specific property will be used from the objects that are piped into the command+parameter. ValueFromPipeline Example

ConvertTo-SecureString gives different experience on different servers

徘徊边缘 提交于 2019-12-07 02:05:31
I am running into an issue creating a Credential Object from an XML File on a remote server. Here is the code I am using to test XML File <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"> <Obj RefId="0"> <TN RefId="0"> <T>Selected.System.Management.Automation.PSCredential</T> <T>System.Management.Automation.PSCustomObject</T> <T>System.Object</T> </TN> <MS> <S N="UserName">domain\username</S> <S N="Password"

Attempting to export remote registry hive with PowerShell

ⅰ亾dé卋堺 提交于 2019-12-06 22:36:26
I need to export registry keys from a remote computer for import into other remote machines (copy) using PowerShell V3.0. When I use REG QUERY to view the registry keys thus: reg query \\[computername]\HKLM\[subkey] /s | Out-File -append .\export.log all subkeys are recursively output to export.log as expected. However, when using REG SAVE to actually save a copy of the registry (in order to use REG RESTORE to import keys into target computers): reg save \\[computername]\HKLM\[subkey] .\export.hiv I am encountering the following error: "ERROR: The system was unable to find the specified

Apply service packs (.msu file) update using powershell scripts on local server

不想你离开。 提交于 2019-12-06 12:11:30
What it basically does is the script gets the .msu files from a location and copies to the "C:\temp\" folder. Then the script gets all the .msu files and stores the names in the array. Using the foreach loop it tries to apply the .msu updates to the local server where the script is running. However when i run the script. It doesn't do anything. Below is the code $from="sourceLocation\*.msu" $to="C:\temp\" Copy-Item $from $to -Recurse -Force $listOfMSUs= (Get-ChildItem –Path $to -Filter "*.msu").Name Write-Host $listOfMSUs if($listOfMSUs) { foreach($msu in $listOfMSUs) { Write-Host "Processing

Is there way to know cmdlet version in Powershell for backward compatibility?

浪子不回头ぞ 提交于 2019-12-06 12:01:09
Say you are scripting in Powershell 4.0 environment and you want to make sure the script works in Powershell 3.0. How do you ensure its backward compatible?. Ok the question as phrased is a little more specific into what you are looking for. Sounds like you are asking for requires . The #Requires statement prevents a script from running unless the Windows PowerShell version , modules, snap-ins, and module and snap-in version prerequisites are met. If the prerequisites are not met, Windows PowerShell does not run the script. That way, while you are scripting, you can enforce the functional

PowerShell to delete Desktop Items from a remote PC

末鹿安然 提交于 2019-12-06 11:30:58
I have 200 PC that need to have some specific icons removed. I created a CSV file with the ComputerName (1 name per row) I have another file with the file name of the icon that needs to be removed from the desktops (Shortcut1.lnk, etc). This other file is also a CSV (1 file name per row). How can I run a PowerShell script to remove those icons. (Please note that not all computers in my CSV file maybe turned on. Some maybe off or have network issues). $SOURCE = "C:\powershell\shortcuts" $DESTINATION = "c$\Documents and Settings\All Users\Desktop" $LOG = "C:\powershell\logs\logsremote_copy.log"