Quantcast
Channel: Windows PowerShell forum
Viewing all 21975 articles
Browse latest View live

Unzip GZ files using Powershell

$
0
0
I have  Windows 2008 Server with some GZ type files in a folder. I would like to script unzipping them using Powershell, can someone tell me if this is possible and how I would do it?

The folder is d:\data_files\ and I'd like to uncompress all the .gz files in there

I've searched around on the Net but can't find much that deals with GZ files specifically. The files are all named data-1.gz, data-2.gz etc
Hello

I have  Windows 2008 Server with some GZ type files in a folder. I would like to script unzipping them using Powershell, can someone tell me if this is possible and how I would do it?

The folder is d:\data_files\ and I'd like to uncompress all the .gz files in there

I've searched around on the Net but can't find much that deals with GZ files specifically.

Get-ADUser Filter by Manager disabled

$
0
0

Hello All, 

I am trying to work on the Script to get the manager disabled for a specific set of accounts and i am using the following conditions to get the disabled manager information. 

Get-ADUser -Filter {(sAMAccountName -like "xx" -or sAMAccountName -like "yy")} -properties Manager|

Select Name,@{label="Manager Status";expression={(Get-ADUser $_.Manager -Properties SAMAccountName).SamAccountName}} |

Where-Object {($_.Manager).Enabled -eq $false} |Export-CSV C:\temp\managerdisable.csv


When i try to run this script i am getting a blank CSV file. 

windows 8 PowerShell script for disabling ALL USB devices "USB power management" under device manager

$
0
0

I work for a company that uses Windows8 as a base platform for it's application.  We're having issues with touch screen randomly losing touch for no reason at all with the ACER touch screens.

We've been able to isolate some of the problems to ACER touch screen itself not being compatible with the USB power management feature built in to Windows.

For our Win7 I was able to use the below Powershell script to disable all of the USB devices Power management without having to go through each USB device in device manager.

$hubs = Get-WmiObject Win32_USBHub
$powerMgmt = Get-WmiObject MSPower_DeviceEnable -Namespace root\wmi | where {$_.InstanceName.Contains($hubs.PNPDeviceID)}

foreach ($p in $powerMgmt)
{
    $p.Enable = $False
    $p.psbase.Put()
}

This same script however doesn't work for Windows8.  Any one know how to modify the script above to make it work on Windows8??

Thanks!

Extracting logs through Powershell using a script

$
0
0

Hello,

We have windows server 2012 R2.We want to create a task[we schedule it to run once every month] which can run in powershell and export result in xml file.

Can anyone help us out with the powershell script?


Add-Computer cmdlet does not prompt for password when running over SSH

$
0
0

Hello,

I need to join computer into domain. Add-Computer cmdlet does not prompt for password when I am running from text-based terminal. I am connected over SSH to remote computer. How can I force powershell/cmdlet to ask for password?

My steps:

1. I connect to remote computer over SSH (using Putty),
2. Then start powershell.exe in the terminal on remote computer,
3. Then run Add-Computer* cmdlet, but powershell does NOT prompt for domain admin password.

*Add-Computer -DomainName 'mydomain' -Credential adminlogin

When I connect through remote desktop and run the same cmdlet, it asks me for the password. I want the same behaviour when I am in pure text mode.

Thanks!

Get-ADUser multi filters issue

$
0
0

Hi,

I am struggling with this simple script to find those without the keyword "Dean", "Instructor", or "Professor", etc. in the Description, but I ended up getting everyone. What's wrong?

Here is the script:

