Thursday, September 19, 2013

Powershell: Restart service on a list of computers

#Gets a list of machines and then restarts the specified service on each computer.
#Get list of computers
$Computers = Get-Content C:\myscript\serverlist2.txt
#what service
$service = "spooler"
#Function to create object
function OutData($computer,$service,$Object) {
 $out = New-Object psobject
 $out | add-member -type noteproperty -name Computer $computer
 $out | add-member -type noteproperty -name Service $service
 $out | add-member -type noteproperty -name Result $Object
 $out
}
#create empty variable
$result = @()
#main
foreach ($computer in $computers)
    {
    if (Test-Connection -ComputerName $computer -Quiet -count 1)
        {
        $Object = "Restarted $($service) service"
        Restart-Service -InputObject $(Get-Service -Computer $computer -Name $service)
        $result += Outdata $computer $service $object
        }
        else
        {
        $object = "$($computer) not online"
        $result += Outdata $computer $service $object
        }
    }
#export the results
$result | Export-Csv C:\myscript\RestartServiceResults.csv -NoTypeInformation
$Result


If you find this article useful please leave me a comment or click on an ad to show your support.

Tuesday, September 10, 2013

My Plasma Ball sets of my smoke alarm

I turned on my plasma ball that my dad gave me years ago,, then the smoke alarm went bezerk. I wonder what is happening to cause this.

I suspect the high frequency and high voltage of the plasma ball may be knocking the protons that the smoke alarm uses sense if there is smoke in the room or not off course (normally smoke particles would do this).

Powershell Export-CSV as FileName with Date

Exporting data from powershell in to CSV format is easy. We can use the 'export-csv' cmdlet. However I got stuck trying to append the date to the filename of the CSV.

The tricky bit that I got stuck on was when i tried Get-date I tried like this thinking it would work.
$users | Export-Csv c:\temp\LNCUS-$(Get-Date -format dd-MM-yyyy) .csv -NoTypeInformation  
This failed with the following error


The error happens because the output from Get-Date is not in a string format. To fix this we just need to convert the date format to string by doing the following
$users | Export-Csv c:\temp\LNCUS-$((Get-Date).ToString('MM-dd-yyyy')).csv -NoTypeInformation

If you find this article useful please leave me a comment or click on an ad to show your support.

Tuesday, September 03, 2013

How to restart the task sequence wizard in WINPE without having to reboot

If you make a mistake and cancel out the task sequence wizard in WinPE you can restart it without rebooting. Keep in mind this won't work everytime as it depends on where you failed your task sequence

TsBootShell.exe

To find it you might need to goto to the root of your WinPE drive and type

DIR TsBootShell.exe /s

It will normally be found in

X:\sms\bin\i386

If you find this article useful please leave me a comment or click on an ad to show your support.

Friday, August 16, 2013

How to stop a Windows 7 PC from locking


You can stop a Windows 7 PC from locking by changing the following registry key

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System.
Create a new DWORD 32-bit value named DisableLockWorkstation and give it one of these values:• 1 – Disable Lock Workstation• 0 – Enable Lock Workstation

I found when testing this I did not need to restart for this setting to take effect. 

I found out this registry key the hard way when using a Lenovo BIOS update utility. When the Utility is updating the BIOS it locks the keyboard and mouse and also inserts that setting into the registry. However, it did not remove the registry key after the BIOS update. Therefore I was unable to lock my PC until I found out why. 




If you find this article useful please leave me a comment or click on an ad to show your support.