Change service startup type in multiple systems


Hi there,
This is a very simple script to view the actual status of a startup type of a service and change that status :).

#********************************************************

$ComputerName = gc “.\servers.txt”

Get-WmiObject Win32_Service -ComputerName $ComputerName | where{$_.Name -eq “SERVICE NAME”} | ft Name, StartMode, State, status, __SERVER

Set-Service -ComputerName $ComputerName -name “SERVICE NAME” -StartupType Disabled

Get-WmiObject Win32_Service -ComputerName $ComputerName | where{$_.Name -eq “SERVICE NAME”} | ft Name, StartMode, State, status, __SERVER

#********************************************************

That’s all.

Script for use Disk Cleanup on server 2008, without installing the desktop experience.


Hi,

Requested by many families (a pedido de muitas familias), Portuguese joke :), here is a script that manually place the files, so you can put the Disk Cleanup working without installing the Desktop Experience.
The Zip file contains two scripts.

The first copies the need files to the system folder. The second creates a folder in the Start menu.

Download Script . Enjoy.

Powershell Script to get Mcaffe Information


Hello,

This Powershell script is to check ProductVersion, EngineVersion, DatVersion, AVDatDate, for the Mcaffe anti-virus.
You can also adapt this script for other things, if you need to read from registry, just like I did :).

######################################
#——————————————————
# get-content <list of servers.txt> | .\Script.ps1
# or
# get-content <list of servers.txt> | .\Script.ps1 | FT
#——————————————————
Continue reading

Script to check the installed date of software in powershell


Hi,
The simplest way to know when particular software, or all software was installed in your system, is run this script.

######################################## Start Script ########################################

Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |Select DisplayName, DisplayVersion, Publisher, InstallDate, HelpLink, UninstallString | ft

######################################## End Script# ########################################

Enjoy.
🙂

Nslookup in Powershell


This script is needed when we have multiple ip’s, and we need to know which server to which it belongs.
Instructions:
Powershell_Script_Nslookup.ps1 servers_IP_List.txt output_file_list.txt

# Start Script #

Function NSlookup {
Param($hostname)
#$iphostEntry = [System.Net.Dns]::GetHostEntry($hostname)
# Rexolve obsolete but better than GetHostEntry
$iphostEntry = [System.Net.Dns]::Resolve($hostname)
$line = $iphostEntry.HostName

$strSeparator = “;”
foreach ($addr in $iphostEntry.AddressList) {
$line = $line + $strSeparator + $Addr.IPAddressToString
$strSeparator = “|”
}

$strSeparator = “;”
foreach ($alias in $iphostEntry.aliases) {
$line = $line + $strSeparator + $alias
$strSeparator = “|”
}

return $line
}

# ***********************************************

Function TestFile {
Param(
[String] $strFilename,
[String] $strCurDir
)
if ($strFilename) {
$strCurDir = $(if ($strCurDir) {$strCurDir} else {if ($MyInvocation.MyCommand.CommandType -eq “Function”) {(Get-Location).Path} else {Split-Path -parent $MyInvocation.MyCommand.Path} })
If ((Test-Path(“$strFilename”)) -eq $False){
If ($strFilename.ToUpper().Contains($strCurDir.ToUpper()) ) {
Write-Host “ERROR: file $strFilename NOT exist”
return
} Else {
If ((Test-Path(“$strCurDir\$strFilename”)) -eq $False){
Write-Host “ERROR: file $strFilename NOT exist”
Write-Host “ERROR: file $strCurDir\$strFilename NOT exist”
return
} Else {
$strFilename = “$strCurDir\$strFilename”
}
}
}
return $strFilename
}
}

# ***********************************************

