Setting Windows PowerShell environment variables

I have found out that setting the PATH environment variable affects only the old command prompt. PowerShell seems to have different environment settings. How do I change the environment variables...

PowerShell 2.0 and "The term 'Param' is not recognized as the name of a cmdlet, function, script file, or operable program"

I am running Windows 7 RTM. PowerShell 2.0 is installed by default. I am using the excellent Windows PowerShell ISE to edit my scripts. I have the following script: Param($p) Param($d) echo $p...

How to group files by date using PowerShell?

I have a folder with 2000+ files. I want to count the files by date. so with: Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- ...

Using PowerShell credentials without being prompted for a password

I'd like to restart a remote computer that belongs to a domain. I have an administrator account but I don't know how to use it from powershell. I know that there is a Restart-Computer cmdlet and...

How do I loop through get-counter results to get to make a decision?

I'm trying to get the following counter over the span of 5 minutes. If it returns 100, 5 times in a row, I'd like to receive an email. get-counter -Counter "\Processor(_Total)\% Processor Time"...

File Output in Powershell without Extension

Here is what I have so far: Get-ChildItem "C:\Folder" | Foreach-Object {$_.Name} > C:\Folder\File.txt When you open the output from above, File.txt, you see...

How can I exclude multiple folders using Get-ChildItem -exclude?

I need to generate a configuration file for our Pro/Engineer CAD system. I need a recursive list of the folders from a particular drive on our server. However I need to EXCLUDE any folder with...

Form doesn't refresh in Powershell GUI application (Enable/Disable Text boxes doesn't work)

i am writing a script which reads the user details from active directory, it reads users samid and pull all his details in text boxes to display; here i am using a radio button to enable/disable...

Invoke-sqlcmd on remote machine

I am using following code to execute a query on a remote machine. Invoke-Sqlcmd -ServerInstance $serverInstance -Database $dbName -InputFile $filePath -U "test" -P "testpwd" But getting an error...

How to use powershell to select and copy columns and rows in which data is present in new workbook.

I want to select and copy columns and rows in which data is present in new workbook. I found this link which helped me just do the...

Use ValidateSet with the contents loaded from a CSV file

I really like the way that ValidateSet works. It proposes the options as a list while you type your Cmdlet in the PowerShell ISE. I would like to know if it's possible to retrieve values from a...

PowerShell function parameters syntax

Why do the Write-Host outside of the function work different than inside of the function? It seems like somehow the parameters variables are changing from what I declared it to be... function...

PowerShell programmatically set input field by name in IE

Related: https://stackoverflow.com/questions/17049203/powershell-download-or-save-source-code-for-whole-ie-page The input fields I need to programmatically drive do not have an ID, so I'm trying...

Configuring "Do not forcefully unload the users registry at user logoff" in User Profiles of Group Policy editor

I need to write a PowerShell script that should configure the below settings of Group policy in all the machines. Gpedit.msc → Computer Configuration → Administrative Templates → System →...

Remove blank lines in powershell output

I'm trying to remove blank lines before and after output but it's just not working. I tried Adding -NoNewLine after the very first Write-Host, but that only removes one blank line so far. Code: ...

MPIO Disk active path

I was using the below mentioned VBScript to collect the MPIO Disk active path information from multiple servers. I was trying to convert the VBScript to a PowerShell module, but am unable to find...

How to enable the Windows 10 "Containers" feature?

Using the latest Windows 10 Fast Ring build 14316 (inside a VMware virtual machine), I'm trying to make the Desktop App Converter function working. When running the PowerShell script as...

Is it possible to write one script that runs in bash/shell and PowerShell?

I need to create ONE integrated script that sets some environment variables, downloads a file using wget and runs it. The challenge is that it needs to be the SAME script that can run on both...

How do I force powershell to reload a custom module?

I have created a module 'ActiveDirectory.psm1' which contains a class in powershellv5. I am importing that module in another file called 'test.ps1' and then calling a method from the...

Powershell and UTF-8

I have an html file test.html created with atom which contains: Testé encoding utf-8 When I read it with Powershell console (I'm using French Windows) Get-Content -Raw test.html I get back...

How to create System.IO.StreamWriter with Encoding in Powershell?

I'm trying to create instance of StreamWriter with UTF8 encoding in PowerShell. $f = New-Object System.IO.StreamWriter "a.txt", $false, [System.Text.Encoding]::UTF8 This throws error: New-Object...

Exit PowerShell if Remove-Item fails

I have such command dir "D:\BA1\xml-data\build-dir" -Directory | Where LastAccessTime -lt (Get-Date).AddDays(-22) | Remove-Item -Recurse to remove old folders. And most of the times it works....

how to fix DownloadFile error in powershell in windows10

I ran cmd as administrator and input: start powershell when open the powershell, I input: $client = new-object...

Get-AzureADPolicy : The term 'Get-AzureADPolicy' is not recognized

After connecting to Azure AD with Connect-AzureAD , If run the command Get-AzureADPolicy, PowerShell is prompting the message as "Get-AzureADPolicy : The term 'Get-AzureADPolicy' is not recognized"

kubectl exec command not working from powershell ISE (works from powershell) - Is there a reason or workaround to make it work?

I have recently started working with Kubernetes and Docker and still new with how it all works. I have made a ps1 script to run all the steps I need to do to build image and execute image on...

How can I check to see if today is a holiday

We've got some scripts that run inside of scheduled tasks that send us email alerts to remind us to take action on some things in our environment daily. I'd like to prefix the script(s) with logic...

Powershell install - No match was found for the specified search criteria and module name

I am having a difficult time installing/updating my powershell modules. I noticed this when I tried installing DBA Tools moudle. Reference links are https://dbatools.io/download/ and...

Execute PS from bat for Intune Win32

I am so confused and actually also not so familiar with PS and bat after my troubles with them. I want to set the Lockscreen in Windows 10 with Intune through an IntuneWin file (WIN32...

Create a Script: Enumerate Access Control Lists

I am "attempting" to create a script using a foreach loop in order to display the ACL's in that directory. Here are the instructions : Above the foreach condition, set a variable, $directory, to...

PowerShell filter by OU

Import-Module ActiveDirectory Get-ADComputer -Filter {enabled -eq $true} -properties *|select Name, | Out-File -FilePath c:\Powershell.txt I am trying to export a list to txt file and have it...