893 questions
1
vote
0
answers
58
views
Set Date Format In Multi Table Powershell CSV Export [duplicate]
I am working with a Powershell script, using DBATools, which exports data from multiple tables to individual CSV files.
In the tables, I am needing to reformat the date to yyyy-mm-dd. I found the ...
0
votes
1
answer
103
views
Adding a key-value pair to a JSON object in Powershell without using ConvertFrom-Json
Is there a way to add a key-value pair to a JSON object in Powershell without using the ConvertFrom-Json cmdlet? The script I currently have outputs a JSON file that is unreadable because it has ...
4
votes
1
answer
102
views
How can I output a PSCustomObject from a compiled Cmdlet?
I have a compiled Cmdlet that works with Hashtables. I would like to write a [pscustomobject] of the hashtable to the pipeline. In a PowerShell script block that would be accomplished using the ...
0
votes
2
answers
105
views
Usage of powershell Set-Disk on USB attached devices
I try to run the following statements on an usb attached device :
Clear-Disk 2 -RemoveData -RemoveOEM -Confirm:$False
Set-Disk -Number 2 -PartitionStyle MBR
When the device is a usb stick (flash disk)...
0
votes
0
answers
120
views
Power BI REST API: RLS Role Not Applied in Query Execution Using PowerShell Cmdlets
I am testing Row-Level Security (RLS) using the Power BI REST API but noticed that roles are not being applied. The query executes with full admin access instead of enforcing the assigned role.
...
2
votes
0
answers
45
views
Is there a way to programmatically determine if a compiled cmdlet requires elevation (other than simply running the command)?
Is there a way to use reflection to programmatically inspect and determine if a given compiled cmdlet requires elevation?
Notes:
This question concerns compiled cmdlets, not script (text) files.
...
2
votes
3
answers
127
views
For a compiled Cmdlet, how can I output each object immediately from an invoked scriptblock?
Consider the following
Invoke-Command {
'a'; Write-Verbose 'a' -Verbose
'b'; Write-Verbose 'b' -Verbose
} |
. { process { Write-Verbose "downstream_$_" -Verbose } }
which outputs
...
0
votes
1
answer
412
views
The type initializer for 'iText.Commons.Actions.EventManager' threw an exception
I'm trying to build a simple PowerShell cmdlet that will use iText7 to open a PDF file and output the text. I've tried using the iText7Module from PowerShell Gallery, but the ...
1
vote
0
answers
119
views
PowerShell Exchange Commands Not Working in Docker on Linux for Exchange On-Premises 2007
I am currently developing a REST API that needs to interact with an on-premises Microsoft Exchange server (Exchange 2007, not Office 365) through PowerShell commands. In my development environment (...
0
votes
1
answer
218
views
Why is there a discrepancy between storage usage in Exchange Admin Center and 'Get-MailboxFolderStatistics'?
I'm currently working on Exchange license storage usage analysis and encountered a discrepancy between the storage usage size shown in the Exchange Admin Center (EAC) for each user and the size ...
0
votes
0
answers
442
views
Unable to catch Powershell cmdlet exception calling MS-Graph API [duplicate]
I have Powershell script which I use to remove MFA authentication methods of a user through MS-Graph.
At a certain point the code executes this command:
try {
Remove-...
2
votes
1
answer
79
views
Powershell C# Extension How to Set the DefaultDisplayProperty when returning data with Write Object
I have created a PowerShell cmdlet in C#:
using System.Management.Automation;
using thosepeskyexternalclasses
[Cmdlet(VerbsCommon.Get, "GetActivity", SupportsTransactions = false)]
public ...
1
vote
0
answers
1k
views
Unable to Use Get-MessageTrace Command in Exchange Online
I’m having trouble with PowerShell and Microsoft Exchange. I’m trying to interact with Exchange Online via PowerShell to retrieve all emails received within a specified date range and display them on ...
0
votes
1
answer
89
views
The term 'ng' is not recognized as the name of a cmdlet, function, script file, operable program
Why is the ng command not working ?
The command should work but it's giving me an error like:
The term 'ng' is not recognized as the name of a cmdlet, function, script file, or operable program. ...
-5
votes
1
answer
197
views
C++ Compiler error : The term 'make' is not recognized as the name of a cmdlet [closed]
I want to compile cpp project in vscode and I write "make to terminal after that I have a error :enter image description here What do you think about this error .How I solve this?
I can't ...
0
votes
1
answer
146
views
Is there a way to use Read-Host using inline syntax in powershell?
I have a command Get-Aduser -Filter 'Surname -like "Doe"' -properties * | Format-List, but I'd like to use it with a Read-Host cmdlet using inline syntax. Something similar to
Get-Aduser -...
1
vote
1
answer
342
views
Powershell out-file -append silently skips a few rows when used inside foreach loop
I am trying to extract a representative sample of a 200MB csv file by writing the header and every 500th row to a new file for testers to use. My first attempt was knowingly sub-optimal but seemed ...
0
votes
1
answer
64
views
PowerShell - Remove-Item working weirdly when -Filter value passed
Can anyone please help me understand why "Remove-Item" cmdlet behaves weirdly when using -Filter option for removing specific list of files? Same if I passed in other cmdlets its working ...
0
votes
1
answer
39
views
How to my own cmdlet (using C#) with two input parameters mandatory but mutually exclusive?
I'm developing PowerShell Cmdlets in C#. I would like to define mandatory parameters, but that are mutually exclusive.
Example:
Parameter A
Parameter B
When invoking the command, I must set only ...
0
votes
1
answer
168
views
$DebugPreference = "Continue" not working when running a powersehll runbook in azure automation account's test pane
Earlier when I used to use command $DebugPreference="Continue" within the powershell script, this used to print the output with all the debugging lines. Now I am not able to see debug ...
0
votes
1
answer
708
views
Azure powershell failing with error: One or more errors occurred while using Get-AzRecoveryServicesVault cmdlet
I am trying to execute a powershell script in azure automation account runbook test pane. In my powershell script, I am importing the modules, connecting automation account using managed identity and ...
0
votes
0
answers
1k
views
Exchange Online: New-DkimSigningConfig cmdlet not found with some Tenants
We use powerscript with EXO on many tenants where we have created an App in the Azure portal. This app has Office 365 Exchange Online application permissions:
full_access_as_app
Exchange.ManageAsApp
...
0
votes
2
answers
191
views
PowerShell script parallelization effort - A job does not wait until it gets an answer from the REST API and finishes the job prematurely
Edited with last version code:
I have a PowerShell script which is doing following steps:
Connect to SQL server, download table of 3 variables (three fields)
Then Connect to REST API (based on three ...
1
vote
1
answer
135
views
In PowerShell, How to refer to a cmdlet itself rather than executing it?
I'm currently learning Powershell 101 using PowerShell 7.4, and I'm interested in inpecting the type of some expressions, for example by executing
[Powershell] | gm
I get:
TypeName: System....
0
votes
0
answers
33
views
Get an error when I use the cmdlets Set-Service
Set-Service -Name TeamViewer -DisplayName Team Viewer
And I always get this error,even if I add double quotes on the name and the displayname
Set-Service: A positional parameter cannot be found that ...
0
votes
1
answer
1k
views
PowerShell CmdLet with NET8 could not load file or assembly
I'm trying an experiment and I want to create a CmdLet for PowerShell in NET8. I have created a new Class Library and added the following packages:
Microsoft.PowerShell.SDK
PowerShellStandard.Library
...
0
votes
1
answer
104
views
C# Serialize PSCredential to XML with XmlSerializer
Experienced with PowerShell, but new to C#.
I am creating a Binary PowerShell Cmdlet and have run into an issue when trying to serialize PSCredential to XML with the XmlSerializer.
When I serialize ...
-1
votes
1
answer
135
views
How to parse filepaths in PowerShell-Functions the correct way?
I have written functions that have path parameters.
I'm not sure if I implemented it correctly. Is there a standardized or better way of doing this in Powershell?
function Get-PathExample {
param(
...
0
votes
0
answers
52
views
How do I pass a value in a Cmdlet class in F#?
I wrote a PowerShell function in F# and I would like to run NUnit tests on the functions.
In C# I wrote these tests previously:
[Fact]
public void ConvertJWTTest()
{
//-- Arrange
var base64 = &...
-1
votes
1
answer
74
views
How to open windows OS host entry file with powershell cmdlet or windows run dialog box?
I hope there must be powershell cmdlet to open the Windows host entry file. I have checked across the net and I could to find the windows command for opening the host entry file, so I can utilize it ...
0
votes
1
answer
322
views
How to use Invoke-RestMethod with Import-Csv to loop through URLs
I'm attempting to dynamically create about 50 QR Codes using GoQR.me's API. I have all the source and destination URLs in a CSV file QRCodes.csv formatted as:
source, destination
https://api.qrservers....
1
vote
0
answers
269
views
PrincipalSource Property is blank in Get-LocalGroupMember by PowerShell Script
I am getting "PrincipalSource" property Blank while running following command by PowerShell Script in c#.
Command : Get-LocalGroupMember -Group Administrators
PowerShell Output:
By C# Code ...
1
vote
1
answer
1k
views
Issue with Setting Alias in PowerShell (oh-my-posh) on Windows 11
I'm facing an issue while trying to set an alias using PowerShell (oh-my-posh) on Windows 11. I have successfully created aliases before, like opening Notepad++ using
Set-Alias np path_to_notepad_exe.
...
1
vote
1
answer
1k
views
How to add pre-defined inbound firewall rules to a GPO using powershell
Update: My use-case requires me to automate deployment of Windows Server VMs for test environment. While I've managed to find ways to automate the process via powershell in 90% of tasks, I'm now stuck ...
1
vote
2
answers
2k
views
Show progress while one cmdlet is running
I know about Write-Progress cmdlet and use it.
This cmdlet is usefull where you want to show progress of an loop running for example, or when stack of cmdlets is running.
But how can I show progress ...
0
votes
1
answer
500
views
I'm trying to write an Azure Function app (http trigger) that executes a PowerShell script
Whenever I try to run said function, I keep getting this particular exception:
EXCEPTION: Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=...
0
votes
0
answers
47
views
PowerShell Start-Job with C++ exe file: Why are start and end times the same for each batch of 5 jobs?
powershell running a c++ .exe using start-job cmdlet
$connectionstring = "Server=localhost;Database=testDB;Trusted_Connection=True;"
$connection=New-Object System.Data.SqlClient....
0
votes
1
answer
308
views
ping command in the CMD
In this code of block everything works great, but... when you type list it supposed to show the entire list of available servers connected, but the servers with id 02, 03, 04, 09 are not revealing, ...
2
votes
1
answer
588
views
How do I actually generate an error using $PSCmdlet.WriteError in PowerShell?
I've been reading up on generating error messages in PowerShell and stumbled across this example...
$Exception = [Exception]::new("error message")
$ErrorRecord = [System.Management....
1
vote
1
answer
609
views
How to create a task on windows using powershell and specified trigger
I'm trying to create a task on windows taskscreduler using the powershell but without success. The script I need to create based GUI description:
"At 08:00 every day -After triggered, repeat ...
0
votes
1
answer
185
views
NodeJS exec can't find MachineGuid from registry using powershell cmdlet
I am trying to obtain the MachineGuid through NodeJS using child_process.exec with cmdlet Get-ItemPropertyValue
const command = "Get-ItemPropertyValue -Path 'HKLM:\\Software\\Microsoft\\...
0
votes
1
answer
181
views
Create an array of enumerable collections using ForEach-Object over object properties (without expanding / enumerating them)
I have a Match[] from string matching, each Match has a Groups property which is a GroupCollection. I want to map the Match[] to a GroupCollection[], and I'm trying to do this with a pipeline's output ...
1
vote
1
answer
84
views
Detect last cmdlet in a powershell pipeline
I want to write a cmdlet that changes its behavior depending on its pipeline position. Simplyfied example:
Get-XYZObject | Rename-XYZObject
If the cmdlet is the last in the pipeline it should work ...
0
votes
1
answer
199
views
How to get the Mailaddress by the Name of an exchange user
I try to run a Script that will give mal participants of a mail-distributiongroup and their mailaddresses. For the participants it works quite well, while for the owners it doesent work, because im ...
0
votes
1
answer
940
views
Azure cmdlet: How to group Results with Invoke-AzCostManagementQuery?
Microsoft has introduced a powerful cmdlet called Invoke-AzCostManagementQuery, which is part of the Az.CostManagement module. This makes it possible to generate customized cost reports in all ...
0
votes
1
answer
193
views
Fix file load error in PowerShell: 'file is not utf-8 coded'
The file load error keeps popping up after I added contents to the file by using commands.
I was working on Windows PowerShell on JupyterLab. Firstly, I created a new file using the following command:
...
0
votes
1
answer
232
views
Powershell .iso install with variable - unable to unmount properly
I'm trying to automate some processes with Powershell and browsing here and there a bit, I've put together a little .ps1 file that allows me to mount an Iso image on the next available drive, store ...
0
votes
0
answers
3k
views
having difficulty to execute powershell from command prompt
Unable to execute powershell script from the command prompt.
test.ps1 file:
echo "testing"
Here is the error:
c:\run>powershell .\test.ps1 echo : The term 'Write-Output' is not
...
0
votes
0
answers
17
views
How can I launch an application via PowerShell in Windows using FolderItem Object [duplicate]
I am collecting a list of names and paths from the following PowerShell code:
(new-object -com shell.application).namespace('shell:appsFolder').items()
I am able open each item using its invokeVerb() ...
-1
votes
1
answer
327
views
Receive-SFTPFile : A parameter cannot be found that matches parameter name 'RemoteFile'
I am using Transferetto module to download SFTP files, it is able to connect to server and list the server files but throwing error while downloading with below error:-
Receive-SFTPFile : A parameter ...