PowerShell
Update: Microsoft will be moving away from UserVoice sites on a product-by-product basis throughout the 2021 calendar year. We will leverage 1st party solutions for customer feedback. Learn more
The following is a list of the states we use to track items.
status | meaning |
---|---|
survey | We saw this and we are considering it. Please upvote if it’s important to you. |
needs more information | We don’t understand the issue and need additional details. |
investigating | We are looking at this internally to understand things like: scenario, reproduction of issue, costing, or other technical details. |
in queue | The issue is understood and in our unprioritized backlog. Your votes will be used to drive prioritization of this work. |
-
Application doesn't get triggered from Powershell script, when invoking inside Do…Until
I am trying to build custom Windows System Utility script which offers some tasks with relevant keypress choices.
For cleanup task, I am trying to invoke CCleaner64.exe from this script, with it's correct switches as mentioned here. And the script I built so far is below:
$ScriptDir = Split-Path $MyInvocation.MyCommand.Path
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
$CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
Exit
}}
Set-Location $ScriptDir; Echo 'Current Directory: ' + (Get-Location | Out-String)function SysUtilMenu…
1 vote -
Bug in class parser
Summary of the issue
Currently powershell is unable to implement [Composition Over Inheritance](https://www.makeuseof.com/tag/basic-programming-principles/#composition-over-inheritance) because of a lack of support for custom interfaces, which prevents multiple inheritance of behavior interfaces
There is a way to get it to work, but it only works when running the code by hand, not in automated scripts
Proposed technical implementation details (optional)
The issue with the workaround boils down to a problem in the parser error: InterfaceNameExpected
It fails to recognize that using Add-Type will add types, instead it incorrectly assumes the given type will not be availableI think we should either…
1 vote -
Remove-Item on a file fails if the path is in shortened 8.3 format
Steps to reproduce:
- Go to your %TEMP% folder and create file Test.txt
- Open Powershell and execute these commands:
$literalPath = (Get-Item -LiteralPath $env:temp).FullName
Test-Path $($env:path + "\Test.txt")
Test-Path $($literalPath + "\Test.txt")
Remove-Item -Force $($env:path + "\Test.txt")
Remove-Item -Force $($literalPath + "\Test.txt")
Both calls to Test-Path succeed, the first call to Remove-Item fails, the second call to Remove-Item succeeds.
Expected behaviour:
Both calls to Remove-Item should succeed.1 vote -
Hyper-v cmdlets do not find wsl paths
This issue is a problem I'm having using Add-VMHardDiskDrive.
I am not able to use a WSL path as argument. It seems the cmdlet can't access paths located in other network devices.
Steps to reproduce
Add-VMHardDiskDrive -VMName test -Path \\wsl$/Ubuntu/home/<image path>Expected behavior
The cmdlet returns the success message describing that the disk was mounted successfully in the hyper-v virtual machine specified.
Actual behavior
```
Add-VMHardDiskDrive : 'test' failed to add resources to
'test'.
An unexpected error occurred: The network name cannot be found. (0x80070043).
'test' failed to add resources. (Virtual machine ID
4F4777B2-4DFD-4A07-89B6-44FFC5BE2D3F)
'main-image-1611598805' encountered an unexpected error: The…1 vote -
Get-PhysicalDisk memory leak
If you run Get-PhysicalDisk (in a powershell-loop or called from a C# application) you will see after after hundreds/thousands of runs a memory-leak.
https://github.com/MicrosoftDocs/windows-powershell-docs/issues/2290
1 vote -
Changes to $DebugPreference Cause Functions in Imported Module To Fail
In a relatively simplistic login script deployed by GPO using "ExecutePolicy Unrestricted" the changing of the $DebugPreference can cause a "Test-Path" command within a function in a imported module to fail.
In the attached if $DebugPreference is set to "Continue" everything works as expected. If it's set to "SilentlyContinue" the "Test-Path $InstallPath" check fails.
Pulling the same function into the original login script results in the function working properly no matter what the preference is set to.
1 vote -
Changes to $DebugPreference Cause Functions in Imported Module To Fail
In a relatively simplistic login script deployed by GPO using "ExecutePolicy Unrestricted" the changing of the $DebugPreference can cause a "Test-Path" command within a function in a imported module to fail.
In the attached if $DebugPreference is set to "Continue" everything works as expected. If it's set to "SilentlyContinue" the "Test-Path $InstallPath" check fails.
Pulling the same function into the original login script results in the function working properly no matter what the preference is set to.
1 vote -
Install a program remotely via RunAs
With this code, I want to install a program via cmd in administrative mode, but it doesn't work
$RemoteMachine = "10.1.1.40"
$Username = 'user'
$Password = ' '
$pass = ConvertTo-SecureString -AsPlainText $Password -Force
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$passInvoke-Command -ComputerName $RemoteMachine -Credential $Cred -ScriptBlock { Start-Process -FilePath "c:\install.bat" -Verb RunAs }
1 vote -
1 vote
-
Allow IF statements to be enclosed in () without using a variable.
Can someone explain why IF statements fails when enclosed in () without a variable? See example below:
$x = 5
$y = 6Fails
( if ($x -eq $y) { "Match" } ELSE { "No Match" } )
Works
if ($x -eq $y) { "Match" } ELSE { "No Match" }
( $xy = if ($x -eq $y) { "Match" } ELSE { "No Match" } )Returned Error
if : The term 'if' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was…
1 vote -
Invoke-Command for ComputerName localhost starts to fail after a scheduled job is run
Typically I can run invoke-command against localhost without requiring any credentials. For example, this works:
Invoke-Command -ComputerName localhost -ScriptBlock { return $null }
However, if you then use the same system to run a scheduled job, for example:
Register-ScheduledJob -ScriptBlock { write-host "hi" } -RunNow
You will see that afterwards the former Invoke-Command will now fail with access denied and requires credentials to be passed in order to succeed.
Basically the behavior of Invoke-Command and localhost remoting is CHANGED when you execute Register-ScheduledJob with -RunNow. This is not expected or documented.
1 vote -
Bug: When defined in an expression, defining a class with references to two other classes throws "Could Not Load Type"
When importing a module that uses expressions to define custom powershell classes, if a class definition references two or more previously defined, custom powershell classes, PowerShell runtime throws an "Could not load type" exception.
Version: PowerShell 5.1, Windows 10
Code to reproduce:
The below code can either be put into into a module file or run directly in a powershell window:Invoke-Expression @'
enum EnumOne {
One = 1
Two = 2
Three = 3
Four = 4
}
'@Invoke-Expression @'
class ClassOne {
[string]$Property1ClassOne([string]$prop1) {
$this.Property1 = $prop1
}
}
'@Invoke-Expression @'
class ClassTwo {
[ClassOne]$ClassOne …1 vote -
JEA -user should not be able to bypass cmdlet restrictions
Presently, if JEA is enabled on target server with cmdlet restrictions for a user account 'user1' - then if the user1 sends command construct with below structure then irrespective of cmdlet restrictions - user1 is able to obtain administrative privelege. This should be fixed as anyone can misuse the JEA features.
1 vote -
Windows PowerShell 5.1 hangs displaying result from Invoke-WebRequest
Entering this reproducibly hangs Windows PowerShell 5.1:
$r = iwr 'https://marketplace.visualstudio.com/items?itemName=austin.code-gnu-global'
$rHere's what one gets with Set-PSDebug -Trace 2:
> $r
DEBUG: 94+ >>>> {
DEBUG: ! CALL function '<ScriptBlock><DynamicParam>'
DEBUG: 97+ >>>> $getCommand = $executionContext.InvokeCommand.GetCmdlet(
DEBUG: ! SET $getCommand = 'Get-Command'.
DEBUG: 99+ >>>> $foreachObject = $executionContext.InvokeCommand.GetCmdlet(
DEBUG: ! SET $foreachObject = 'ForEach-Object'.
DEBUG: 101+ >>>> $whereObject = $executionContext.InvokeCommand.GetCmdlet(
DEBUG: ! SET $whereObject = 'Where-Object'.
DEBUG: 107+ >>>> $command = & $getCommand Out-Default -Type Cmdlet
DEBUG: ! SET $command = 'Out-Default'.
DEBUG: 108+ >>>> $targetParameters = @{}
DEBUG: ! SET $targetParameters = 'System.Collections.Hashtable'.
DEBUG: 109+ >>>>…2 votes -
PowerShell 5.1 can mix two encodings, like Unicode and utf8, in the same file.
This happens when you using "Get-Content" for a file written by PowerShell with "Out-File", and also when PowerShell_ISE prints variables obtained from other applications with "IBM037" encoding, PowerShell prints the result to the Console and mixes both UTF-8 and Unicode characters.
Which makes it impossible to filter a result properly. (This can be seen by printing the result out by Out-GridView )
1 vote -
Start-sleep progress bar
We require a progress bar to track the time is left till the Pause ends.
1 vote -
Windows file shortcuts
Powershell should be able to create windows shortcuts natively. .lnk
1 vote -
BUG Using Where-Object? PowerShell 4.0 and 5.1 OK in 2.0
I really think there is a bug in Where-Object with $_.LastAccessTime
It always returns Last Write Time, NOT Last Access Time. However, Select-Object works..Sample -
Get-ChildItem -Recurse -Path c:\ | Where-Object {$_.LastAccessTime -le (Get-Date).AddDays(1)}Result -
Mode LastWriteTime Length Name
...list of files...
I have tested with PowerShell 2.0 (Windows 2008 R2) 4.0 (Windows 2012 R2) and 5.1 (Windows 2016 and Windows 10).
It WORKS as expected on Powershell 2.0
However, this sample works, but I am unable to finger out how to do anything (like Remove-Item) with the results.
< save the below as a .ps1 file and…
1 vote -
Put CloudShell on Office 365
Put this directly into the Office 365 Admin console if you are forcing us to use something that never works unless you've become a professional with it AND get all the updates on all the changes that happen in just a single month, so put it directly in Office 365 just like Azure has and YOU keep it updated with the right libraries and modules and all that so when we need to run a command, we don't have to search for 45 minutes to get it going, or when you need to run tech support, you know the platform…
1 vote -
Powershell command subommand parameters interactive list with ? button
A function like cisco devices that show a list of powershell parameters with the ? button:
Example:
Restart-Computer -c?-computername
-credential
-others1 vote
- Don't see your idea?