powershell-3.0

Attempting to export remote registry hive with PowerShell

天大地大妈咪最大 提交于 2019-12-10 11:41:12
问题 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] .

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

半世苍凉 提交于 2019-12-10 11:29:52
问题 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

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

若如初见. 提交于 2019-12-10 10:51:32
问题 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?. 回答1: 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

Dot Source a “script” within a Function

北慕城南 提交于 2019-12-10 10:35:57
问题 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? 回答1: As

Word.Application ComObject errors in PowerShell

假如想象 提交于 2019-12-10 09:32:38
问题 I'm unable to get a Word 2010 (14.0.x) document to SaveAs or Close using Powershell. From all the tuts online it seems like it should be working with 2.0, but I don't have that anymore. Simple case: $Path = "C:\MyDoc.docx" $Word = New-Object -comobject Word.Application $Word.Visible = $True #Do this to close it out without task manager $Doc = $Word.Documents.Open($Path) $Doc.SaveAs($Path) $Doc.Close() At this point everything works up until the saving and closing: Argument: '1' should be a

Convert UNC Path to NTFS local path

≯℡__Kan透↙ 提交于 2019-12-10 00:12:49
问题 I have a problem converting UNC location to local drive in powershell. So my code basically takes input from user as read Host as UNC path for a DB Backup location. The location could be like this \\ServerName\m$\SQLBackups\123 . It then prompts where the backup is being copied from. Again this is a UNC path such as \\ServerName\g$\SQLRestores\444\Filename.bak . I need to convert both paths to their local path so that it reads m:\sqldbackups\123 and g:\sqlrestores\444\Filename.bak . Here is

Why is this PowerShell code (Invoke-WebRequest / getElementsByTagName) so incredibly slow on my machines, but not others?

时光总嘲笑我的痴心妄想 提交于 2019-12-09 21:41:32
问题 I wrote some screen-scraping code in PowerShell and was surprised that it took around 30 seconds to parse a few HTML tables. I stripped it down to try and figure out where all the time was being spent, and it seems to be in the getElementsByTagName calls. I've included a script below which on both my home desktop, my work desktop and my home slate, takes around 1-2 seconds for each iteration (full results pasted below). However, other people in the PowerShell community are reporting far

Launch Elevated CMD.exe from Powershell

一曲冷凌霜 提交于 2019-12-09 19:00:25
问题 I am trying to launch an elevated CMD window from PowerShell but I am running into some issues. Below is the Code I have now. There is an admin account on the machine that has the username of "test" and a Password of "test" $username = "test" $password = ConvertTo-SecureString "test" -AsPlainText -Force $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password Start-Process "cmd.exe" -Credential $cred This is all working fine for running an

Executing a batch file in a remote machine through PsExec

旧街凉风 提交于 2019-12-09 06:46:05
问题 I am trying to run a batch file (in the batch file I have just written 'notepad') on a remote PC through PSExec. The psexec command below runs in my laptop but fails to do anything on the remote PC. I don't even see 'notepad' running on the list of processes in the remote machine. c:\Program Files (x86)\PSTools>psexec -u administrator -p force \\135.20.230.160 -s -d cmd.exe /c -c "C:\Amtra\bogus.bat" PsExec v2.11 - Execute processes remotely Copyright (C) 2001-2014 Mark Russinovich

List of all colors available for PowerShell?

≯℡__Kan透↙ 提交于 2019-12-09 05:20:52
问题 I am searching for a list of all colors I can use in PowerShell. Since we need to provide names and no hexnumbers, it's hard to figure out if a color exists or not, at least if you don't know how :)) For example, as -foregroundcolor write-host "hello world" -foregroundcolor "red" 回答1: The console colors are in an enum called [System.ConsoleColor]. You can list all the values using the GetValues static method of [Enum] [Enum]::GetValues([System.ConsoleColor]) or just [Enum]::GetValues(