Powershell

Uninstall a program from powershell

0

If you need to uninstall a program from a prowershell script this will do the trick:

If you get the return value of 1603 your not running your script as admin

SCCM 2007 and Powershell Packages

0

Dont you just hate problems that are fixed by one easy click but finding what to change takes forever. I had a problem with a task sequence for a new laptop model that refused to execute packages using powershell. The older sequences executed fine and I could not understand why. At first I started looking at the powershell executionpolicy and realized I had forgotten to add the commandline that set it to RemoteSigned in the sequence. Easy fix, I added the commandline in the sequence and ran the sequence again…..all powershell packages failed.

 

After this failure I tried running the package commandline manually and it worked fine. All the packages installed without a problem. I started looking at smsts.log and execmgr.log and could not find anything pointing me to what was going wrong until I compared the logs to another model that actually could run these packages. I noticed that the older sequence downloaded the files and executed them locally but the new one executed from the UNC path. This led me to the advertisement of the task sequence, and there it was right in front of my eyes. I had forgot to set the advertisment correct so it did not download the packages before executing them.

 

 

 

Easy fix but took forever to find!

 

// Nike

ESX – Shutdown virtual machines on specific hosts through powershell

0

We needed a powershell script at work to shutdown specific hosts and there vm at power-failure, this is what I came up with.

Notice: You need to install PowerCLI from VM to get this to work as the script uses PowerCLI as a snapin and if you are planing on using this script on another machine then the VSphere server you need a valid certificate on the VSphere server to get this to work.

Export and import wireless profiles through powershell

0

I needed to be able to push out wireless connections through sccm and this is what I came up with.

 

EXPORT

1. We need to export the wireless profile from a connected computer

2. Open the .xml file that was created in the previous step

3. Change the value protected from true to false

4. Enter your password for the wireless connection under keyMaterial, right now you will find a long string so just delete that and enter your password

5. Save and close

Now you have exported a profile and configured it with the password, the password is now in clear-text so this file should be kept in a secure place

 

IMPORT

1. Import the profile on the new computer, default is for current/all users

 

Done, now you have imported the wireless profile and you can now connect without entering a password.

But we dont want to import the profile manually, so now its time to automate this through powershell

1. We need to get the current directory where the script is running from

2. Import the wireless profile

3. Save your .pst file in the same directory as “Your Wireless Profile Name.xml” and just run your script from any source like usb, network share or whatever.

Change DNS on NIC through Powershell

0

I needed to change DNS settings on all my servers with static IP and wrong DNS settings.

Password Expire Mail Script

0

We had a issue at work where all the webmail users called in the same weeks as there passwords was about to expire, they didnt get any notification since they never logon on to a computer, and don’t forget that Windows 7 users dont get the same change password promt as the XP users get, now its just a small notification balloon. Thought this issue would be solved by a quick search for a script on google but didnt find any good ones around that covered all aspects.

There are alot of scripts that gets all users where password is about to expire but they only do the query against one domain, password expire dont replicate as often as needed to just be able to query one DC.

I needed a script that collected all users that are enabled and password was about to expire from all domain so this is what I came up with.

Done, just schedule this script and get rid of all help-desk calls disturbing your morning coffee!

Remove all mapped printers from a specific printserver in powershell

0

I was working on a print-migration and needed to remove all mapped printers to the old print server on all clients. I made this script and placed it under login script in the same GPO as the new distributed printer GPO. This way then the new printers will be deployed for all users the old ones will automatically be removed.

Change the “\PRINT-SERVER” in the script to your print-server and the script will remove all mapped printers that contain that print-server path.

Done, now all your mapped printers that contained the path entered will be deleted!

NZB Cleanup script

0

A friend wanted me to make a powershell script to clean up his NZB movie/series directory from crap files and sample video as they just take place so since i did a little script for that I might as well share it even if its a basic one.

This script will remove the following files: .sfv , .nfo , nzb and par2 files that might have been missed by the NZB download client.

Just exchange the paths to your own nzb download(s) directory.

Just make the windows scheduler run the script at night and you will always have a nice movie repository =)

How to fully automate installation of Microsoft Forefront Security for SCCM with WSUS update in powershell

0

I made a script that would automate the installation of Microsoft Forefront Security and add the computer name to the AD Group for Forefront and then update the WSUS server with the computer name and assign it to the right groups. Now there are ways that you can automatically assign client to the right WSUS server through WSUS itself and then this installation script might come in handy.

Files placed on the installation package:

  • install.ps1
  • Forefront Client Security installation package
  • password.txt

Files placed on the WSUS server directory C:ScriptWsus:

  • wsus.ps1
  • addtowsus.ps1

For this to work we need to execute command on remote servers such as the DC and the WSUS server and therefore PSRemoting must be enabled on these servers.

PSRemoting does the following:

  • Starts the WinRM service.
  • Sets the startup type on the WinRM service to Automatic.
  • Creates a listener to accept requests on any IP address.
  • Enables a firewall exception for WS-Management communications.

(more…)

How to enable “File and Printer Sharing for Microsoft Networks” on NIC with PowerShell

0

Me and a colleague was working on SCCM implementation for a customer and deploying the client turned out to be a problem, after some investigation in the logs and on the client we found that File and Printer Sharing was disabled on the Network Interface Card (NIC) and therefor the installation got canceled as the computernameadmin$ could not be found.

So I started to google the issue and found no good way on how to enable File and Printer Sharing. Found some information about snetcfg_winxp.exe but I didnt want to uninstall and reinstall the service MS_Server I just wanted to enable the binding for File and Printer Sharing on the NIC.

What I did find was a former Microsoft employee that had made his own tool for modifying network bindings called nvspbind that utilizes the INetCfg APIs that can enable network bindings if it has one of the following information on the network card in hand, GUID or Display Name as it will not recognize the friendly name for example Local Area Connection.

The OS on the target computers were Windows XP and I found it easier to use the Display Name as the GUID on XP machines returned nothing but worked fine on Win7.

Here is a script that I made that we connected to the login script so that all computers will run it, if File and Printer Sharing is allready enabled on the NIC nvspbind will do nothing so its safe to run on enabled systems aswell.

Just point out where you placed the tool nvspbind.exe on the network and run the script and File and Printer sharing will be enabled and a new textfile will be generated with the name of the computer that ran the script.

And now File and Printer Sharing is enabled on all active network cards

Page 2 of 212
Go to Top