Questions tagged [powershell]
PowerShell is a cross-platform command line and scripting utility from Microsoft. Use this tag for questions about writing and executing PowerShell scripts ONLY. Programming questions specific to the cross-platform version PowerShell Core (Windows, macOS, and Linux) should be tagged [powershell-core]. Questions about system administration should be asked on Super User or Server Fault.
powershell
118,092
questions
0
votes
1
answer
16
views
How to prevent the message "File open in another application" when creating excel instance
I was running a PowerShell script perfectly fine earlier, but for some reason this message popped up that's saying the file is open in another application. I have checked task manager and the excel ...
0
votes
0
answers
13
views
PS: Redirecting error output of assignment statement to a variable
I am calling PnP-GetWeb like this:
[Microsoft.SharePoint.Client.SecurableObject]$Web = Get-PnPWeb -Connection $pnpConnection -ErrorAction SilentlyContinue
if($null -eq $web) {
throw &...
0
votes
0
answers
6
views
Is it possible to run Connect-IPPSSession, Connect-ExchangeOnline using pwsh on a linux server?
I am trying to use the Powershell ExchangeOnlineManagement module, but I have to perform some automations on a Linux RedHat server and I would like to know if it is possible to execute commands like ...
1
vote
1
answer
17
views
Yarn PM not working in Windows when the User folder(UserProfile env var) has space in folder name or path
As stated in title, the Yarn PM(package manager), that I just installed in my system(Windows 11 64Bit) doesn't work if there's space(s) in my UserProfile folder path.
My User folder name is "...
-2
votes
2
answers
36
views
Is there a way to checkout latest version of origin branch without warnings [closed]
I wrote a powershell script to obtain git submodule and set his branch. It will run from pipeline and branch name will be passed from launch form input.
Param(
[Parameter(Mandatory=$false)]
[...
0
votes
0
answers
29
views
az cosmosdb update --ip-range-filter parameter either from file or powershell pipe
The az cosmosdb update command that I am using has exceeded length of 8192 characters so I am receiving "The command line is too long." error, the command itself looks following:
az cosmosdb ...
0
votes
1
answer
20
views
Failed to update help in windows powershell
I am an absolute beginner to Command Line Interface and noticed this when trying to update the help (I'm following Learn Enough Command Line to Be Dangerous, which I suppose is for Linux and I am ...
1
vote
2
answers
49
views
Place every item from a text file into an array but detect headers/titles
I have text files that contain
Firstname: xxx
Lastname: yyy
Login: abcd
It has many others entries for other definitions but all in the same format header: data
I would like to use an array in ...
1
vote
2
answers
36
views
Powershell : Cannot convert the "java" value of type "System.String" to type "System.Management.Automation.ScriptBlock"
I have a powershell script which converts the String and String[] into a BlockScript. It was working until now but it starts to fail suddenly after some windows upgrade.
function Invoke-...
0
votes
2
answers
51
views
How to make PowerShell `Select-String` aka `sls` output exact match(es) only?
In a PowerShell script, I would like to check if a branch exists locally already, which I'm currently doing as $existsInLocal = (git branch | sls $branch) -ne $null, but that's incorrect because sls $...
0
votes
0
answers
35
views
ps1 file wont run unless I change the encoding or add any character into the script
This is a weird issue, the scripts are coming from Intune deployed from patch my PC. On some devices when i try run these scripts they just hang and eventually timeout. If i convert the file to UTF-8-...
0
votes
1
answer
50
views
PowerShell StandardOutput Redirect Issue
I am trying to use ghostscript to get the number of pages in a PDF. I am getting this error:
Select-Object : Exception getting "StandardOutput": "StandardOut has not been redirected or ...
-1
votes
1
answer
32
views
How do I write a powershell function to send a warning if files don't exist?
I am new to powershell scripting and I am trying to create a function that sends a warning to my email if a list of files do not exist in my C: drive folder. The list of files I am looking for are:
...
0
votes
0
answers
10
views
401 (Unauthorized) Request Id when calling Get-DataGatewayCluster with a service principal
Currently trying to use a service principal in order to check power BI connection status
Connect-DataGatewayServiceAccount -ApplicationId $xx -ClientSecret $xx -Tenant "xx"
$scopeLevel = &...
0
votes
1
answer
40
views
Powershell - format info to csv
Trying to query non-windows native program (dell racadm) info and format string into csv file with other info. Everything works until I get to the iDracIP and it returns blank in the csv file. I ...
-1
votes
0
answers
22
views
How to pass docker commands through Powershell
Everyday i have to restart docker containers everyday. Don't ask. So i want to make Powershell script that connects through SSH to server with docker and then restarts all containers. So right now my ...
2
votes
1
answer
33
views
Winget ls shortening ids
I'm not sure if this is a winget question or a PowerShell question. Basically, winget ls output is too wide for the shell window, so it cuts off the column with ellipses. I tried ooutputing to a file ...
0
votes
1
answer
50
views
Powershell if function calling another function
I have 2 functions when I call the second function from the first one, always returns true doesn't matter if the second function has false return:
function IsPodRunning($podName) {
Write-Output &...
1
vote
3
answers
48
views
Powershell: add new line after every line that contains a given string
I have a >7000 line XML file, which I define as $File, and which contains (scattered throughout all the other lines) four lines exactly as follows:
<text:p text:style-name="P27">&...
-3
votes
0
answers
60
views
Cannot Download latest version of Chrome driver v126 or most latest via powershell command [closed]
Please correct my script if necessary: and please understand that I am new on this.
Script
# Define the destination folder
$destinationFolder = "C:\Users\123\Downloads"
# Create the ...
0
votes
1
answer
40
views
PowerShell: get data from a System.Collections.Generic.list [closed]
I'm struggling to get data from a generic list object in powershell.
This is the output of my list object and I am trying to get the name value.
{@{[email protected]; id=3; loginName=i:0#.f|...
0
votes
2
answers
29
views
Start a process in Jenkins without waiting for its end
I'm able to start a process in my Jenkins pipeline easily, but I'm struggling to avoid being blocked by the process.
Currently, Jenkins is waiting for its end before going on to the next step, but I ...
0
votes
0
answers
40
views
How to launch an application in the second desktop using PowerShell cmdlet
I need to run a PowerShell script using PowerShell or some other means in another desktop without switching back and forth across desktops. I could not find any cmdlet or other way to accomplish this. ...
0
votes
0
answers
18
views
How to add a reg file into Intune App Packager using Powershell?
Can anyone advise me on how I can add the below REG file to an MSI I wish to package on Intune using IntuneWinAppUtil? I understand that Powershell could be utilised, but I have never used it before ...
0
votes
0
answers
14
views
Changing User Rights Assingments From A Powershell Script [duplicate]
I am currently working on a project to make a script to get any computer CIS compliant up to IG3 level. Part of this includes changing the User Rights Assignments to only Admins or remote desktop ...
0
votes
1
answer
52
views
Azure DevOps AWS CLI with Powershell
I have a AWSShellScript task that executed a powershell script - example below trimmed for this post.
-task: AWSShellScript@1
inputs:
scriptType: inline
inlineScript: 'pwsh -File test-script....
0
votes
1
answer
25
views
Power Shell script to automate need to install modules
Load required assemblies
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
function Show-MessageBox {
param (
[string]$message,
[string]$title
)
[System....
-1
votes
0
answers
18
views
Automatically upload OneDrive files on log off/reboot
I am trying to set up automatic uploading of downloaded files to a user's OneDrive directory, at logout. When running my script at logout the OneDrive processes are already completed, I edit the ...
1
vote
1
answer
39
views
Prevent system shutdown while task scheduler task is running
How can I create a task in Windows task scheduler that prevents (automatic) system reboots while it is running? I want the task to finish before any restarts are performed.
Note: I'm aware that one ...
0
votes
1
answer
45
views
Powershell: replace every line that contains a given string
Suppose I have a text file that contains the following lines:
Apple
Bananas
Fruit things
Oranges
Fruit pieces
I want to replace every line that contains the string "Fruit" with a new line ...