Click here to Skip to main content
15,886,110 members
Everything / Programming Languages / PowerShell

PowerShell

PowerShell

Great Reads

by The Ænema
This article will teach you how to create an amazing, clean and smooth WPF/Winform UI for your native application without using any complex, unsafe, ActiveXish methods, etc.
by Daniel Miller
This article describes the C# implementation for a high-performance user/role security principal hierarchy.
by Jo_vb.net
This article and the demo are about getting started using the MVVM Toolkit and some self-created interfaces / services for MessageBox and some dialogs.
by Christian Vos
How to use Microsoft Unity Interception as a solution for cross cutting concerns in a .NET application

Latest Articles

by Federico Di Marco
A tool which creates one or more Powershell scripts which in turn recreate one or more binary files
by Wessel Beulink
Azure spearheads cloud evolution, Azure Automation Runbooks manage hybrid/SOC environments effectively
by Federico Di Marco
How to enable Bitlocker hardware encryption on self encrypting drives
by Federico Di Marco
Create quickly VPN connections in Windows according to a XML configuration file

All Articles

Sort by Updated

PowerShell 

2 Mar 2024 by Federico Di Marco
A tool which creates one or more Powershell scripts which in turn recreate one or more binary files
25 Jan 2024 by Wessel Beulink
Azure spearheads cloud evolution, Azure Automation Runbooks manage hybrid/SOC environments effectively
22 Dec 2023 by Federico Di Marco
How to enable Bitlocker hardware encryption on self encrypting drives
15 Dec 2023 by Richard MacCutchan
Try treating the content like a .csv file and using Import-Csv (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Learn[^] to create a set of custom objects. You should then be able to sort the objects. [edit] This seems to work: $A =...
14 Dec 2023 by Member 13174636
Hi, I have a text file test.txt with the following content: AAAA z 669 BBBB y 9555 AAAA z 5 BBBB z 48 CCCC y 1166 AAAA x 67777 BBBB z 223 I want to find lines with "z" and sort the resulting set according to last column. What I have tried:...
28 Nov 2023 by taersious
Wrap this in a function (script block). $block = { ... your custom method ... } Then put the function call in a loop that runs on a list of servers as shown here: foreach ($Server in $Servers) { if (Test-Connection...
21 Nov 2023 by Federico Di Marco
Create quickly VPN connections in Windows according to a XML configuration file
13 Nov 2023 by Zijian
Use PowerShell scripts to generate icons of native mobile apps
8 Nov 2023 by ImfeldC (Switzerland)
When running the script extract below it used different encoding when running from command shell or as scheduled task! The relevant command is 'Add-Content', why does it be have different when running this directly wihtin a command window then...
10 Oct 2023 by OriginalGriff
Check the content of $sql - if it refers to parameters like this:SELECT Description FROM MyTable WHERE ID = @ID then make sure that you have added the parameterized data to the $cmd object before you try to call ExecuteReader. And why are you...
10 Oct 2023 by Damian Tsai
Not sure what's wrong with the command lines below. See the command lines and errors I received. # Load into datatable $dt = New-Object System.Data.DataTable $cmd.CommandText = $sql $dt.Load($cmd.ExecuteReader("CloseConnection")) Error...
13 Sep 2023 by Enrique Parris
Error: The partial main could not be found at Object.invokePartial What I have tried: The file is in the right place, so I tried to reinstate the file in my command terminal, using Windows PowerShell.
30 Aug 2023 by OriginalGriff
To add to what the others have said, it doesn't quite work like that. We do not do your work for you. If you want someone to write your code, you have to pay - I suggest you go to Freelancer.com and ask there. But be aware: you get what you pay...
29 Aug 2023 by Member 16081714
# Quell-Pfad $quelle = "C:\Users\tanc\Documents\Test\Quelle" # Zielpfad $ziel = "C:\Users\tanc\Documents\Test\Ziel" # Datum abfragen $date = read-host "Datum des Ordners eingeben (yyyymmdd)" # ordner ermitteln und diesen dann verarbeiten...
28 Aug 2023 by Pete O'Hanlon
Sounds like you're using handlebar here. In your app.engine call, you have the option to define a partialsDir like thisapp.engine('hbs', hbs({ // other settings here partialsDir : [ path.join(__dirname, 'views/partials'), ] }) ); Move...
14 Jun 2023 by Leszek Koc
Auto subscription of Azure functions to Event Grid
7 Jun 2023 by Micah Ebohon
When you want to get files from a remote machine and needed by a system or other process, it is possible using WinSCP and PowerShell script.
25 May 2023 by Illya Reznykov
The post describes how to use token-based authentication to run SQL queries against Azure SQL Database.
8 May 2023 by Dathuraj Pasarge
Extract SQL Server DB inventory\baseline using TSQL and PowerShell scripts
3 May 2023 by huynhminh97
I tried to set up kiosk mode for my laptop to run WPF single app. Firstly, I turn on Shell Launcher in Turn Windows features on or off and run script in powershell with admin right to open my WPF app then restart device. After restart and login...
3 May 2023 by Graeme_Grant
Did you try rebooting in safe mode? This should get you back in.
3 May 2023 by OriginalGriff
We really can't help you - we have no access to your app or your system, and you probably need both to get anywhere. I'd suggest you start with MS tech support - they can at least dial into your machine and see what is going on, which we can't.
9 Apr 2023 by baburman
I want to launch a simple windows service through Windows PowerShell ISE. My code is as below: $serviceName = "BabServiceInPowerShell" Class BabServiceInPowerShell : System.ServiceProcess.ServiceBase { ...
9 Apr 2023 by 0x01AA
OnStart and OnStop are not events the .NET object System.ServiceProcess.ServiceBase does expose. These are virtual Methods you can ovveride in case you derive from ServiceBase. For more infromation please read this: Register-ObjectEvent...
25 Mar 2023 by l o o l
Understand that this is true said by Dave-Kreskowiak You cannot export a single value. You would have to write your own tool to do that A bat would do that, but use a filter and a temp file: @echo off set "_hkey=HKLM\SOFTWARE\Dinesh" >nul reg...
25 Mar 2023 by Dinesh Kumar Dora
How can i export only a single reg entry from a reg key? I dont need all the subkeys or entries or values to be exported. Just a specific single reg entry. I tried reg export but it exports the whole reg key with whole reg subkeys and other...
20 Mar 2023 by Bogdan Marian
Ensure your Docker Compose services start in the correct order
15 Mar 2023 by Hm Grossman
Using visual studio window designer; include PowerShell on button clicks. For example run run an MSI installer on ok button click? What I have tried: I don't know what to try but my window is built in vs.
15 Mar 2023 by OriginalGriff
Save it as a .PS1 file, and use Process.Start to execute the file.
12 Mar 2023 by hans.sch
I created a PowerShell script that accesses iTunes on my PC, but I failed at receiving events from the iTunes object. The code which I found on the internet (in fact, Chat GPT recommended this code) is: $eventHandler = {Write-Host...
9 Mar 2023 by Bruno van Dooren
How to clean up user profiles on a computer
6 Mar 2023 by Mandavali
I have a nested json that I am working on converting to csv here is section in it that is not in Square bracket, that I would like to iterate.. How do I do that to get the data "answers": { "1": { ...
6 Mar 2023 by Richard MacCutchan
See ConvertFrom-Json (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Learn[^] and ConvertTo-Csv (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Learn[^].
3 Mar 2023 by Dave Kreskowiak
You can't. There is no tool that comes with Windows that will export anything other than an entire key and all of its sub-keys and values. You cannot export a single value. You would have to write your own tool to do that.
3 Mar 2023 by Richard MacCutchan
PowerShell is fun :) Export registry information using PowerShell[^] Batch Script - Reading from the Registry[^]
27 Feb 2023 by Jo_vb.net
This article and the demo are about getting started using the MVVM Toolkit and some self-created interfaces / services for MessageBox and some dialogs.
19 Feb 2023 by MrSorrow1993
I use BurntToast module in order to throw toast notifications in Windows 11. Here is my notification: https://i.stack.imgur.com/wWOV1.png When I click Pause button, its caption should be changed to Resume and its argument should be changed to...
19 Feb 2023 by Andre Oosthuizen
The following might help - $Button1 = Get-ChildItem -Path 'SomePath\SomeFile' | Out-GridView -OutputMode Single -PassThru -Title 'SomeTitle' | ForEach-Object { $_.name } if ($button -eq 'pause') { $button = 'resume' } Write-Host "Button...
22 Dec 2022 by Rupesh yadav 2022
. $env:USERPROFILE\.config\powershell\user_profile.ps1 ERROR:E212 cant open file for writing:no such file or directory What I have tried: i gave all permission to user_profile.ps1
22 Dec 2022 by Gunesh Shanbhag
Above error comes because you dont have a default powershell profile file IN powershell terminal Run, echo $PROFILE Output will be in this format which is the path to default powershell profile eg....
23 Sep 2022 by Illya Reznykov
Functions that manipulate CloudWatch log group by PowerShell Core
18 Sep 2022 by Illya Reznykov
Functions that get information about web ACL by PowerShell Core with AWS CLI
6 Sep 2022 by Member 14686752
Powershell Command is: Set-NetIPInterface -InterfaceIndex 11 -InterfaceMetric 99 This command is working when I run it on PowerShell as admin. but: C# Code PowerShell ps = PowerShell.Create(); ps.AddCommand("Set-NetIPInterface -InterfaceIndex...
6 Sep 2022 by Member 15758983
Use AddScript() instead of AddCommand() and it will work
2 Sep 2022 by Member 15755436
$SCApplicationName = 'Office 365 Setup' $SCApplication = Get-WmiObject -Namespace "root\ccm\ClientSDK" -Class CCM_Application | where {$_.Name -like $SCApplicationName} [hashtable]$Arguments = @{Id = $SCApplication.Id;IsMachineTarget =...
24 Aug 2022 by Member 9346617
Hello Everyone, I want to pass below string parameter from cmd to ps1. The string that I want to pass has spaces in between. As a result, I believe, it is not able to read the entire string. string parameter - ...
24 Aug 2022 by Richard MacCutchan
Just put it in double quotes: Foo.ps1 "\\Intranet.abc.com\afhb-emea\GROUP\IND\IT\SharedServices\Pune Ravet\Test"
10 Aug 2022 by Member 15733198
I am using vs code for python codding and i was trying to upgrade pip and in the process my terminal showed this weird text with beeping noise. The weird text: ←]633;P;IsWindows=True 633;A633;P;Cwd=C:\Users\ENJOY.ENJOY-PC\Downloads\Python...
8 Aug 2022 by Sai Darshan 2022
We have a requirement to change our application's IIS app pool password everytime it expires. Currently, we have to manually login to each server adn run a snippet of PowerShell code which changes the password. Here is the code we run on each...
5 Aug 2022 by User 15325224
I have a text log from an automated test that looks something like this: Start: 2022-08-01 19:18:39 - Auto_Performance_Test TestCase_Import SUCCESS 19.851s TestCase_VerifySOMETHING_begin SUCCESS 1.339s ...
5 Aug 2022 by Richard MacCutchan
Here is a starter that can extract all the time values: $regex = 'TestCase_' foreach($line in Get-Content -Path $mylog) { if($line -match $regex) { $test, $success, $time = $line.Split() $time = $time.TrimEnd('s') ...
14 Jul 2022 by Dave Kreskowiak
You copied nearly every character from a year old question into "your" question, and didn't bother to read the comments on the original question? The comments in the original question would have given you the answer you're looking for.
14 Jul 2022 by Member 15706520
I'd like to use PowerShell to get a list of available applications in the Software Center, and then pick the ones I wish to install on a local computer with a PowerShell script. What I have tried: Get-WmiObject -Namespace "root\ccm\ClientSDK"...
14 Jul 2022 by Richard MacCutchan
See the suggestions at How to install applications from software center through powershell[^]
12 Jul 2022 by Soskipic
Select-String -Pattern "\b($($keywords -join '|'))\b"-AllMatches
12 Jul 2022 by Soskipic
I have a list of keywords (sometimes with non-alphanumeric characters) that I’d like to find in a list of files. I can do that with the code below, but I want to avoid matching keywords if they are found inside another word, e.g.: Keywords.csv:...
5 Jul 2022 by Bruno van Dooren
How to read data from OPC DA servers into a PowerShell script
15 Jun 2022 by Tomasz Malicki
How to create a dynamic object in C # containing the results of a command executed in PowerShell.
26 May 2022 by taljit
I am trying to run a console application in background using powershell script and in the main method of "program.cs" it requires user confirmation. Working of this console application is to update some configurations and settings before i...
26 May 2022 by Gerry Schmitz
Redirect "standard input". process.StartInfo.RedirectStandardInput = true; process.StartInfo.UseShellExecute = false; Give user input for batch file via c# code - Stack Overflow[^]
26 May 2022 by Silver Lu
Windows instance run the following PowerShell command: Invoke-RestMethod http://100.100.100.200/latest/meta-data/ram/security-credentials/EcsRamRoleDocumentTesting then it will Obtain a temporary authorization Token result: { "AccessKeyId"...
26 May 2022 by Richard MacCutchan
Use Out-File (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Docs[^].
12 May 2022 by OriginalGriff
It's not the powershell file itself that needs permissions, it's one of the commands it contains that is trying to output to a specific file that causes it. Probably, it's trying to reference a folder that doesn't exist. Start by looking at the...
11 Apr 2022 by Scott C Hall
I need to a add a functiion in my existing web service to apply the 'Allow to Authenticate' rule to a computer. This has been a manual process in the past done with a PowerShell script we need to convert this to C#.The allowed to authenticate is an extended right.You can set it using...
21 Feb 2022 by Illya Reznykov
PowerShell script which copies certificate to another storage
3 Feb 2022 by JRivord
I have a script that is using PowerShell 5.1 and calling New-WebServiceProxy. I want to make this work in PowerShell Core (7.1). I have spent several hours trying to resolve this issue. Some of the best places I have found are...
19 Jan 2022 by harish koripelli
while running this in PowerShell $command1 = 'git shortlog branch..branch1 --oneline --pretty="%an committed %h %s"' $A=iex $command1 Write-Host "Starting" Write-Host "testing " foreach($i in $A) {$pos = $i.IndexOf(":") $leftPart =...
19 Jan 2022 by Peter_in_2780
The error message is clear. The second argument (length) to Substring() is out of range, specifically it is negative. You have provided $pos as second argument, so the error message is telling you that $pos is negative at that point. You set $pos...
17 Dec 2021 by Member 14992347
I am trying to get the list of virtual machine names, from a local Hyper-V server, with the following code: string _scr = ("Get-VM | Select -ExpandProperty Name"); var _ps = PowerShell.Create(); _ps.AddScript(_scr); Collection _cObj =...
17 Dec 2021 by Empty Coder
Get-VM only works in a PowerShell session run as administrator. When I try your C# code run as an administrator it does print VM names. When I try it without administrator rights I get no output, same as you - but there is an error reported if...
14 Dec 2021 by Member 15467879
Write a program to list all the directories and the corresponding files, under these directories,
14 Dec 2021 by Member 14156312
0 I want to read a 2 of text file (Byte2.txt and FB.txt), but I dont want to put the path on the script, I want to use argument when I run the script from command line to parsing the path to my script. My expextation, when I run the script from command line : $PowerShell.exe Script.ps1 arg1...
29 Nov 2021 by Member 13967067
Hi All, I have a script to remove Everyone permissions for NTFS and add Authenticated users, but I am using the SMB share to remove and add but that is not working for the Subfolders, can I do that using the ACL permissions instead of SMB...
26 Nov 2021 by Tomasz Malicki
Basic PowerShell handler C# class with an explanation
23 Nov 2021 by Raphael Mun
In this article, we explore packaging then deploying a game to Azure PlayFab servers.
21 Oct 2021 by Empty Coder
Hi All Below is the code I am currently using to remove the special NTFS permission from folder This code is working fine and removing the special permission from the folder. But the problem is the folder is also having 2 SYSTEM permission. 1...
11 Oct 2021 by rjb911
Hi, Would someone be so kind to help with regex question? I have an html file I need to search for all urls contained within href attributes that are not in a list I have specified. I need to return every line that contains a url that is not...
7 Oct 2021 by Empty Coder
Hi All I have below data which I want to write to existing excel sheet Error: 48 Ignored: 15 Want to put the data like below e.g. E8 - Error F8 - 48 E9 - Ignored F9 - 15 What I have tried: Need idea for how to do this in existing excel.
7 Oct 2021 by CHill60
See your previous question Excel formulas to find MIN, MAX and difference of time in powershell[^] The link I provided in my solution gives a specific example of how to put data into a specific cell.
7 Oct 2021 by Richard MacCutchan
See Introducing the PowerShell Excel Module - Scripting Blog[^].
6 Oct 2021 by Empty Coder
Hi All Below is the data i have in excel Server Name Control Group Tape Number Status Transfer Start Date Transfer Start Time Transfer End Date Transfer End Time BR502V7C QCLDUSYSW Q23028 ACTIVE 25-09-2021 ...
6 Oct 2021 by CHill60
If I was trying to find the minimum and maximum values of data in Excel I would just use a pivot table - either a straight forward pivot or a pivot query using Power Query. In Excel it's probably best to combine the date and time into a single...
5 Oct 2021 by Empty Coder
Hi All Below is the data I am getting in NewLines -Ignored:31,Modified src data,all *file,MINOSFIC/UTMNUP10 -Ignored:33,Modified src & tgt data,all *file,MINOSFIC/UVEGAP10 -Ignored:92,Synchro is running,*file,MINOSFIC/VM010P50...
5 Oct 2021 by Richard MacCutchan
Try this: $data = Get-Content 'file.txt' | Select -SkipLast 1 $Lines = @("Error Code, type, object") foreach ($line in $data){ if($line -match "Ignored") { $parts = $data[0].Split(" ",...
5 Oct 2021 by Richard MacCutchan
I just tried your code and the output was: -Ignored:32 Modified tgt data all *file MANHIN_SV/MCRHA52268 -Ignored:32 Modified tgt data all *file MANHIN_SV/MCRHA52269 -Ignored:32 Modified tgt data all *file ...
1 Oct 2021 by Empty Coder
Hi All Below is the existing data I have in my csv file "Server","Disk ###","Status","Size","Free" "s1","Disk 0","Online","100 GB","1024 KB" "s1","Disk 1","Online","6144 MB","1024 KB" "s1","Disk 2","Online","200 GB","1024 KB" "s1","Disk...
30 Sep 2021 by Empty Coder
Hi All Below is the text file data I have Disk ### Status Size Free Dyn Gpt -------- ------------- ------- ------- --- --- Disk 0 Online 100 GB 1024 KB Disk 1 Online 6144 MB 1024...
30 Sep 2021 by Richard MacCutchan
You can use about Split - PowerShell | Microsoft Docs[^] to separate the fields of the input. You then just need to use Write-Output to rewrite as required. Note that you need to call the code that does the rewriting once gfore every server....
16 Sep 2021 by Fringe Coder
How to uninstall multiple devices at once using PowerShell ISE
12 Sep 2021 by Lokesh Zende
Hi, Is there any way to find the dependent projects in the solution and build the projects accordingly sequentially. The project with no dependencies will build first. Then the other projects which are dependent on the first project and so on. ...