forked from PoeBlu/powershell-scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGet-OU-From-IP.ps1
More file actions
24 lines (22 loc) · 1.06 KB
/
Get-OU-From-IP.ps1
File metadata and controls
24 lines (22 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Author : Assaf Miron
# Http://assaf.miron.googlepages.com
# Description :
# This Script outputs to a file the OU location of computer IP's from a List text file
# Using the Ping-Host command from PSCX
# Input : IP List text File and a Path to a log file
# Output: Log file that has the Canonical Names of all Computers in the IP List Text File
param ($IPFile = $(Read-Host "al1l59545.endo.com"),$LogFile = $(Read-Host "D:\"))
$ScriptLocation = Split-Path -Parent $MyInvocation.MyCommand.Path
IF( Get-PSSnapin | where { $_.Name -eq "PSCX" } ) {
$msg = "Script Has Started $(Get-Date)" + "`n`r`n" + "Reading from File $IPFile`n`r`n"
Out-File $logFile -InputObject $msg
$File = Get-Content $IPFile
ForEach ( $line in $File){
# Resolve the computer name using ping
$tmpHost = (Ping $line).Host.Split(".")[0]
# GetCanonical Name from VBS
$tmpOU = Invoke-Expression ("Cscript -nologo $ScriptLocation\SearchObjects-ReturnCanonicalName.vbs $tmpHost computer")
# Output to the Log file
$line+","+$tmpOU | Out-File -Append $LogFile
}
}