powershell-2.0

Launching background tasks in a remote session that don't get killed when the session is removed

柔情痞子 提交于 2019-11-29 09:47:47
I have been using PsExec -d to launch console applications in a remote powershell session because I want these apps to run in the background while I perform some task. The problem is that I want the background applications to continue running even if I kill the remote powershell session with Remove-PSSession . What happens currently is once the remote powershell session is killed so are all the processes that were started with the help of PsExec -d . I'm guessing it has something to do with process trees and how windows manages the lifetime of such things. Does anyone have any idea how I can

Why is Powershell 2.0 installed in the same location as Powershell 1.0?

…衆ロ難τιáo~ 提交于 2019-11-29 09:39:19
Does anyone know why Powershell 2.0 is installed in C:\Windows\System32\WindowsPowerShell\v1.0 on a Windows 7 box? Start-Automating It's actually an interesting story in side-effects. Visual Studio has a fixed list of assemblies in their "Add Reference" dialog. Anything else has to be browsed for. Developers tended to browse for this location in the Windows directory, where System.Management.Automation.dll (the assembly that runs most of PowerShell lives) This made an absolute reference to this location. Since there wasn't going to be a side-by-side install option with PowerShell (as there is

How do I use Add-Type to load Microsoft.Web.Deployment?

旧时模样 提交于 2019-11-29 09:13:34
I am writing some PowerShell scripts that use the MSDeploy API. I can load the assembly using [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Deployment") The location is in the GAC : PS > [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Deployment") | fl Location Location : C:\Windows\assembly\GAC_MSIL\Microsoft.Web.Deployment\7.1.0.0__31bf3856ad364e35\Microsoft.Web.Deployment.dll However, I am not able to load the assembly using Add-Type . I get an error saying the assembly cannot be found and that one or more assemblies are missing. PS > Add-Type

Create PSCredential without a password

此生再无相见时 提交于 2019-11-29 09:07:29
How to create a instance in PSCredential that has no password? Things I tried: $mycreds = New-Object System.Management.Automation.PSCredential ("username", $null) Error: Cannot process argument because the value of argument "password" is null $mycreds = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString $null -AsPlainText -Force)) Error: ConvertTo-SecureString : Cannot bind argument to parameter 'String' because it is null. $mycreds = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "" -AsPlainText -Force)) Error:

Launch Elevated CMD.exe from Powershell

╄→гoц情女王★ 提交于 2019-11-29 08:37:45
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 application from the user profile with no administrator rights that this script sits in, but when calling

PowerShell: Capture the output from external process that writes to stderr in a variable

£可爱£侵袭症+ 提交于 2019-11-29 07:42:08
I need to capture the output of a external process into a variable (string), so I can do some processing on that. The answer from here works nicely as long as the process writes to stdout. However, if the process fails, it writes to stderr. I'd like to capture this string too, and I can't figure out how to do it. Example: $cmdOutput = (svn info) | out-string This works, unless SVN has an error. If an error occured, SVN writes to stderr, and $cmdOutput is empty. How do I capture the text written to stderr in a variable in PowerShell ? Try this: $cmdOutput = svn info 2>&1 To complement manojlds'

Get Latest Version of Folder from TFS, using Powershell

痞子三分冷 提交于 2019-11-29 07:02:47
I am trying to " Get Latest Version " of a particular folder from TFS, using Powershell. I have installed the TFS Snappin, and have been using TFS Power Tools cmdlets in PowerShell (such as Get-TfsChildItem and Select-TfsItem etc) [ How do I set up TFS PowerShell Snapin ], and have gone through their documentation (which I didn't find explanatory enough!). Confused, on the exact cmdlet to use, when I am trying to get the latest version of an entire Folder structure from TFS, that is mapped to my local drive ( and not just a changeset or ChildItem ). Example : Tfs Path - $/APD-RepairSolutions

Import-Module : The specified module 'activedirectory' was not loaded because no valid module file was found in any module directory

落花浮王杯 提交于 2019-11-29 05:29:12
I am having trouble doing an import-module ActiveDirectory on a Server 2008 SP2 (64 bit). NET Framework 3.5 SP1 is installed I download the Windows6.0-KB968934-x86.msu (for ADWS) This file did not install saying that "The update does not apply to my system" Doing some research ( http://anti-american.rssing.com/chan-2091246/all_p15.html ) I installed hotfix in KB article 969166 and the above update installed. After a reboot, I noticed that in services, Active Directory Web Services is running I opened an administrative PS prompt and performed an Import-Module ActiveDirectory, but... ...I get:

Powershell script cannot access a file when run as a Scheduled Task

送分小仙女□ 提交于 2019-11-29 03:47:23
My Powershell (2.0) script has the following code snippet: $fileName = "c:\reports\1.xlsx" $xl = new-object -comobject excel.application $xlFormat = [Microsoft.Office.Interop.excel.XlFileFormat]::xlWorkbookDefault $xl.displayalerts = $false $workbook = $xl.workbooks.open($fileName) #Code to manipulate a worksheet $workbook.SaveAs($fileName, $xlformat) $xl.quit() $error | out-file c:\reports\error.txt I can run this script in the Powershell command prompt with no issues. The spreadsheet gets updated, and error.txt is empty. However, when I run it as a task in Task Scheduler, I get errors with

Read Json Object in Powershell 2.0

会有一股神秘感。 提交于 2019-11-29 03:18:36
I am using Powershell 2.0 (cannot make an upgarde to V3.0 as of now) & I want to read the below Json object. "{\"DevResults\":[{\"TechnologyName\":\"AD\",\"RuleName\":\"SOA account (user logon/display name)\",\"OutputValue\":\"SOADevClientCenter\"}, {\"TechnologyName\":\"AD\",\"RuleName\":\"SOA account (pre-Windows 2000)\",\"OutputValue\":\"SOADevCliCen\"}, \"ProdResults\":[{\"TechnologyName\":\"AD\",\"RuleName\":\"SOA account (user logon/display name)\",\"OutputValue\":\"SOAClientCenter\"}, {\"TechnologyName\":\"AD\",\"RuleName\":\"BPM Service Account (pre-Windows 2000)\",\"OutputValue\":\