powershell-3.0

Dot Source a “script” within a Function

こ雲淡風輕ζ 提交于 2019-12-06 09:21:12
My PowerShell profile is getting a bit cumbersome and I find that I don't always use everything in it. I want to reduce the size of my profile and speed up the startup time that's been getting slower and slower, but I still want to be able to access those functions relatively quickly when I need them. Is there a way to "Dot Source" a set of PowerShell Functions and Aliases from within a separate function such that the sourced functions will be available outside of that function call? As others have already pointed out, the proper way to go about this would be to put those extra functions into

How do you get the name field of a JSON object in Powershell if you don't know it?

谁都会走 提交于 2019-12-06 09:02:11
问题 I have this JSON file: { "CARD_MODEL_TITLE": "OWNER'S MANUAL", "CARD_MODEL_SUBTITLE": "Configure your download", "CARD_MODEL_SELECT": "Select Model", "CARD_LANG_TITLE": "Select Language", "CARD_LANG_DEVICE_LANG": "Your device", "CARD_YEAR_TITLE": "Select Model Year", "CARD_YEAR_LATEST": "(Latest)", "STEPS_MODEL": "Model", "STEPS_LANGUAGE": "Language", "STEPS_YEAR": "Model Year", "BUTTON_BACK": "Back", "BUTTON_NEXT": "Next", "BUTTON_CLOSE": "Close" } And the syntax I use to convert it to a

Speed up PowerShell script for Windows Registry search (currently 30 minutes)

别说谁变了你拦得住时间么 提交于 2019-12-06 06:35:45
I'm working on a script for use in Windows 7 and Windows 10 for a Windows Registry search in HKLM:\Software\Classes. So far my code works, but it's extremely slow. It takes about 30 minutes to complete. I need to use Set-Location also to avoid an error with Get-ItemProperty, which occurs because the $path is not a valid object. How can I speed this code up? What's wrong? File regsearch.ps1 ( Mathias R. Jessen's answer applied) Function Get-RegItems { Param( [Parameter(Mandatory=$true)] [string]$path, [string]$match) #Set Local Path and ignore wildcard (literalpath) Set-Location -literalpath

Using PowerShell v3's Invoke-RestMethod to PUT/POST X Mb of a binary file

淺唱寂寞╮ 提交于 2019-12-06 04:13:35
问题 I have been doing a bit of work with PowerShell v3 (CTP2 from here) and its new Invoke-RestMethod like so: Invoke-RestMethod -Uri $dest -method PUT -Credential $cred -InFile $file However, I'd like to use this for pushing very large binary objects, and therefore like be able to push a range of bytes from a large binary file. For example, if I have a 20Gb VHD, I would like to break it up into chunks of say, 5Gb each (without splitting and saving the individual chunks first) and PUT/POST these

How to run the .reg file using PowerShell?

ぐ巨炮叔叔 提交于 2019-12-05 21:06:49
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 Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\SePI] [HKEY_LOCAL_MACHINE\SOFTWARE\SePI

How to set Low I/O (“background”) priority in Powershell

只谈情不闲聊 提交于 2019-12-05 20:14:08
There's this powershell script which can set processes' priorities from "Idle" to "Realtime" but some tools offer another priority level which drops a process's priority even below: How to set that in Powershell? It is not clear to me whether the IO priority can be set. The SetProcessInformation() call takes a PROCESS_INFORMATION_CLASS as an argument and that only defines ProcessMemoryPriority. I was having problems with a powershell script getting run out of task manager with a memory priority of 2 which was killing me. I am new to the PInvoke stuff and using it from PowerShell so I've

Start PowerShell ISE with the 2.0 runtime

前提是你 提交于 2019-12-05 19:56:53
问题 This question was migrated from Server Fault because it can be answered on Stack Overflow. Migrated 6 years ago . When PowerShell 3.0 is installed, I can force PowerShell to start using the version 2.0 -Version Starts the specified version of Windows PowerShell. Enter a version number with the parameter, such as "-version 2.0" This is useful with snapin that does not supports the .Net Framework V 4 (SharePoint!). Is there an equivalent for PowerShell ISE ? I tried to run powershell_ise.exe

How to set LastWriteTime property of a file?

有些话、适合烂在心里 提交于 2019-12-05 18:28:45
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 0 client 2013-08-15 01-00-00.bak -a--- 16/08/2013 16:55 0 client 2013-08-14 01-00-00.bak -a--- 16/08

PSRemoting performance overhead with get-childItem

南笙酒味 提交于 2019-12-05 17:16:56
This completes in 2.3 minutes on LOCALSERVER: A: measure-command {$x = invoke-command {gci -recurse "C:\"}} This completes in 38.4 minutes on LOCALSERVER: B: measure-command {$x = invoke-command -comp LOCALSERVER {gci -recurse "C:\"}} Why is B so much slower? Is it because the "output is being serialized to XML and then reconstituted into objects again", as explained here , with B but not A? Or is something else going on? LOCALSERVER runs Windows 2008R2 with PS v3. In both cases $x.count is 98973. I was wondering about changing an existing script to use PSRemoting for file searches on remote

Can Powershell Receive-Job return a DataSet?

一曲冷凌霜 提交于 2019-12-05 12:04:09
Background Info : I have an application that makes several SQL connections to multiple databases which currently takes a very very long time to execute. Powershell (.NET) will wait for each proceeding " SQL-GET " function to finish before it can fire off the next. I am under the impression I can speed this app up dramatically by firing each " SQL-GET " function in their own background job simultaneously!I will then retrieve the data from each job as they finish. Ideally as a DataSet system object. The Issues : When retrieving the data from the background job, I can ONLY manage to get a System