236 questions
0
votes
2
answers
203
views
How can I use Invoke-Command with WSMan in PowerShell 7 if "Powershell.7" endpoint does not exist?
I'm trying to run a remote command using Invoke-Command over WSMan in PowerShell on my local machine.
Here’s my test script:
$server = 'localhost'
Invoke-Command -Authentication Negotiate -...
4
votes
2
answers
99
views
Isn't Strict Mode supposed to throw exception when accessing a non-existent key
I am using Set-StrictMode and $ErrorActionPreference
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$Foo = @{}
$Foo["bar"] # No exception
$Foo.bar # Exception as ...
0
votes
0
answers
30
views
Cannot comprehend why my VS dev console chokes, but regular powershell 7 works, is this caused by Powershell 5's arg handling? [duplicate]
I have this snippet in a Powershell script, I can run the script on PSVersion 7.4.7 without error or problem, the git option gets set properly.
$cmd = '"' + $mergeTool + '&...
2
votes
0
answers
92
views
Why can't the type of a PowerShell function parameter be changed once it's been bound? [closed]
I thought PowerShell is a dynamically-typed language because I can do this:
$var = "1234"
echo $var.GetType().Name # String
$var = 1234
echo $var.GetType().Name # Int32
However, when I try ...
0
votes
1
answer
117
views
Powershell script using Add-PnPFile to add same file to 2 different libraries isn't working
I wrote a script to add files to a document library within SharePoint. Pretty straightforward, however I now want to add that same file to a different document library depending on if certain criteria ...
1
vote
1
answer
70
views
Is there an equivalent for the Matlab function "ismember" in Powershell?
Ex: I have a script that compares file information to a previously saved database file that has the same file information plus the calculated hash of each file. If the current file properties match ...
0
votes
1
answer
533
views
Applying a template with PnP to a SharePoint site
I am writing a script to export a template from a SharePoint site then uploading it to a different tenant.
I am using PnP PowerShell library, and I am exporting the template using this command:
Get-...
0
votes
1
answer
72
views
Parameter values empty in Powershell function
All my parameter values are being received as empty in this seemingly straightforward function:
function Get-SSH-Command {
param (
[string]$private_key_path,
[string]$user,
...
0
votes
1
answer
1k
views
Update Powershell 7 to specific version without winget
I have a server running Powershell 7.3.10 core and I need to upgrade to 7.4.2 which is the latest version my company supports. The problem is the server doesn't have winget on it and I can't find an ....
1
vote
0
answers
191
views
Executing PowerShell scripts from C# .NET 6 web app using RunImpersonated not working - Scripts still execute as IIS APPPOOL\APP
My app needs to execute PowerShell scripts to create and manage AD accounts. My current setup uses HangFire to launch background jobs, PowerShell execution being one of them. I have an ...
0
votes
1
answer
2k
views
Start Powershell 5 out of Powershell 7
My main Script is Powershell 7, but i want to run a function in powershell 5 (because this function is only possible in powershell 5).
I also want to give the function a psobject and return a psobject,...
0
votes
1
answer
83
views
On running the dotnet --version or dotnet run command on Visual Studio or VSCode Poweshell, we are getting the Windows popup asking for App selection
On running the dotnet --version or dotnet run command on Visual Studio or VSCode PowerShell, we are getting the Windows popup asking for App selection. Same issue doesn't occur on command prompt when ...
0
votes
0
answers
65
views
TextBox.Text gets saved as System.Object
I started writing a script to copy specific attributes from one AD-User and create a new User with those attributes and a different name. So far so well, it worked in the past.
I deleted a codeblock ...
0
votes
1
answer
134
views
How to export/import cmdlet from local module?
The problem I have is that cmdlets are not exported and not imported.
Consider following module example (.\Modules\Tools.psm1)
Function Write-Message() {
param ([String] $Message)
Write-...
2
votes
1
answer
196
views
Why PowerShell $Matches Hashtable automatic variable is not returning all matches?
I'm using Named Captures in PowerShell. But the following example is not returning all matches. All the lines in the following code return correct output - except the lines 7 and 8. I was expecting $...
2
votes
1
answer
398
views
How to error handle Invoke-Command over SSH
I'm currently working with a script that utilizes the Invoke-Command over SSH as shown below. While it works well, I'm looking to implement exception handling, specifically for scenarios where the ...
0
votes
0
answers
616
views
COM Objects, Powershell 5 vs 7 and Constrained Language mode
I have a strange issue and wonder if anyone has any ideas. I am trying to make a powershell script that can replace text in a word document.
This script works fine on version 5 but not on version 7
...
2
votes
1
answer
138
views
Why is `Install-Module` not respecting $ErrorActionPreference=Stop from the script scope?
I have the following script:
$ErrorActionPreference = "Stop"
Install-Module 'DoesNotExist' -Force
Write-Host "This should not be printed!"
I'd assumed, that if an error occurs in ...
2
votes
1
answer
1k
views
Any way to remap ls from Get-ChildItem to another command in PowerShell?
Trying to replace the default PowerShell Get-ChildItem command (mapped to ls by default in PowerShell 7) with eza, however I cannot seem to find anything on how to do so
Using New-Alias results in ...
1
vote
1
answer
763
views
Invoke-WebRequest 'ftp' scheme not supported (Powershell >7.0+)
I am trying to download a file from ftp but Invoke-WebRequest is not working. Since wget is not available on Powershell, I have to resort to use Invoke-WebRequest but I encountered this error:
Invoke-...
0
votes
1
answer
223
views
Managing Windows Services with Remote powershell - Windows Server 2019 Datacenter Edition
I want to remotely stop / start / restart SQlBrowser service from a .net core 6 application running on IIS that uses the Powershell 7 library.
The application pool of the .net core service runs under ...
0
votes
1
answer
235
views
Migration from PowerShell 5 to 7: can't load types from System.ServiceModel.Web v4.0.0.0
Recently transitioned from PowerShell 5.1 to 7.3.6. Most scripts are fine, but there is one puzzling issue with a script calling a .NET class.
The class can't load, crashing with this message:
System....
0
votes
0
answers
232
views
Can't import PS5 module into PS7
I've tried this on a few systems so I think it's something with the module itself, but I'm not sure what to look for.
Code
Import-Module PSWriteHtml -UseWindowsPowerShell -WarningAction Ignore
Error
...
1
vote
1
answer
233
views
Can I pass parameters while calling PS7 from PS?
I have a module that was written in PS5, and I'm adding a new function that requires PS7. I want to be able to run the function from PS5, so I'm thinking I can just have the function call pwsh, but I ...
1
vote
1
answer
130
views
Why can't I store my object in a variable within a Parallel ForEach-Object loop?
I'm trying to retrieve the AD property LastLogon from each of our domain controllers, for each user. Due to the amount of time this will take, I'm trying to use the Parallel feature from PowerShell 7
...
0
votes
1
answer
93
views
Is there a way to make VBA as a standard open PowerShell 7.3.6.0?
Running the following VBA code opens PowerShell v1, and computes size remaining on DriveLetter C.
Sub RunPowershell()
Set wShell = CreateObject("WScript.Shell")
Set wShellResult = ...
3
votes
1
answer
168
views
Powershell PSReadLine : Get Key's for a given Function?
In PSReadLine 2.2.2 for PowerShell 7.2.11, On Windows, you can also use the Alt+? key chord to show the function bound to the next key chord you enter.
Conversely, is there a key or PS command that ...
3
votes
0
answers
1k
views
Error when running application with PowerShell version 7: "Get-ExecutionPolicy" command not found
Description:
I encountered an error while running my application with PowerShell version 7. The error message states:
Get-ExecutionPolicy: The 'Get-ExecutionPolicy' command was found in the module '...
1
vote
1
answer
341
views
Unable to use .Net class via the Add-Type cmdLet in PowerShell 7
I have a PowerShell script that listens for a key to be pressed before exiting. I accomplish this using a custom TypeDefinition; here's the code:
param(
[string]$quitKey = "F16"
)
$...
1
vote
3
answers
2k
views
SmbShare: the module could not be loaded
The Problem:
I have inherited a PS script file that deletes a directory. In case there are any locks on it, it removes them using this line:
Get-SmbOpenFile | Where-Object -Property Path -Like "$(...
0
votes
1
answer
194
views
How to parse a table in TXT
I have a bunch of Log files (saved as .txt) that contain a 'table' at the end of each log that I need to parse.
What do I mean by 'table'?
Total Copied Skipped Mismatch FAILED ...
0
votes
1
answer
253
views
Using ForEach-Object -Parallel on multiple Servers with Get-NetFirewallRule
I am writing a code which is checking the firewall rules from multiple servers. Since we have alot servers here, i want to run my Script parallel on these servers. My script is kind of working. I get ...
0
votes
0
answers
438
views
Powershell transcript for powershell 7
I've migrated to powershell 7 recently, but I can't make the powershell transcription working for powershell 7. (Legacy powershell transcription works fine though.)
The registry is this:
Computer\...
1
vote
2
answers
1k
views
PowerShell 7 Cmdlets not recognized when using AWS SSM Automation document script
Trying to figure out why 3 powershell cmdlets are not working when using AWS SM Automation inputs Script, but they do work when running them in a local script directly on my Windows instances.
The ...
-1
votes
1
answer
1k
views
how to pass mutiple parameters from YAML to Powershell Function
I have to invoke POST METHOD from powershell function which is having 8-9 parameters and these parameter may contain big strings.
I am calling powershell function from Azure DevOps Yaml based ...
2
votes
1
answer
71
views
Why do process blocks correctly return a hashtable, instead of an array of hashtables?
I am trying to sort some REST API responses and extract data from them, and found this helpful answer on how to end up with a hashtable at the end.
$res= (Invoke-RestMethod @commonParams -uri "...
2
votes
2
answers
140
views
Set a PSObject path using an array for the "dot" variable names
I have a PSObject that I have filled with a json structure. I need to be able to set the value of one of the entries in the tree using an array that has the names nodes of the json path. Here is an ...
7
votes
2
answers
3k
views
Service 'McpManagementService (McpManagementService)' cannot be queried due to the following error:
I am trying to run this in PowerShell7
PS C:\Users\MYUSER> $myoutput = get-service| where-Object Status -eq "Stopped"| select-Object Name, Status
However, I am getting the below error:
...
0
votes
0
answers
621
views
Get-MgUserCalendar only works if I have delegate permissions in O365
When calling Get-MgUserCalendar I get an error "The specified object was not found in the store." unless I have given myself delegate permissions on that person's mailbox. I am a global ...
0
votes
1
answer
3k
views
How to interact with Azure AD B2C custom User Attributes via Microsoft Graph PowerShell SDK?
I have added a custom User Attribute named Company Name via:
Azure AD B2C > User attributes
so that this information can be returned in the identity token after successful sign in.
I want to update ...
0
votes
0
answers
330
views
Why does the IndexOf() method give me an error when the documentation states that it should work?
I'm looking to parse out a specific blob of text to a different file. However, I'm having an issue with the .IndexOf() method when trying to define my endIndex.
The string I'm looking for will start ...
1
vote
1
answer
618
views
VSCode breaks my powerShell associations once a ps1 file is opened with that editor
I have a strange problem with Visual Studio code related to selecting the default Powershell version: I have installed Powershell 5.1 and 7 parallely, but when I doubleclick on a ps1-file, it should ...
0
votes
1
answer
182
views
PowerShell 5 (now updated to 7) - Check if multiple levels / depths of subfolders exists and if so move its contents up one level
Normally I wouldn't even post without some framework together, but I'm stumped on where to begin.
I have a directory of hundreds of subfolders that should only be one level deep but some are two ...
0
votes
1
answer
131
views
ForEach -parallel processing sorted data
I am trying to process a bunch of files (hash them) from a Directory in parallel, but need the results to keep the order the inputs have.
Get-ChildItem -Recurse -Force -File `
| Sort-Object -Property '...
0
votes
1
answer
798
views
How to prompt for UAC in PowerShell 7 and save the entered password as variable?
I have a simple script to create a scheduled task like this:
$action = New-ScheduledTaskAction -Execute "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -Argument '-file "...
0
votes
1
answer
547
views
Get-MessageTrace producing inconsistent results
I have a powershell script running the following line of code:
$results = Get-MessageTrace -SenderAddress $senderEmail -StartDate $daysAgo -EndDate $todayDate
A new employee tries to run this and ...
2
votes
2
answers
4k
views
How to fix Nuget Provider "Find-Module" Installation error with PowerShell 7.3?
I've been trying to run a PowerShell script, and upon doing so, I receive a message that NuGet Provider is required.
NuGet provider is required to continue
This version of PowerShellGet requires ...
0
votes
0
answers
71
views
get-help does not work in PS5 but does work in PS7
I'm working on some PowerShell code that used to work and has broken. I noticed in PS5 when I run get-help against the below help section I receive:
Get-Help : Get-Help could not find C:\PATH\program....
1
vote
1
answer
7k
views
WARNING: Unable to find module repositories. "Get-PSRepository" ubuntu20.04
I was trying to install Az-Module in my Ubuntu power-shell, But It wasn't installing than I double checked the PSRepository and I came to know that I don't have any repository there.
I also have tried ...
0
votes
1
answer
1k
views
PowerShell 7 Remoting from Azure DevOps Pipeline
We were using Azure DevOps Pipelines and PowerShell Remoting to execute PS1 scripts:
trigger: none
jobs:
- job: PSRemoting
timeoutInMinutes: 5760
pool:
name: 'DevOps-Agent2-VM'
...