119,260 questions
0
votes
0
answers
18
views
Trouble accessing a single element of an array in Powershell
I am attempting to use a single element of an array, when creating a string message, but it is using both elements, concatenated by a space, whether I use $myArray[0] or $myArray[1]...
# Multiple ...
1
vote
1
answer
76
views
How save specific strings and then put next to lines?
I'm parsing a file using powershell 5.1 and I almost get my goal but I need help in this part. The input file is like this:
CODE=MMH4
description=beg somedata - dduik
CODE=PPH2
description=beg Area1 -...
0
votes
0
answers
30
views
How to replace string by new line in Powershell 5 [duplicate]
I have a file with some strings like below for which I want to replace the || with newline using powershell 5.1.
This is || some test || string
I've follow some advices in this thread and I'm trying ...
2
votes
2
answers
72
views
Verbose in class with "using module" directive
I faced a specific behavior while using verbose output in class.
This works like a charm:
# SomeModule.psm1
class SomeClass {
SomeClass() {
Write-Verbose "It works!"
}
}
...
-1
votes
0
answers
59
views
An ad_group_membership resource(hashicorp/ad) get error The command line is too long
I have a code which map users to group via a resource ad_group_membership from terraform provider hashicorp/ad
locals {
# --- Загружаем все YAML-файлы ---
yaml_be = yamldecode(file(var....
1
vote
1
answer
154
views
If statement with [string]::IsNullOrEmpty() always runs even if output is not null
$qusertest = quser | Out-String
if ([string]::IsNullOrEmpty($qusertest)){
Restart-Computer -Force
} else {
Write-Output $qusertest; exit 0
}
I am testing out code to automatically reboot ...
1
vote
1
answer
94
views
Powershell copy-item replaced a directory with a file
I'm using a command similar to the one below to copy a file to a directory:
copy-item 'C:\\some\\source\\directory\filename.txt' -Destination 'T:\some\destination\dir'
C:\ is a local disk. T:\ is a ...
2
votes
1
answer
114
views
How to delete Recycle Bin files older than 30 days for all users (running as SYSTEM from RMM)?
I'm building an script in PowerShell that runs via an RMM tool, so it executes in the SYSTEM context. The goal is to automatically delete files from the Recycle Bin that are older than 30 days, for ...
Advice
0
votes
5
replies
93
views
access module variables from outside of the module
I'm currently writing a helper module and despite my efforts, some private variable have to be accessed read/write from outside the module.
my first attempt was using Export-ModuleMember -Variable but ...
4
votes
2
answers
173
views
Illegal coercion operation producing inconsistent error/exception behavior depending on scope
Consider this example, a script named test.ps1
function MyTestFunction
{
[CmdletBinding()]
param ()
try
{
[bool]$functionBool= $null
}
catch {throw $_}
Get-...
0
votes
1
answer
508
views
Scripted installation of the PowerShell Active Directory (ActiveDirectory) module on Windows 11
In my PowerShell scripts I'm using the ActiveDirectory module, which contains the various *-AD* cmdlets such as Get-ADUser.
How can I automate (script) the installation of the PowerShell ...
0
votes
1
answer
58
views
Find and replace in Word doc with special characters
I'm trying to add commands to a powershell script that finds a username and password test and replaces them with the user's name and password. The issue that I'm running into is with special ...
2
votes
0
answers
77
views
How do I send arguments to application in windows launched with shell:appsFolder?
I know you can use the Get-AppxPackage and Get-AppxPackageManifest cmdlets in Powershell to get the package family and it's specific application entry point.
In this example with Windows Media Player ...
3
votes
2
answers
99
views
In Powershell, error when calling Azure Log Analytics query containing 'extend'
With the below KQL query, I'm extracting accesses to Azure Key Vault secrets and keys in log analytics, by extracting name of the Key Vault resource (kv) and its accessed keys and secrets (sec) from '...
3
votes
2
answers
159
views
Cannot get command line code to run via python
I am running python 3.13.5 via PowerShell in windows 10. I can successfully run the folowing command, and now want to run it with a python script
& 'D:\realesrgan\realesrgan-ncnn-vulkan.exe' -i 'D:...
2
votes
2
answers
119
views
Problem when running Docker container inside Powershell script [duplicate]
Environment
Windows 11 23H2
Powershell v5.1
Docker desktop 4.49.0
Issue
I have a weird problem when I use variables as arguments for a docker run command inside a Powershell script (.ps1 file).
If ...
1
vote
0
answers
53
views
Delete DHCP-Reservation via Python Script
I want to delete DHCP Reservations using a Python script and have the following code:
import tkinter as tk
from tkinter import messagebox
import subprocess
def delete_reservation():
dhcp_server = ...
3
votes
2
answers
108
views
How do I Download Poppler and Tesseract Programmatically with PowerShell
In Python, there are two libraries which are often used in tandem, Poppler and Tesseract. They both need external downloads to function:
Poppler, Tesseract. The general recommendation for Windows is ...
2
votes
2
answers
130
views
Kotlin script - can't run if full path contains space [closed]
Kotlin compiler is located in C:\kotlinc\bin, when trying to run any script that is located in a path with space - it fails with message
InvalidPathException: Illegal char <:> at index 2: /H:/My%...
2
votes
2
answers
99
views
powershell compress-archive verbose output to text file
I have a powershell command that I want to execute and direct the verbose output to a text file.
Compress-Archive -Path $currentLogDir_TempPathString -DestinationPath $currentLogDir_ArchiveFileName -...
0
votes
2
answers
116
views
Windows 11 powershell run executable with parameter switches when IF statement false
Windows 11 Power shell
I'm trying to run the following IF statement in power shell - basically to check if a file exists on encrypted drive P, if it doesn't then create the encrypted drive. I get an ...
Advice
1
vote
1
replies
97
views
How to open the Developer PowerShell for x64/amd64?
The start menu features a Developer PowerShell for VS 2022 which defaults to x86:
PS C:\> (Get-Command link.exe).Source
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14....
1
vote
0
answers
86
views
Invoke-WebRequest URL encoding
I want to retrieve content from web page. However, I tried above method but the error still come when the query string contain Chinese character.
code
$json = Get-Content -Encoding utf8 -Path "./...
0
votes
1
answer
78
views
C# Compress-Archive not storing full folder names
I have a log folder structure that's similar to this:
D:\
+ Logs
+ Prod
+ API1.domain.com
+ Server1.domain.com
+ Server2.domain.com
+ API2.domain.com
+ Server1.domain.com
...
5
votes
1
answer
92
views
How get Powershell v7.5 to expand $env from command line like v5.1
Passing an environment variable from command line works differently in Powershell v7.5 compared to v5.1. Is there some overall setting for PS 7.5 to provide compatibility? Or an explanation of why ...
2
votes
3
answers
119
views
Is it possible to state an object's property from a string in Powershell? [duplicate]
I have:
$method = "property.childproperty"
How can I get to $foo = $object.property.childproperty by using the $method variable?
0
votes
0
answers
71
views
error: Package is incompatible with 'all' frameworks in project when package does not already exist in C:\<USER>\.nuget\packages
I have a powershell script calling dotnet add
Script:
dotnet add `"$projectFilePath`" package "$packageName" --source "$dorsetIcsSourceName" --version "$...
1
vote
0
answers
112
views
Azure DevOps Pipeline YAML file - How To Access (upstream) Pipeline Resource Completion Time in downstream pipeline?
How to get the completion time of a stage in my upstream pipeline?
I read in the documentation that I can use resources.pipeline.<alias>.xyz, but I don't see any predefined variables that allow ...
-2
votes
2
answers
172
views
String not recognized as a valid DateTime
I'm receiving this date and time in US format from an upstream server I have no control over and can't change: 12/16/2024 11:30:23 AM
I am trying to convert it to UK format using PowerShell:
[DateTime]...
Advice
0
votes
1
replies
71
views
Local groups and members using Powershell (Get-WMIobject)
I am trying to replicate a combination of WMI and ADSI, to use just WMI. This is a quick fix whilst we put a case forward for winRM as a replacement. This is something that is new to me, so please ...
Advice
1
vote
7
replies
102
views
Build string from
I have array of strings
$Emails = '[email protected]','[email protected]','[email protected]'
This array can contain from 1 to unlimited numbers of elements.
And I need to build a filter string from ...
1
vote
1
answer
96
views
Powershell string split confusion on result
While using .split, if the string contains just "/" (root) and the delimiter is also "/" - the count of the string split is 2, though would have expected 0
Why is this the result?
...
4
votes
1
answer
78
views
WinSCP PowerShell script with mask downloads files but creates empty folders
I am using a PowerShell script using the module WinSCP to download files from a SFTP server.
I am using a file mask so I only download files matching *.zip which have been added today. The SFTP folder ...
0
votes
1
answer
70
views
RBAC role to restore service principal
I am in the process of building a custom RBAC role, only to delete & restore the App registration and service principals. I can manage delete actions and restore the App registration, but I don't ...
2
votes
0
answers
115
views
#NAME? error when opening an Excel sheet via Powershell
I am trying to export Excel files to PDF. Since there are a lot of Excel files to be exported I'm trying to automate this via PowerShell. In principle this works fine, but some Excel files contain ...
0
votes
0
answers
32
views
DSCv3 Json configuration with SqlServerDsc/SqlPermission failed
I try to implement a SQL automated installation of SQL Server. Currently I hang with SqlServerDsc/SqlPermission. I use a block in my json:
{
"type": "SqlServerDsc/SqlPermission"...
0
votes
1
answer
72
views
Creating an Azure DevOps User Story with Powershell
I'm looping through an Azure DevOps query script to essentially create copies of work items into a new iteration. The problem I'm having is with the final Invoke-RestMethod call at the end of the ...
Tooling
1
vote
5
replies
171
views
Transferring basic Powershell scripts to a full secure windows program
I reviewed many suggestions posted, but didn't find an exact match. I've created PS scripts where there is one parent script that runs its functions and then calls upon 25 other subscripts in sequence ...
2
votes
2
answers
187
views
how to get PowerShell to gracefully accept a multi line, array, system.object input to a `[string]` parameter?
ff
I have a function foo, it needs to accept a string, this string can be passed to it directly by typing at the terminal, from a variable or from the clipboard.
function foo{
[CmdletBinding()]
...
1
vote
1
answer
119
views
Activate PIM Entra ID role with Azure CLI or PowerShell [closed]
I'm trying to automate the activation of my PIM Entra ID role for Azure Tenant with either Azure CLI or PowerShell.
I've followed the answers in Activate PIM role for Azure resources via REST / ...
2
votes
0
answers
74
views
GitHub Copilot in VS Code triggers a KeyboardInterrupt error when opening PowerShell with conda environment [closed]
I'm encountering an issue when using GitHub Copilot in VS Code.
After Copilot agent modifies a file, it suggests a PowerShell command and asks whether I want it to run the command for me. When I click ...
Best practices
1
vote
6
replies
152
views
PowerShell: syntax sugar to combine parent and child attributes in pipe
I'm building a report about SMART metrics (SSD storage wear status):
Get-PhysicalDisk | %{
$s = $_ | Get-StorageReliabilityCounter;
[PSCustomObject]@{
Model = $_.Model;
...
1
vote
1
answer
84
views
Use value saved in variable as command line argument [duplicate]
How to fix this so that option /FI is detected correctly?
This is just an example.
$myfilter="foo"
$myargs="/FI $myfilter"
tasklist $myargs
ERROR: Invalid argument/option - '/FI ...
3
votes
2
answers
143
views
How to Use Virtual-Key Code Constants in Powershell?
In a Powershell script, Mute is performed with:
(New-Object -ComObject WScript.Shell).SendKeys([char]173)
That works.
Windows reference lists constants for each key. Mute constant is VK_VOLUME_MUTE.
...
0
votes
0
answers
59
views
Powershell script to replace a single carriage return [duplicate]
I am importing a web order CSV file into our in-house database. Usually it's ok but, if the user enters special delivery instructions, the csv file includes the string "help.", followed by ...
2
votes
1
answer
65
views
Azure DevOps “File Path” PowerShell task fails with “MissingEndCurlyBrace” but script parses and runs fine locally and as inline steps
Environment
Azure DevOps Classic UI
Task: PowerShell@2 (Windows PowerShell, not pwsh)
Agent: Windows (Microsoft-hosted and self-hosted both repro)
PowerShell version: Windows PowerShell 5.1
Script ...
3
votes
1
answer
120
views
PowerShell Script: When the Ethernet Port status changes why doesn't the status report show the actual port status?
I am an occasional casual programmer (for about 60 years now!). I wrote 2 functional SNMP PowerShell desktop shortcut scripts 4 years ago. Now I am writing two scripts for my old Windows 10 system: ...
4
votes
2
answers
132
views
sqlite3 shell on Windows : extra carriage returns when using output redirection
Demonstrate the issue
Let's use nvim to create a text file:
> nvim C:\temp\in-file.txt
The contents of the text file:
> Get-Content C:\temp\in-file.txt
abc
bcd
cde
Now let's create a simple ...
4
votes
2
answers
129
views
How to suppress all output in Teams PowerShell module
I am using the Teams PowerShell Module 7.3.1 on PowerShell Core 7.5.3 to pause a provisioning script until a newly created user becomes available in the Microsoft Teams PowerShell module, as follows:
...
1
vote
3
answers
245
views
How to convert a batch to Powershell parallel processing to run over thousands of input files?
I have a large number of files (about 3800) that I want to run a program over. The program reads a WAV file and makes a short .TSV text file containing the WAV's lip-sync data (but that is by-the-by ...