powershell

PowerShell Script Returning Unexpected Output (random numbers)

天涯浪子 提交于 2021-01-27 06:46:04
问题 Problem I am writing a script in PowerShell that uploads a file to an http server. The upload completes successfully, but its returning a bunch of numbers in the console upon execution (far more than what is displayed below). Output: Here's the script I'm running: Param([Parameter(Mandatory=$True,Position=1)] [string]$user, [Parameter(Mandatory=$True,Position=2)] [string]$pass, [Parameter(Mandatory=$True,Position=3)] [string]$dir, [Parameter(Mandatory=$True,Position=4)] [string]$fileName,

Can Powershell read code from stdin?

倾然丶 夕夏残阳落幕 提交于 2021-01-27 06:45:25
问题 I'm trying to run a Powershell subprocess from Python. I need to send Powershell code from Python to the child process. I've got this far: import subprocess import time args = ["powershell", "-NoProfile", "-InputFormat None", "-NonInteractive"] startTime = time.time() process = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) process.stdin.write("Write-Host 'FINISHED';".encode("utf-8")) result = '' while 'FINISHED' not in result: result += process

Can Powershell read code from stdin?

淺唱寂寞╮ 提交于 2021-01-27 06:44:43
问题 I'm trying to run a Powershell subprocess from Python. I need to send Powershell code from Python to the child process. I've got this far: import subprocess import time args = ["powershell", "-NoProfile", "-InputFormat None", "-NonInteractive"] startTime = time.time() process = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) process.stdin.write("Write-Host 'FINISHED';".encode("utf-8")) result = '' while 'FINISHED' not in result: result += process

Azure DevOps get commits linked to a work item via the REST API

ⅰ亾dé卋堺 提交于 2021-01-27 06:36:49
问题 Is there a way to get Git Commits that are linked to a work item given only the work item ID? I'm using PowerShell and this URI to get work items, but I don't see any of the linked commits on the returned object. I also don't see any documentation on how to get these links. $Results = Invoke-RestMethod -Uri "http://azuredevops/azuredevops/Collection/Project/_apis/wit/workitems?api-version=5.1&ids=1" -Method "GET" -UseDefaultCredentials | Select-Object -ExpandProperty Value $Results.fields 回答1

Pester mock method for Powershell 5 class

喜你入骨 提交于 2021-01-27 05:40:46
问题 I am having an issue trying to mock a powershell 5 class method, when executing the test, I get the error " CommandNotFoundException: Could not find Command FunctionToMock". I am trying to unit test the "OutputToOverwrite" method by mocking "FunctionToMock". I think I would have to mock ChocoClass itself first, but I am not sure how to do it. Thanks. Class ChocoClass { [string] OutputToOverwrite() { return $this.FunctionToMock() } [string] FunctionToMock() { return "This text will be replaced

Pester mock method for Powershell 5 class

不羁的心 提交于 2021-01-27 05:40:35
问题 I am having an issue trying to mock a powershell 5 class method, when executing the test, I get the error " CommandNotFoundException: Could not find Command FunctionToMock". I am trying to unit test the "OutputToOverwrite" method by mocking "FunctionToMock". I think I would have to mock ChocoClass itself first, but I am not sure how to do it. Thanks. Class ChocoClass { [string] OutputToOverwrite() { return $this.FunctionToMock() } [string] FunctionToMock() { return "This text will be replaced

Error: Unable to index into an object of type in Powershell

旧巷老猫 提交于 2021-01-27 05:38:52
问题 Below is powershell script. $Requests = Get-WmiObject -Class SMS_UserApplicationRequest -Namespace root/SMS/site_$($SiteCode) -ComputerName $SiteServer | Select-Object User,Application,CurrentState,Comments | Sort-Object User $Count = @($Requests).Count for ($i=0; $i -lt $count; $i++) { if ($Requests[$i].CurrentState -eq '1') { $Requests[$i].CurrentState = "Pending" $checkbox1.Enabled = $true } when I execute the script I am getting following error. Unable to index into an object of type

Unable to configure ASP.NET HTTPS endpoint in Windows docker container

 ̄綄美尐妖づ 提交于 2021-01-27 04:57:37
问题 Getting this error when running ASP.NET Core in Windows docker container... Unhandled Exception: System.InvalidOperationException: Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found. I was able to get this to work... RUN dotnet dev-certs https But I want to install an actual certificate...for now a self-sign certificate but later a real one. So based on a blog post titled "Import and bind an SSL cert in a Windows

Python hangs after some time, Continues when pressed [Enter]

旧城冷巷雨未停 提交于 2021-01-27 04:20:09
问题 I have made a python script which prints and logs CPU % and memory usage of a particular process every 2 seconds. It was working pretty fine. Until I went for a break. (after one hour) When I check again, the python script was paused (or hung). When I pressed [Enter], it started executing again as usual. The script worked fine for 1 hour. Then the log and output were missing for 1hour 30 minutes and not it is working fine again. What is the cause of the pause.? How can I prevent it.?

What is “cooked value” returning in Powershell's get-counters cmdlet?

柔情痞子 提交于 2021-01-27 04:08:10
问题 I'm using Powershell to return values for certain performance counters, and I'm seeing that it is referring to "Cookedvalues" when presenting the information. I'm looking for each counter hit to be reported on it's own, so I can do analysis like seeing the 90th percentile values or max/min, so I need to know how it is arriving at Cooked Value. Here is the code I am currently working with: $computer = $ENV:Computername $instance = "_total" @("\\$Computer\PhysicalDisk(*)\Current Disk Queue