$staff = Get-ADUser -Filter {
  (Description -notlike "Instructor*") -or (Description -notlike "*Professor*") -or (Description -notlike "*Dean*") -or (Description -notlike "*Program Chair*") -or (Description -notlike "*Program Director*") -and (Enabled -eq $true)} `
  -SearchBase "OU=Employees,OU=User Accounts,DC=School,DC=edu"
$staff | Sort-Object -Property SAMAccountName | Select-Object -Property SAMAccountName | Out-File c:\staff.csv 
($staff).Count

Thanks,

Mike

Get MAC address of all connected, active network adapters?

$
0
0

Does anyone know how to filter down GetMac's results to only show connected network adapters?

GetMac seems to return two columns: Physical Address, Transport Name

So far I have:

$results = GetMac | Format-Table -AutoSize
$results

I'd like to apply the filter of:

IF "Transport Name" has the word "disconnected" (case insensitive) in it.

All my attempts have failed :(

Powershell output from Get-ItemProperty - VersionDetails property of file does not correlate with version when browsing through GUI.

$
0
0

Hi,

Recently we needed to get the version of mpio.sys one of our servers.

I used Get-ItemProperty in Powershell to get the version, but when we browsed to the mpio.sys file in Explorer and looked at the Details tab, the values did not correlate with the values I got from Powershell. I am 100% certain that the path included in the Powershell command was correct. Can anyone provide an explanation of why this can occur?


Script For .NetFramework 4.7.2 GPO installation

$
0
0

I'm trying to push .net framework 4.7.2 to some domain pcs using a logon script through GPO.

Clients are Windows 7 SP1 x86 machines and the server is Windows 2008 R2 Std

i''m using a .ps1 script with the following command:

Start-Process -FilePath \\sharepath\NDP472-KB4054530-x86-x64-AllOS-ENU.exe -ArgumentList "/q /norestart"  -Wait -Verb RunAs

I then add it as a logon script in GP under User Configuration - Windows Settings - Scripts -> logon (In powershell Scripts Tab)

When the user logs in, the script runs fine, but because of the fact that my users don't have administrative privileges, the UAC window pops up and requires admin rights.

Is there a way to add a command in the script to run using one of the domain admins account or any admin account so as to install the software with admin rights?

Password Expiry in the Clear-PasswordTimestamp.ps1

$
0
0

Hi,

Added the powershell script mentioned in the below URL to OSD Task sequence. 

https://blogs.msdn.microsoft.com/laps/2015/05/06/laps-and-machine-reinstalls

Password expiry date is showing in the below format. This is not in the correct format. It should show 30 days from the script executed date. 

for example if the script run today the password expiry date should be 25/08/2019 12:00:00am

Please help


Regards, Boopathi

Get-ADUser filter -- getting disabled accounts when (Enabled -eq $true) is applied.

$
0
0

Hi,

I am trying to find only active/enabled faculty members with this script, but ended up getting disabled accounts, too.

Any insight?

Thanks,

Mike

----------------------------------------------------------------------------------------------------------------------------------

# To find faculty
$filter_faculty = {
    Enabled -eq $true -and 
    Description -like "*Instructor*" -or
    Description -like "*Professor*" -or 
    Description -like "*Dean*" -or
    Description -like "*Program Chair*" -or
    Description -like "*Program Director*"
}
$faculty = Get-ADUser -Filter $filter_faculty -SearchBase "OU=User Accounts,DC=School,DC=edu"
$faculty | Sort-Object -Property SAMAccountName | Select-Object -Property SAMAccountName | Out-File c:\faculty.csv


Windows Form, have button return to disabled if text box is empty?

$
0
0

New to forms here :).... I'm trying to have my validate button return to disabled (grayed out) when the text box goes from having text to no text. I can get this work initially when the text box is empty. Below is my code as well as a screen shot of the form. I've come this far with method 'add_TextChanged'. Top Pic: no text in text box so validate button is disabled (grayed out). Middle Pic: text box has text so validate button is enabled. Bottom Pic: text in text box has been deleted, but validate button remains enabled. 

$Form = New-Object system.Windows.Forms.Form
$Form.Text = "Validate Name"
$Form.Width = 420
$Form.Height = 130
$Form.StartPosition = "CenterScreen"

$LabelFolder = New-Object System.Windows.Forms.Label
$LabelFolder.Location = New-Object System.Drawing.Size(10,10) 
$LabelFolder.Size = New-Object System.Drawing.Size(90,15) 
$LabelFolder.Text = "Folder Name:"
$LabelFolder.BackColor = $Color
$Form.Controls.Add($LabelFolder)

$ButtonFolderVal = New-Object System.Windows.Forms.Button
$ButtonFolderVal.Enabled = $false
$ButtonFolderVal.Location = New-Object System.Drawing.Size(320,10)
$ButtonFolderVal.Size = New-Object System.Drawing.Size(60,22)
$ButtonFolderVal.Text = "Validate"
$ButtonFolderVal.Add_Click({Validate})
$Form.Controls.Add($ButtonFolderVal)

Function Validate
{
	$Form.Controls.Remove($LabelValRes)
	$LabelValRes = New-Object System.Windows.Forms.Label
	$LabelValRes.Location = New-Object System.Drawing.Size(10,40) 
	$LabelValRes.Size = New-Object System.Drawing.Size(200,15) 
	
	if ($TextBoxFolder.Text -eq "Something Valid")
	{
		$LabelValRes.Text = "$($TextBoxFolder.Text) is valid"
	}
	else
	{
		$LabelValRes.Text = "$($TextBoxFolder.Text) is not valid"
	}

	$Form.Controls.Add($LabelValRes)
}

$TextBoxFolder = New-Object System.Windows.Forms.TextBox 
$TextBoxFolder.Location = New-Object System.Drawing.Size(110,10) 
$TextBoxFolder.Size = New-Object System.Drawing.Size(200,15)
$TextBoxFolder.add_TextChanged({$ButtonFolderVal.Enabled = $true})
$Form.Controls.Add($TextBoxFolder)

$Form.ShowDialog()

                   

Thanks for the help, Joey



Filtering on NoteProperty

$
0
0

Hello,

I need to filter on a particular class’ (i.e. Management Server) property (i.e.IsGateway), but am being returned an empty collection:

$objManagementServerClass = Get-SCOMClass -DisplayName "Management Server"

$colManagementServers = Get-SCOMClassInstance -Class $objManagementServerClass | Where-Object {$_.IsGateway -eq $false}

When I perform a Get-Member on the class, I see that the property in question (i.e.IsGateway), is not your regular Property type, but rather a “NoteProperty”, and that it is inherited, as can be seen here:

[Microsoft.SystemCenter.HealthService].IsGateway                                    NoteProperty

How do I filter on this “property”?

Thanks,

Larry

Blog post: How to Check your PowerShell Version (All the Ways!)

$
0
0
In PowerShell, there are a zillion ways to do the same thing (or close to it). In this blog post, you're going to learn every way check your PowerShell version for both local and remote computers. We'll cover the bad ways and my recommended way.

https://adamtheautomator.com/check-powershell-version

Blog post: PowerShell Tutorial Mini-Course: Building a Server Inventory Script

$
0
0
Hello fellow scripters, I thought I'd just this in here in case it may help someone.

Summary: In this free 9,000-word PowerShell tutorial (mini-course), learn how to build a real-world script step-by-step. This is a must read for PowerShellers.

https://adamtheautomator.com/powershell-tutorial-mini-course

deleting archived personal certificates by issuer

$
0
0

I've been scratching my head all afternoon on this one . I want to delete archived personal certificates from the cert store identifying by issuer. The following works great for non-archived certificates,

Get-ChildItem Cert:\CurrentUser\My  | ?{ $_.Issuer -eq 'exactIssuerName' } | Remove-Item

but I cannot find a way to target and remove archived certificates in the same store.

Any ideas?

Blog post: How to Check for a Pending Reboot in the Registry (Windows)

$
0
0
Hello fellow scripters, I thought I'd just this in here in case it may help someone.

Summary: Learn how to check for a pending reboot the registry on Windows Servers and how to automate it in this tutorial!

https://adamtheautomator.com/pending-reboot-registry-windows

How to add value in JSON Array using PowerShell

$
0
0

How do I add value to the following JSON under Resource

{
"Sid": "AmazonS3Access",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::123",
"arn:aws:s3:::123/*",
"arn:aws:s3:::456*",
"arn:aws:s3:::456/*"
]
}

My target is to add following two value

"arn:aws:s3:::789*"
"arn:aws:s3:::789/*"

I have tried Add after importing JSON using ConvertFrom-Json, but didn't work.

$ImpJSON.Resource.Add(""arn:aws:s3:::789*"")

Note: JSON format is fixed, as you can see it is AWS IAM policy, but all the values are variable, so, it should be dynamic.

Any idea?


Regards, Saugata D

power shell script for getting list of members from Intune group

$
0
0

Hi All,

please provide PowerShell script for getting list of members added in Intune group. Thank you.

saving web session contents to an array

$
0
0

Hi,

Is it possible in powershell; to connect to a web page with a username & password, and save contents to an array ?

Thanks,

 

Viewing all 21975 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>