Function GetFileIntoArr {
Param(
[String] $strFilename,
[String] $strCurDir,
[Ref]$arrFile,
[String] $strComment
)
$strComment = $(if ($strComment) {$strComment} else {“#”})
$strCurDir = $(if ($strCurDir) {$strCurDir} else {if ($MyInvocation.MyCommand.CommandType -eq “Function”) {(Get-Location).Path} else {Split-Path -parent $MyInvocation.MyCommand.Path} })

$retFilename = TestFile -strFilename $strFilename -strCurDir $strCurDir
if ($retFilename) {
$Content = Get-Content “$retFilename”
Foreach ($line in $Content) {
$comment = $False
If ($line.Trim().length -gt 0) { # take only line with data and without # at begininng of the line
# if we do not want to use comment
If ($strComment -eq “#”) {
If ($line.substring(0,1) -eq “#”) {
$comment = $True
}
}
If ($comment -eq $False) {
# Get Search & Replace
$arrFile.Value += $line.Trim()
}
}
}
return $True
} else {
return $False
}
}

# ***********************************************

#
# Start here 😀
#

If($Args.Count -lt 2) {
Write-Host “Syntax:”$MyInvocation.MyCommand.Name “inputfilename outputfilename”
Write-Host ” Example:”$MyInvocation.MyCommand.Name” ‘inputfile.txt’ ‘outputfile.txt’ ”
Write-Host
Break
}

$inputfile = $args[0]
$outputfile = $args[1]
$date = get-date -format “yyyy-MM-dd”
$Content = “#Date;Computer;Hostname;IP`r`n”
$Content | Out-File -encoding ASCII $outputfile
[Array] $arrComputers = @( )

if ($inputfile) {
if (!(GetFileIntoArr -strFilename $inputfile -arrFile ([Ref]$arrComputers))) {
Break
}
} else {
Write-Host “ERROR: you need a filename.txt as second parameter inputfile”
Break
}
Foreach ($computer in $arrComputers) {
$nslookup = NSlookup($computer)
$line = $date + “;” + $computer + “;” + $nslookup
#+ “`r`n”
Write-Host $line
$line | Out-File -append -encoding ASCII $outputfile
}

# End of script #

Connectivity to Dc´s


You need PORTQRY and a txt file to enter the hostnames of the servers or IPs.
Just copy the script below and save it as batch file.

Enjoy.

:::::::::::::::::::::::::::: BEGIN SCRIPT :::::::::::::::::::::::::

@ECHO OFF
:: Test connectivity.
:: using PORTQRY utility.
:: The SERVERS.TXT contains a list of servers (one server per line)
:: to check connectivity to.
ECHO     DATE: %DATE% > PORTQRY_%COMPUTERNAME%.TXT
ECHO     TIME: %TIME% >> PORTQRY_%COMPUTERNAME%.TXT
ECHO     USER: %USERNAME% >> PORTQRY_%COMPUTERNAME%.TXT
ECHO COMPUTER: %COMPUTERNAME% >> PORTQRY_%COMPUTERNAME%.TXT
ECHO. >> PORTQRY_%COMPUTERNAME%.TXT
ECHO. >> PORTQRY_%COMPUTERNAME%.TXT
ECHO. >> PORTQRY_%COMPUTERNAME%.TXT
FOR /F “tokens=1” %%i in (servers.txt) DO (
ECHO ::::::::::::::::::::::  %%i  :::::::::::::::::::::::::: >> PORTQRY_%COMPUTERNAME%.TXT
ECHO Testing %%i
ECHO. >> PORTQRY_%COMPUTERNAME%.TXT
PORTQRY -n %%i -e 88 -p TCP | findstr /i “88”  >> PORTQRY_%COMPUTERNAME%.TXT
PORTQRY -n %%i -e 53 -p TCP | findstr /i “53” >> PORTQRY_%COMPUTERNAME%.TXT
PORTQRY -n %%i -e 137 -p TCP | findstr /i “137” >> PORTQRY_%COMPUTERNAME%.TXT
PORTQRY -n %%i -e 138 -p TCP | findstr /i “138” >> PORTQRY_%COMPUTERNAME%.TXT
PORTQRY -n %%i -e 139 -p TCP | findstr /i “139” >> PORTQRY_%COMPUTERNAME%.TXT
PORTQRY -n %%i -e 445 -p TCP | findstr /i “445” >> PORTQRY_%COMPUTERNAME%.TXT
PORTQRY -n %%i -e 389 -p TCP | findstr /i “389” >> PORTQRY_%COMPUTERNAME%.TXT
PORTQRY -n %%i -e 3268 -p TCP | findstr /i “3268”  >> PORTQRY_%COMPUTERNAME%.TXT
PORTQRY -n %%i -e 3269 -p TCP | findstr /i “3269” >> PORTQRY_%COMPUTERNAME%.TXT

ECHO. >> PORTQRY_%COMPUTERNAME%.TXT
ECHO. >> PORTQRY_%COMPUTERNAME%.TXT
)

:::::::::::::::::::::::: END SCRIPT :::::::::::::::::::::::::