powershell

Script Argument matching

二次信任 提交于 2021-01-27 07:16:08
问题 Does PowerShell do some sort of nearest match or autocompletion when dealing with arguments passed to a script? Given this code... [CmdletBinding()] Param( [string][Alias("aS")] $applySet, [string][Alias("cS")] $conformSet, [string][Alias("sL")] $setList, [Parameter(ValueFromRemainingArguments = $true)][Object[]]$extraParameters = @() ) Write-Host "s: $set" Write-Host "sL: $setList" Write-Host "aS: $applySet" Write-Host "cS: $conformSet" Write-Host "X: $extraParameters" If I use -junk "junk"

PowerShell cmdlet Install-WindowsFeature called from C# errors and is not listed in the collections of commands

你。 提交于 2021-01-27 07:15:15
问题 I'm trying to install new features on a Windows Server 2012 system through PowerShell and C#. I am getting this error back when trying to call the Install-WindowsFeature cmdlet: The term 'Install-WindowsFeature' is not recognized as the name of a cmdlet, function, script file, or operable program... I can call other cmdlets though C# and even some of the other new ones. I did a Get-Command and Install-WindowsFeature , Remove-WindowsFeature , and Get-WindowsFeatures are not listed...but about

Script Argument matching

这一生的挚爱 提交于 2021-01-27 07:14:57
问题 Does PowerShell do some sort of nearest match or autocompletion when dealing with arguments passed to a script? Given this code... [CmdletBinding()] Param( [string][Alias("aS")] $applySet, [string][Alias("cS")] $conformSet, [string][Alias("sL")] $setList, [Parameter(ValueFromRemainingArguments = $true)][Object[]]$extraParameters = @() ) Write-Host "s: $set" Write-Host "sL: $setList" Write-Host "aS: $applySet" Write-Host "cS: $conformSet" Write-Host "X: $extraParameters" If I use -junk "junk"

How can I find the potential source environment variable for a partial path in PowerShell?

北城以北 提交于 2021-01-27 07:12:43
问题 I want to write a function that converts regular path to path that includes environment variables: For example: C:\Windows\SomePath convert to: %Windir%\SomePath How would I do that and is this possible? Here is what I'm trying to do, but problem is, I need to check the string for all possible variables, is there some more automatic way? such that -replace operator wont be needed function Format-Path { param ( [parameter(Mandatory = $true)] [string] $FilePath ) if (![System.String]:

Clickable hyperlink on PowerShell's console output

妖精的绣舞 提交于 2021-01-27 07:09:58
问题 I'm having some issues with the following PowerShell script, could you please help me with that? What I'm trying to accomplish is create a clickable hyperlink in PowerShell's console output. Something like that: $testOutPut = "http://something.com" Write-Host $OutputConvertedIntoHYPERLINK Where the desired console response would be: clickable link to external app http://something.com My goal with it is to show this clickable information on build console into TFS 2015. 回答1: You can't do that

Cannot access Win32_WinSAT from 32 bits process

僤鯓⒐⒋嵵緔 提交于 2021-01-27 07:07:16
问题 When requesting Win32_WinSAT from a x64 process I get the correct results (WinSATAssessmentState = 1), but when executed from a x86 I get "results not available" (WinSATAssessmentState = 3) x64 Powershell: PS C:\Users\alive> gwmi Win32_WinSAT __GENUS : 2 __CLASS : Win32_WinSAT __SUPERCLASS : __DYNASTY : Win32_WinSAT __RELPATH : Win32_WinSAT.TimeTaken="MostRecentAssessment" __PROPERTY_COUNT : 8 __DERIVATION : {} __SERVER : COMPNAME __NAMESPACE : root\cimv2 __PATH : \\COMPNAME\root\cimv2:Win32

Clickable hyperlink on PowerShell's console output

孤街醉人 提交于 2021-01-27 07:06:14
问题 I'm having some issues with the following PowerShell script, could you please help me with that? What I'm trying to accomplish is create a clickable hyperlink in PowerShell's console output. Something like that: $testOutPut = "http://something.com" Write-Host $OutputConvertedIntoHYPERLINK Where the desired console response would be: clickable link to external app http://something.com My goal with it is to show this clickable information on build console into TFS 2015. 回答1: You can't do that

How to force delete an open file using PowerShell

﹥>﹥吖頭↗ 提交于 2021-01-27 07:05:28
问题 Remove-Item command does not delete files which are in use. Is there any way where we can delete all the files irrespective of their state? 回答1: You can do this is by finding the processes that are using the file then stop the processess.You can then delete the file after. $allProcesses = Get-Process #$lockedFile is the file path foreach ($process in $allProcesses) { $process.Modules | where {$_.FileName -eq $lockedFile} | Stop-Process -Force -ErrorAction SilentlyContinue } Remove-Item

Cannot access Win32_WinSAT from 32 bits process

半腔热情 提交于 2021-01-27 07:05:15
问题 When requesting Win32_WinSAT from a x64 process I get the correct results (WinSATAssessmentState = 1), but when executed from a x86 I get "results not available" (WinSATAssessmentState = 3) x64 Powershell: PS C:\Users\alive> gwmi Win32_WinSAT __GENUS : 2 __CLASS : Win32_WinSAT __SUPERCLASS : __DYNASTY : Win32_WinSAT __RELPATH : Win32_WinSAT.TimeTaken="MostRecentAssessment" __PROPERTY_COUNT : 8 __DERIVATION : {} __SERVER : COMPNAME __NAMESPACE : root\cimv2 __PATH : \\COMPNAME\root\cimv2:Win32

PowerShell Script Returning Unexpected Output (random numbers)

早过忘川 提交于 2021-01-27 06:50:24
问题 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,