Search The Web

Showing posts with label script. Show all posts
Showing posts with label script. Show all posts

Tuesday, February 25, 2014

Manual Sync ADFS with Powershell.

Manual Sync ADFS with Powershell.

Occasionally you cant wait three hours for your ADFS to synchronise your local Active Directory with the Azure copy. No matter, as you can force a directory sync with the following powershell command:
Start-onlinecoexistencesync
start-onlinecoexistencesync www.dizzyit.com
start-onlinecoexistencesync www.dizzyit.com
This command will sync your on premises Active Directory with the Azure online copy. This is especially useful in situations such as Office 365 implementations where you have changes such as email addresses or group membership changes that need to be updated into the online directory.

This post can be viewed on our sister site www.dizzyit.com at: http://wp.me/p1Zlmi-7e




Saturday, March 30, 2013

Remove Network Printers from Command Line or Script



Remove Network Printers from Command Line or Script


There are several options when it comes to removing printers via command line / script.The first option is to use the "rundll32 printui.dll" method. For this, open a command prompt and type:

rundll32 printui.dll,PrintUIEntry /dn /n \\printsvr\printername

if you want the operation to be silent, then use the /q switch at the end. this is especially useful if you have multiple printers that you want to remove via a batch file and/or if you are unsure if the printers are installed on the end users machines. If the printer is not currently installed and you attempt to remove it without the /q switch then you will receive an error. The figure below shows the command in its entirety:
Remove Network Printers from Command Line or Script
The next method would be to use a VB script such as this :
to make the script work, just replace the \\PRINTSERVER\PRINTERNAME" field with the details of your network printer and save as a .vbs file. to call the script just open up an administrator command prompt and type in " cscript scriptname.vbs " where scriptname is the name of your script.
To delete more printers just another line to the  " Dim sPrinterName "  lines with the printer number at the end, and then again  add another objNetwork.RemovePrinterConnection sPrinterName2, True, True line that reflects the printer number you just added.
Likewise, to remove only one printer just remove one of the above lines.


Option Explicit

  Dim objNetwork, objPrinters

  Set objNetwork = CreateObject("WScript.Network")
  Set objPrinters = objNetwork.EnumPrinterConnections

  ' ### Delete selected network printer

  Dim sPrinterName1
 Dim sPrinterName2
  sPrinterName1 = "\\PRINTSERVER\PRINTERNAME"
 sPrinterName2 = "\\PRINTSERVER\PRINTERNAME"
  objNetwork.RemovePrinterConnection sPrinterName1, True, True
 objNetwork.RemovePrinterConnection sPrinterName2, True, True

I found with this method however that it will error out if that printer does not exist. im not enough of a VB guru to tell you if its possible to quieten it down to run silently.

When all is said and done, there is a much better way of doing this, and that is with Group Policy Preferences. this gives you centralized control over your printer environments, allowing you to add and remove and update printers for small groups or your entire organisation.
Group Policy Preferences will be covered for printers in an upcoming entry.
This article can also be found on our You Tube Channel:















Monday, March 4, 2013

PowerShell - Set Execution Policy - Files Could not be Loaded because the running of scripts is disabled on this system.

PowerShell - Set Execution Policy -  Files Could not be Loaded because the running of scripts is disabled on this system.


when using PowerShell you may get an error stating that " Files Could not be Loaded because the running of scripts is disabled on this system. Please provide a valid certificate with which to sign the files" as shown below:



This at a basic level means that your security settings in PowerShell are preventing you from running the script ( the execution policy.

To fix this, you need to set the execution policy to a more relaxed setting. these are as follows:

  • Restricted - No Scripts can be run. Windows PowerShell can only be used in interactive mode.
  • All Signed - Only Scripts signed by a trusted publisher can be run
  • RemoteSigned - Downloaded scripts must be signed by a trusted publisher before they can be run
  • Unrestricted - No Restrictions, any PowerShell script can be run
At the time of writing, PowerShell comes out of the box in restricted mode.

To check which execution policy your system is running type Get-ExecutionPolicy




To change to policy you type Set-Execution Policy . When you run and go to a less secure setting, you will get a large warning asking if you want to do so
e.g. Set-ExecutionPolicy RemoteSigned.




It's not recommended to use unsigned as this would allow anyone who accesses the system to run malicious or damaging code on your system. Most individuals will settle on Remote Signed, however before doing so in an organisation please ensure that this complies with your organisations security settings.

for a video walk through of this, please check this youtube video from our sister site www.dizzyit.com . The article can also be located there.




Sunday, March 4, 2012

start and stop services via batch file / command prompt

start and stop services via batch file / command prompt


To start and stop services with a batch file is very easy and is useful for scheduled tasks where you may want to regularly restart a service for various reasons
Firstly, you need to know the name of the service. to locate this you go to computer management -> services and look for the name of the service you need to restart. In this case we will use the Print Spooler service.
your commands to stop the service are net stop "service name" and your command to start it are net start "service name"
so to restart as a batch file would look like"
@Echo Off
REM this will restart the prince spooler service

net stop "Print Spooler"
net start "print spooler"
exit
as usual you would want to add a remark (REM) to the start of the batch file to describe what you would like to do.
you can combine these commands for restarting complex systems such as IIS. as an exambple, this series of command will restart IIS's web, FTP and SMTP services
@Echo off
REM this restarts IIS's web, SMTP and FTP services
net stop "World Wide Web Publishing Service"
net start "World Wide Web Publishing Service"
net stop "FTP Publishing Service"
net start "FTP Publishing Service"
net stop "Simple Mail Transport Protocol (SMTP)"
net start "Simple Mail Transport Protocol (SMTP)"
so as you can see this is all pretty straight forward stuff. from here you can save the batch file and add it as a scheduled task in windows (more on that later)