close
Skip to main content

New answers tagged

Score of 0

How to create a JSON object with array in Powershell

If anyone else comes along this way, this helped with me, I struggled to get them nested in my logging: from: function logto-file ($message) { $date = get-date -Format 'dd-MM-yyyyTHH:mm:ss' $...
Score of 0

PowerShell inconsistency?

Let me complement Santiago's helpful answer with a systematic summary: In PowerShell, objects can have properties (more generally: members) from 3 distinct sources: (a) .NET type-native (public) ...
Score of 0
Accepted

Git clone over SSH hangs in WSL2 at expecting SSH2_MSG_KEX_ECDH_REPLY

It stalls at SSH2_MSG_KEX_ECDH_REPLY because that is the first large inbound packet, carrying the host key and signature. PowerShell works because the Windows stack has black hole detection. HTTPS ...
Score of 1

Detect whether PowerShell scripts can be executed from Windows Batch

Constructing the logic in PowerShell If we can do it inside a PowerShell window, we can do this: if ((Get-ExecutionPolicy) -eq 'RemoteSigned') { C:\Users\username\file.ps1 } else { Write-Host '...
Score of 9
Accepted

Detect whether PowerShell scripts can be executed from Windows Batch

You can check it, but you probably shouldn't need to. The powershell.exe command line accepts an -ExecutionPolicy parameter that overrides the policy for that process only, without changing machine ...
Score of 2

Detect whether PowerShell scripts can be executed from Windows Batch

The Get-ExecutionPolicy commandlet in PowerShell gives you something to test, and all you need is a quick shim to invoke PowerShell and execute that commandlet from your batch script: powershell -...
Score of 4
Accepted

PowerShell inconsistency?

First, note the comment about Count and Length properties in intrinsic members: Not all scalar type have Count or Length properties in the base type. PowerShell adds the missing property as an ...
Score of 0

Capture program stdout and stderr to separate variables

Since PowerShell 7.6 one can use PSRedirectToVariable feature, for example: dir ~, invalid_path 1>variable:stdout 2>variable:stderr $stdout $stderr
Score of -1

Exchange 2016 CLI does not accept Pipeline command of moving all arbitration mailboxes

Get-Mailbox -Database "Mailbox Database 1440273088" -Arbitration | Foreach-Object { New-MoveRequest -TargetDatabase "MDB3" -Identity "$($_.Name)"}
Score of 0

PowerShell - Password Generator - How to always include number in string?

This short PowerShell script generates a cryptographically random pa$$word guaranteed to meet these common pw requirements: Length (total number of chars) One uppercase character One lowercase ...
Score of 2

What is the equivalent Cmd.exe program for this PowerShell one-liner program?

You can invoke a line of powershell from cmd. I do this often. You just have to manage the quoting. Cmd only knows double quotes, and the pipe has to be escaped with the rest within double quotes. ...
Score of 0

Invoke-Expression with exe in Program Files

I found that PowerShell has a problem mit the -xr!*.bak parameter - it inserts a blank. So I had to use an argument array. To be platform independant (\ or /), I use Join-Path. -mx=9 is here for ultra ...
Score of 0

Running a script on a virtual machine using Invoke-Command

You will likely need to escape the $using:... with (...) or $(...) within an expandable string - "..." So that $signcheck_output = ./$using:sign_check_tool /accepteula -c $using:arguments ...
Score of 7
Accepted

What is the equivalent Cmd.exe program for this PowerShell one-liner program?

Dissect the following PowerShell command: Get-ChildItem -Path E:\input\* -Include *.xml | foreach { $html="E:\output\"+$_.basename+".html"; .\program $_.fullname $html} Get-...
Score of 3

Confusion about pipe ("|") character in an environment variable in different Windows CLI tools

This has to do with how cmd.exe interprets commands. From the set command documentation has a good summary: The characters <, >, |, &, and ^ are special command shell characters, and they ...
Score of 0

cannot be loaded because running scripts is disabled on this system when installing angular

Run this command in your powershell or cli Set-ExecutionPolicy -Scope CurrentUser RemoteSigned
Score of 4
Accepted

How can I connect to MgGraphs and Exchange Online in the same PowerShell session?

Very possible that the cause is an assembly conflict between Graph and Exchange Online modules and either one implements an assembly load context... what you can try is updating both modules to their ...
Score of 0

Adding members to local groups by SID in multiple languages

A bit late to the party but useful nevertheless :) Placeholders: <user>, <desc>, <fullname> A PowerShell command that adds a existing user to the local administrators group: Add-...
Score of 0

How can I see the command history across all PowerShell sessions in Windows Server 2016?

This is the solution that got me as close as pssible to a persistent history list with ! type functionality. Test if you have a $PROFILE: Test-Path $PROFILE If False, create $PROFILE: New-Item -...
Score of 0

How do I create an index pattern in OpenSearch using the API?

I'm not sure when the requirement was enforced, but in OpenSearch 3.7, you must include attributes.fields when creating an index pattern, or else if you later create a saved search using that index ...
Score of 3

Using PS, export users in the AD groups that have certain prefix and suffix

You can use Get-ADGroup to get the relevant groups and pass them to Get-ADGroupMember eg : Get-ADGroup -Filter "Name -like 'prtr*'" | Get-ADGroupMember * is a wildcard which means anything ...
Score of 0

PowerShell C# PrintWindow() output not working

Since the code in the question is not working, I had to follow all the comments to get it fixed. Besides just making it work without errors, I've also made some minor improvements: Renamed the class ...
Score of 3
Accepted

PowerShell .ForEach() method

What you're seeing is a bug in Windows PowerShell (the legacy, ships-with-Windows, Windows-only edition of PowerShell whose latest and final version is 5.1) that has since been corrected in PowerShell ...
Score of 0

Why does `QueryServiceConfig2` return a "The parameter is incorrect" error when requesting a service's preferred node?

The error is more of a Microsoft bug. After creating the SCM and opening a service: SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT); SC_HANDLE hService = OpenService(...
Score of 0

Error calling PutEx with a filtered array

Old, but it may help some: As the OP noted, this code works : $values = @("xyz", "abc" ) $user = [adsi]"LDAP://CN=someone,CN=Users,DC=acme,DC=com" $user.PutEx(3, "...

Top 50 recent answers are included