powershell-3.0

How to iterate through remote registry keys using powershell?

断了今生、忘了曾经 提交于 2019-12-12 06:39:02
问题 I have a powershell script that goes through a list of name value pairs in a registry key and do some maniuplations. All of this happens inside the below foreach-object loop Get-ChildItem "HKLM:\SOFTWARE\PathA\pathB" -Recurse | ForEach-Object { $regkey = (Get-ItemProperty $_.PSPath) | Where-Object { $_.PSPath -match 'debug' } if ($masterList.Contains($_.Name)) #Check if the reg key is in master list { Set-ItemProperty -Path $regkey.PSPath -Name $_.Name -Value 1 } } This works perfectly fine

Delete user profile using Powershell

笑着哭i 提交于 2019-12-12 05:34:53
问题 I am wondering how I can delete user profile by using Powershell? I know the command of Get-WmiObject Win32_UserProfile which will give me the whole users on the computer. I have 2 variables of $computername and $username . So I wants to use the above command to delete on a remote computer (which is $computername ) the profile of $username . How I can do it? Thanks. 回答1: Get-WMIObject can retrieve objects from remote computers with no problem, and not only does the Win32_UserProfile class

Powershell - Import local CSV

时间秒杀一切 提交于 2019-12-12 05:32:16
问题 I have a powershell script that imports a CSV file using this command: $empCsv = Import-Csv "addEmp.csv" I have the csv sitting in the same directory as the script but I'm getting a FileNotFoundException . If I use the command with a path to the CSV like this: $empCsv = Import-Csv .\Desktop\createUser\addEmp.csv It works fine. I want to be able to give this script to someone to use and let them run the script from any location and be able to import the .csv that's sitting in the same

Running Remote Powershell Commandlet that wraps a process exits before completion

核能气质少年 提交于 2019-12-12 04:48:53
问题 I have a custom PowerShell commandlet that I have created in C# that spins up some instances of vstest.console.exe and publishes the test results to a .trx file or to tfs. This commandlet works in isolation when using PowerShell locally. However when I run the commandlet remotely using v3 PowerShell remoting, The invoke-command completes, but there are 2 issues: The test run process does not complete as there is no results file published I do not get the results on the remote console, whereas

Enabling desktop experience from C# on windows 2008 / 2012

懵懂的女人 提交于 2019-12-12 04:42:41
问题 I am currently using command: servermanagercmd -install Desktop-Experience From what I read, I understood that this is no longer supported in Windows 2012. I understood that can be done from PowerShell cmdlet somehow but can't find an example for a need. 回答1: I think the PS script you're looking for is: Add-WindowsFeature Desktop-Experience 回答2: I don't think the Add-WindowsFeature command will work back in 2008. DISM is the best route for all versions involved. Dism /online /Enable-Feature

PowerShell - ForEach using SQL data input

吃可爱长大的小学妹 提交于 2019-12-12 04:37:51
问题 I am using powershell code to first connect on a database and from the SELECT I am making, this output is then output : NAME: %SERVERNAME1 NAME: %SERVERNAME2 Now I want to make a "foreach" loop where it will make a "get-childitem" on every %SERVERNAME to find every EXE files and output to out-gridview. My foreach look like this but obviously it doesn't work : $Connection.open() Write-host "Database Connection $databasename = SUCCESSFULL : Searching role $Role in $palier ..." -foregroundcolor

Try/catch not working in Powershell console, but works in ISE

谁都会走 提交于 2019-12-12 04:32:07
问题 I have a Powershell script with try / catch parts to write the errors into a logfile. This works perfectly fine in Powershell ISE, but not in the Powershell console. Here's the script: $serverfile = "C:\Serverlist.txt" $Logfile = "C:\Deploy_Log.txt" $startdate= "01/05/2016" $starttime = 13 Set-StrictMode -Version latest $ErrorActionPreference = "Stop" $WarningPreference = "Stop" function LogWrite { param([string]$logstring) Add-Content $Logfile -Value $logstring } function DeployTask { param(

How to extract metadata using a specific filename (get-childitem) rather than looping through ComObject namespace items

血红的双手。 提交于 2019-12-12 03:59:24
问题 I have found multiple code snippets to scroll through a folder and display the metadata of each item in the folder, like this: function funLine($strIN) { $strLine = "=" * $strIn.length Write-Host -ForegroundColor Yellow "`n$strIN" Write-Host -ForegroundColor Cyan $strLine } $sfolder = "S:\Temp" $objShell = New-Object -ComObject Shell.Application $objFolder = $objShell.namespace($sFolder) foreach ($strFileName in $objFolder.items()) {funline "$($strFileName.name)" for ($a ; $a -le 266; $a++) {

Matching Lines in a text file based on values in CSV

ⅰ亾dé卋堺 提交于 2019-12-12 03:56:24
问题 Hi Everyone, I am having trouble with the below script. Here is the requirement: 1) Each text file needs to be compared with a single CSV file. The CSV file contains the data to that if present in the text file should match. 2) If the data in the text file matches, output the matches only and run jobs etc.. 3) If the text file has no matches to the CSV file, exit with 0 as no matches are found. I have tried to do this, but what I end up with is matches, and also non matches. What I really

Powershell loop through xml to create a jagged array

橙三吉。 提交于 2019-12-12 03:48:50
问题 I'm guessing this is pretty simple, I'm just starting with powershell and I can't seem to find a simple solution after a few hours searching the net. Basically I have the following xml file <Config> <System> <Server> <Name>host1</Name> <Service>service1</Service> <Service>service2</Service> </Server> <Server> <Name>host2</Name> <Service>service1</Service> </Server> </System> <System2> <Server> <Name>host1</Name> <Service>service1</Service> <Service>service2</Service> </Server> <Server> <Name