Questions tagged [powershell]

PowerShell, created by Microsoft, is a versatile command line and scripting tool that works across different platforms. This tag should be used solely for inquiries relating to writing and running PowerShell scripts. If you have programming questions related to the cross-platform version called PowerShell Core (compatible with Windows, macOS, and Linux), make sure to use the [powershell-core] tag instead. For inquiries regarding system administration, it is recommended to seek help on Newtab Q&A or Newtab Q&A.

Utilizing Powershell to transform every line in a text file into JSON structure

I have a file named output.txt that contains the following data: device:VM01,partition:"C",size_gb:100 device:VM02,partition:"D",size_gb:200 device:VM03,partition:"E",size_gb:150 When I read each line and use ConvertTo-Json, I expect the result to be: [ { ...

Exploring the Potential of Powershell, JSON, and Hashtables

Looking for Help [ { "example": "abc123", "exampleName": "abcd_test", "exampleShortcode": "", "isComplete": false }, { "example": "def456", ...

What could be causing my PowerShell to be undefined when running npm run dev?

I am currently working on a Vue project using Vite in Windows 11. Whenever I try to run "npm run dev" with PowerShell (which is vite --open --host), I encounter the following error:https://i.stack.imgur.com/LPSc0.png It seems like the path is showing as & ...

What is the best way to display the information stored in a nested JSON hash table onto a PowerShell output?

Is there a way to output all the contents of a nested JSON hash table in PowerShell in a single line? $json = @" { "outer": "value1", "outerArray": [ "value2", "value3" ], "outerHash": { "inner": "value4", " ...

Stopping the server in VSCode after closing the terminal window

When working with full-stack development in VS Code, it's common to accidentally leave the server running without stopping the batch process. This can lead to issues like encountering the error message Port XXXX is already in use when trying to run up ...

How can I generate a sorted array of objects in a JSON output using PowerShell?

Is it possible to generate a JSON output with an array of objects sorted in ascending order based on the "count" property? I need to maintain the original $result object structure, without caring about the order of "Good" or "Bad", My goal is to sort the o ...

Exploring JSON Data with PowerShell

Struggling to make my code work despite looking at numerous examples. The JSON structure appears unique and I need to extract "id" and "legalName" from the results. [ "URL: https://myurl.com/rest/api", { "value": [ ...

Can Selenium C# tests retrieve a parameter from a batch or PowerShell script?

My Selenium tests navigate to a specified URL using the code: driver.Navigate().GoToUrl("www.blahwhatever.com"); Currently, I am able to execute these Selenium tests using either a batch file or PowerShell script. Ideally, these scripts would be triggered ...

Having problems with utilizing the yo (yoeman-generator)

I searched extensively online but was unable to determine the root cause of the error. I attempted adjusting the path variable as a potential solution. Could someone please provide guidance on how to resolve this issue: To install yo, I used the command: ...

Update NPM automatically in Bash/GitBash only when a newer version is detected

Is there a way to automatically check for the availability of a new stable version of NPM online without manually opening a browser? If a newer version is found and it's greater than what I currently have installed globally, then I want to run the command ...

Leveraging PowerShell to run a script on a remote machine that triggers a batch file

Having trouble running a batch file on a remote server to execute an automated Selenium test On a remote server, there is a batch file named mybatch.bat that triggers a Selenium test. Below is the code snippet in a Powershell script on the same server: $ ...

What command in PowerShell can be used to determine the version of chromedriver.exe?

While working on a PowerShell script to upgrade my webdrivers before running a selenium script, I encountered an issue. The command I was using to retrieve the version of msedgedriver.exe was successful, but when I tried the same command for chromedriver.e ...

Why is it that PowerShell cannot execute Angular commands?

Recently, I started diving into Angular and encountered an issue using PowerShell in Windows. Every time I run an angular command like: ng new new-app or ng serve I keep getting this error message: ng : File C:\Users\< username >\ ...

Leverage JSON as your configuration file for PowerShell commands

$Settings = (Get-Content -Raw -Path $settingsFile)| ConvertFrom-Json -Verbose Output: @{key1=value1; key2=value2} From the input file: { "key1": "value1", "key2": "value2" } I seem to be receiving a string instead of the expected result. What c ...

Inputting data one row at a time instead of all at once in groups

I am working on a project to extract rows from a large JSON document and insert them into an SQL Server database. The current code I have successfully inserts one row at a time into the table, which seems to be every 1000th row. add-type -path "C:\P ...

What method can I utilize in Powershell to filter out specific key names from a JSON file?

Attempting to shrink a large 700MB JSON file, which is a scaled-down version of the file found here: The goal is to eliminate unnecessary data by excluding certain keys such as hypernyms, pos, categories, and more. However, previous attempts at this using ...

Is it possible to execute a Python script in Notepad++ through PowerShell, ensuring that it runs within the script's directory?

Is there a way to execute a Python script in Notepad++ that launches in Windows Powershell and runs the script directly from its directory, even if the directory path contains spaces? ...

What is the best way to modify a JSON file using PowerShell?

There's a json file named mytest.json, and I am looking to modify its values using a PowerShell script. The update.json file looks like this: { "update": [ { "Name": "test1", "Version": "2.1" }, ...

Stopping a Powershell script while it is running in React can be achieved by utilizing

Running some simple files using React in Powershell and trying to stop the script. When attempting Ctrl+c, it only displays stopping endlessly. Ultimately, I find myself having to close out of Powershell and utilize task manager to end the npm scripts. Ev ...

Avoid writing any duplicate values to a CSV file

I need help with converting a JSON file into a CSV file while avoiding duplicate values in the output. I want to include four columns in my CSV file without repeating any data. My approach involves storing variables in an array and writing them to a CSV f ...

Send a member as an array to be converted to JSON in PowerShell

Check out this brief PowerShell code snippet: $users = New-Object System.Collections.ArrayList $userAsJson = ' { "name" : "abc", "companies" : ["facebook", "google"] }' $user = $userAsJson | ConvertFrom-Json $null = $users.Add($user) $users | Conv ...

Different means of obtaining Azure AD login records in Python without relying on the subprocess library or powershell.exe

After researching various sources, it seems that the subprocess library in Python is commonly used to run PowerShell commands from within Python. For instance: data = subprocess.check_output(["powershell.exe", "Connect-AzureAD -AccountId < ...

Alternative Ways to Send Emails with PowerShell

I am facing an issue with sending emails using a PowerShell script as my company's Virus scan (McAfee) is blocking port 25. While I am aware of the option to disable the "prevent mass email" setting in McAfee and calling Outlook within the script, both opt ...

Why does the for loop keep replacing the JSON objects within the array in PowerShell?

Here is the code snippet I've been working on using PowerShell: $ArrayOfArguments = @("Param1", "Param2", "Param3") $ArrayOfArgumentDescriptions = @("Description1", "Description2", "Description3") ...

Unable to replicate the JSON data block

I've been attempting to duplicate the condition block from id 106 to id 107 using the script below, but I keep encountering an error stating "ConvertFrom-Json: Invalid JSON primitive:". Is there something important that I am overlooking? Any guidance would ...

Is it possible for me to connect an npm run command as a task in a Gruntfile?

In the root directory of my site, I have made changes to the package.json file by adding the "scripts" hook below: "scripts": { "ngDeployDev": "@powershell -NoProfile -ExecutionPolicy Unrestricted -Command ../../Scripts/ng-build-deploy/ngDeployDev.p ...

Obtaining Font Information using Node.js

Is there a way to retrieve the Description section of a font's properties, as seen when you right-click on the file? https://i.stack.imgur.com/rwnLw.png I am specifically looking for details related to the Title attribute. I tried using the get-file-pro ...

Extracting table information from a webpage with PowerShell

As a newcomer to both PowerShell and HTML, I am venturing into the realm of extracting table data from a webpage using the powerful combination of PowerShell and Selenium webdriver. My approach involves automating the process of launching a specific webpag ...

There seems to be an issue with the functionality of Selenium in Powershell when used within the Start-J

I am attempting to run a PowerShell script that utilizes Selenium and Start-Job Start-Job { $Url = 'https://stackoverflow.com/' $Driver = Start-SeChrome Enter-SeUrl -Url $Url -Driver $Driver } The intended functionality is for the script ...

Install NPM without changing directories to the folder

Currently, I am using Windows Powershell and a pipeline to create the package for an application deployment. Here is the pipeline setup: https://i.stack.imgur.com/am2iR.png My current obstacle revolves around the "npm install" command, as I want to avoid ...

What could be causing the sanity cli to encounter an error during installation?

I'm facing an issue while attempting to execute the following commands: npm install -g @sanity/cli >> sanity init --coupon javascriptmastery2022 and this error message is displayed: sanity : File C:\Users\...\AppData\Roaming ...

Insert a fresh key-value pair into a JSON document using Powershell

Recently, I've been working with a JSON file that looks like this: { "buildDate": "2017-08-16", "version": "v1.2.0" } I've been wondering about how to add new key-value pairs to an existing JSON file. For instance, starting with the J ...

Eliminate item from collection of objects in Json using Powershell

I have a scenario where I am importing JSON data into Powershell to update certain values, but I also need to remove specific objects from the imported data. Here is my import code: $fileJson = Get-Content -path/Template.json -Encoding UTF8 In the JSON ...

Enrich PowerShell with additional JSON functionality

Does anyone know of a straightforward method to merge one JSON file with another and save the combined output to a new file using PowerShell? I am currently working on creating a recursive function for this purpose, but I'm wondering if there is a sim ...

Modifying the nodeJS executable path on Windows without administrator privileges

My Windows PC does not grant me admin rights, but the admin has already installed Node at C:\Program Files\nodejs, with version 12: PS C:\Users\JO52900> node -v v12.18.3 PS C:\Users\JO52900> Get-Command node CommandType ...

Using Powershell to open a new terminal and execute a command in a bash session within WSL

Currently, I am in the process of creating a Powershell script to expedite setting up my development environment. My goal is to have multiple instances of WSL programs running on bash terminals. My objectives from within Powershell are as follows: Open a ...

Running multiple npm tasks concurrently using a ".sh" file in Windows: a step-by-step guide

Brand new to ".sh" right now when faced with this question. I am not even certain what ".sh" refers to - Shell, Powershell, Bourne shell, etc. Currently, I am operating from a Windows OS. The goal of this question is: Change directories Run the npm scrip ...

Encountered a 0x80131515 error when attempting to load an assembly from a network UNC share

When attempting to add an assembly from a network UNC share using the following command: $scriptPath = Split-Path ($MyInvocation.MyCommand.Path) Add-Type -path "$scriptPathselenium-dotnet et40WebDriver.dll" You may encounter the following error: Add- ...

Add the output of an SQL query to an HTML table using Powershell

I have multiple databases from various SQL Servers. I am attempting to output SQL data to an HTML table using Powershell from these different databases/SQL Servers, and then send it via email. Although my current script is functioning, it generates multip ...

Utilizing Powershell to eliminate characters from a string

After pulling a list of IPs from a JSON file, I've been using the code snippet below: $Request = 'https://url-to-json.com/file.json' $AWSIPs = Invoke-WebRequest $Request | ConvertFrom-Json | Select-Object prefix -ExpandProperty prefixes -ExcludeProperty ( ...

Separating JSON objects by their key value

At the moment, I am focused on retrieving the expiry status of Azure AD applications. I have collected approximately 1700 AD applications and added a new key pair (status) to the JSON object based on the expiration date of the secret. 1) valid 2) Expired 3 ...

Execute PowerShell commands with Node scripts

Whenever I work on my projects locally, I usually run MongoDB and start Nodemon. To do this, I open up terminals in vscode but I often forget the specific commands needed for each. As a result, I have to refer back to a txt file where I copy and paste the ...

Powershell throwing error due to unsigned Firebase script

While setting up a new project with Firebase, I encountered an issue after running the firebase init functions command. The error message displayed is as follows: firebase : File C:\Users\fudge\AppData\Roaming\npm\firebase.ps ...

Setting a variable in Powershell from a package.json script - a step-by-step guide

I am currently facing an issue with the script in our package.json that is meant to run single test files using a specific syntax. The problem arises when running this script in Windows 10 with Powershell, as it generates an error message: "singleTest ...

Gathering data from distant servers through powershell

I need to retrieve drive information from a collection of Windows servers running between 2008 and 2016 using PowerShell. I have successfully written code to fetch the information locally, but I am struggling to do it remotely or from a text file containin ...

Using Powershell to Transform JSON Data into Property Format

I'm currently facing a challenge that I am struggling to overcome due to my lack of experience. Any assistance from the experts on this platform would be immensely helpful :) My task involves converting JSON input into property format. For example: T ...

Concealing Command Prompt Output with PowerShell and Selenium

Currently, I am utilizing Selenium in conjunction with PowerShell to launch a dashboard display using Internet Explorer on a large office monitor. The process is initiated as follows: $seleniumOptions = New-Object OpenQA.Selenium.IE.InternetExplorerOption ...

Powershell is unable to detect NPM modules that have been installed locally in the bin directory

When creating a local NPM project designed to act as an installable NPM CLI command on Windows, I encountered issues with local testing not behaving as expected. To showcase this problem, I have set up this GitHub repository. Take a look at the provided r ...

PHP web application experiencing delays in response time following the execution of a PowerShell script

I'm currently developing a PHP web application on an IIS web server, and my goal is to create a read-only PowerShell live web console. Here's how the setup works: 1) On the main "console" page, there is a div element along with some buttons. I ...

Command prompt does not acknowledge Cordova. The variables have been successfully updated

An error occurred while running the command in the cmd prompt: C:\Users\Admin>cordova C:\Users\Admin\AppData\Roaming\npm\node_modules\cordova\node_modules\execa\index.js:347 th ...

Run a Powershell command remotely in the background

I am attempting to connect to a Windows machine using SSH and run a command in the background. When I directly run the following command from the terminal after establishing an SSH connection, it works: start PowerShell.exe -ExecutionPolicy Unrestricted I ...

Get rid of the first line of PowerShell output

While attempting to retrieve the session ID, I encountered an issue where the output displayed the column name instead of the actual ID. When using a match function, the correct value is returned since the output does not include the column names. Is ther ...

Utilizing PowerShell to Retrieve Shopify JSON Data through the API (Experiencing a 401 Error with Invoke-Webrequest)

I am currently working on writing a PowerShell script to interact with Shopify's API and retrieve JSON data. I have set up a private app, and successfully accessed a JSON feed via a browser. Initially, I managed to make it work using System.Net.WebClient, ...

System.Diagnostics.Process versus System.Management.Automation.PowerShell: A Comparative Analysis of Performance

In a recent blog post by the PowerShell Team, they discussed the use of posh commands. Can we utilize Create() without loading any PS command to function as a system process executor (similar to System.Diagnostics.Process)? How can we achieve this wi ...

Creating environment variables and making changes to a JSON file with the Power Shell Script Plugin in Jenkins: A step-by-step guide

The JSON file is located at %Workspace%\solution\config\appsettings.json { "appName": "Test", "appId": "1", "env" : "Test", "url" : "https://url.com", "client_id": "", "client_secret": "", "QAEmail" : "<a href="/cdn-cgi/l/email-protecti ...

Programs installed from the admin command prompt or PowerShell are not automatically included in the PATH for regular command prompt or PowerShell, causing errors like "foo not

Currently, I am facing an issue while attempting to globally install a package that requires installation from an administrative cmd/powershell (as it utilizes windows-build-tools). The installation process goes smoothly without any errors when executed th ...