powershell

How to read PowerShell script stdout and stderr from C#

橙三吉。 提交于 2021-01-27 14:58:58
问题 I'm implementing a custom PowerShell host and I need to read stdout and stderr of the PowerShell script. Problem is that I do not get stdout when I convert object returned by invoking pipeline to string. However, when I add "out-string" cmdlet to the pipeline it works perfectly fine. Is there any way to fetch stdout and stderror without using "out-string"? this.currentPowerShell.AddScript(cmd); Collection<PSObject> results = this.currentPowerShell.Invoke(); foreach (PSObject obj in results) {

Put Assembly Version from AssemblyInfo.cs in Web.config

孤街浪徒 提交于 2021-01-27 14:41:22
问题 I have this scenario, where I have the project's Assembly Version from AssemblyInfo.cs, for example 2.0.0 as below: [assembly: AssemblyVersion("2.0.0")] In addition, I would like to retrieve this AssemblyVersion and set it as part of the parameters in my web.config dynamically, such as below, for example: <my.config.group> <version versionNumber="2.0.0" /> </my.config.group> I need to set the version number above, as the version number of my Assembly dynamically, to avoid having to modify it

Refreshing Excel Sheets using powershell

旧巷老猫 提交于 2021-01-27 14:39:46
问题 I have 10 excel different excel sheet in one folder named test. I want to refresh the data connection and data in the pivot table using windows power shell script. The process is using for each loop open each file and then in the file choose powerpivot menu refresh all data there which will refresh the OLEDB and OLAP query and then close that page and go to the data tab and click on the refresh all button and after refreshing work book in each excel sheets there are 5 sheets in 4 out of 5

How to read PowerShell script stdout and stderr from C#

寵の児 提交于 2021-01-27 14:36:42
问题 I'm implementing a custom PowerShell host and I need to read stdout and stderr of the PowerShell script. Problem is that I do not get stdout when I convert object returned by invoking pipeline to string. However, when I add "out-string" cmdlet to the pipeline it works perfectly fine. Is there any way to fetch stdout and stderror without using "out-string"? this.currentPowerShell.AddScript(cmd); Collection<PSObject> results = this.currentPowerShell.Invoke(); foreach (PSObject obj in results) {

Executing a scriptblock via startprocess

家住魔仙堡 提交于 2021-01-27 14:23:30
问题 Would any of you possibly know why this is not working? Start-Process $PSHOME\powershell.exe -ArgumentList "-NoExit -Command & `"{$outvar1 = 4+4; `"out: $outvar1`"}`"" -Wait The ultimate purpose for this is so that i can run a script block as another user with the addition of the -Credential option. But i can not get this simple script block to work yet. Many thanks. Chris. 回答1: Here is somthing that is working: PS C:\> Start-Process $PSHOME\powershell.exe -ArgumentList "-NoExit","-Command `"

DSC File Resource - copy file

僤鯓⒐⒋嵵緔 提交于 2021-01-27 14:12:37
问题 I'm using a PowerShell DSC Pull Server. It's possible to use the File resource to copy a file every time is modified? I've tried the below: File Test{ DestinationPath = "c:\yyy\test.txt" SourcePath = "\\share\test.txt" Ensure = "Present" Type = "File" Credential = $Credential Checksum = "modifiedDate" Force = $true} but no luck: if I modify the file from SourcePath I'd expect that the destination file should be updated too. 回答1: Add MatchSource, See documentation here. File Test{

Converting JSON to PowerShell object and converting PowerShell back to JSON

不想你离开。 提交于 2021-01-27 14:11:37
问题 I am exporting the JSON from an Azure Resource Group to a JSON file like this: Export-AzureRmResourceGroup -ResourceGroupName $SourceResourceGroupName -Path $filename Then I am getting the JSON contents of the file, then applying it to a variable: $SourceJSON = Get-Content $filename -Raw I then want to turn (convert) this into a PowerShell object: $SourceJSONRG = $SourceJSON | ConvertFrom-Json I then have a look at the resources from with the object: $SourceJSONRG.resources But the

Converting JSON to PowerShell object and converting PowerShell back to JSON

时间秒杀一切 提交于 2021-01-27 14:03:01
问题 I am exporting the JSON from an Azure Resource Group to a JSON file like this: Export-AzureRmResourceGroup -ResourceGroupName $SourceResourceGroupName -Path $filename Then I am getting the JSON contents of the file, then applying it to a variable: $SourceJSON = Get-Content $filename -Raw I then want to turn (convert) this into a PowerShell object: $SourceJSONRG = $SourceJSON | ConvertFrom-Json I then have a look at the resources from with the object: $SourceJSONRG.resources But the

GetScheduledTaskInfo NextRunTime is wrong

北慕城南 提交于 2021-01-27 13:42:04
问题 I'm trying to use Powershell to get the NextRunTime for some scheduled tasks. I'm retrieving the values but they don't match up to what I'm seeing in the Task Scheduler Management Console. For example, in the Task Scheduler console my "TestTask" has a Next Run Time value of "1/9/2018 12:52: 30 PM". But when I do the following call in Powershell it shows "12:52: 52 PM" for the NextRunTime. Get-ScheduledTask -TaskName "TestTask" | Get-ScheduledTaskInfo From what I've seen the seconds value is

Using Powershell with MICROSOFT.ACE.OLEDB.12.0 to convert between CSV XML XLS XLSX XLSM

别说谁变了你拦得住时间么 提交于 2021-01-27 13:25:20
问题 How do I convert files between CSV, XLS, XLSM, and XLSX to CSV, XLS, XLSX, and XML in Powershell without using Excel.Application? I would like to just use MICROSOFT.ACE.OLEDB.12.0. 回答1: I wrote this as a module first, but then prefer it as a ps1 to .include. You could also pop it in the top of a file and call it underneath. A note about creating excel spreadsheets without using excel: I am not very good at it. It seems to be working with the data I throw at it. If you have a better way of