One liner to get users from a text file and create a report of distinguishedname. You need the activedirectory module imported to run.
import-module activedirectory
gc "C:\temp\serviceaccounts.txt" | Foreach-Object {Get-ADUser -filter {CN -like $_} -Properties *} | select Name, SAMAccountName, distinguishedname | export-csv -path c:\temp\test.csv
These are just random notes and programs that may have incomplete descriptions. Any scripts or programs use at your risk
Showing posts with label Get. Show all posts
Showing posts with label Get. Show all posts
Friday, September 12, 2014
Saturday, August 23, 2014
Powershell - get all host files on domain.
Purpose: This script will search AD for Window computers and attempted to connect to each one. Then it will read the contents of the host file and write them to a csv file.
Note: This will take a while to run unless someone wants to make it multithreaded.
I just wrote this so there may need to be some bug fixes but in general it seemed to work.
#Read all host files and write to CSV file Import-Module ActiveDirectory $PATH = "c:\temp\hostfiles.csv" $myCol = @() $AllComputers = Get-ADComputer -Filter {OperatingSystem -Like "Windows*"} -Property * | Select -Expand Name foreach ($Computer in $AllComputers){ $i++ Write-Progress -activity "Scanning Machine $Computer " -status "Scanned: $i of $($AllComputers.Count)" -percentComplete (($i / $AllComputers.Count) * 100) Get-Content -Path "\\$Computer\c$\windows\system32\drivers\etc\hosts" | where {!$_.StartsWith("#")} | foreach { if ($_ -ne ""){ $data = $_ -split " ",2 $Hosts = New-Object -TypeName PSObject -Property @{ Host = $Computer IPAddress = $data[0].Trim() Node = $data[1].Trim() } } $myCol += $Hosts } $myCol |Select Host,Node,IPAddress| Export-Csv -Path $PATH -NoTypeInformation }
Subscribe to:
Posts (Atom)
Powershell: Microsoft Graph to add new roles to application registration
PowerShell Script Bulk add new roles to application registration in azure. Update $roles with ,Us...
-
Here is an excel document I created that will ping a list of nodes in column A and give results in column B. There are much better tools th...
-
#reads event logs for filter and exports to $Date = ( Get-Date ).AddMinutes(-30) $LogName = 'Security' $ProviderName = ...
-
Using Google Chrome or MS Edge: Disable Javascript post page load. 1. Open console in dev tools 2. press ctrl - alt - p 3. In the run dial...