Powershell - W7

Problems with your computer or anything else? We have a lot of skilled members that are very knowledgeable and might be of help!
User avatar
Cptn Merika
Posts: 1055
Joined: November 11th, 2014, 11:33 pm
Steam Profile: Cptn Merika

Powershell - W7

Post by Cptn Merika » May 22nd, 2017, 9:50 am

I am in need of someone who knows Powershell, and specifically some commands to help remedy my problem. I am need to query two active domain servers to run a search for IP and report back with computer name, AD Domain, and IP. The problem I am having is that if I send the code to someone else to run through normal Powershell (not ISE), the window will automatically close upon completion of the script. I have tried a pause-break code, but the most I can ever get is for the script to start, then "press enter to exit", then it finishes the script and closes (in that order). If you can help, that would be awesome :) Nobody really uses Powershell in my job, and google search is not helping as much as I thought it would.
word count: 138
191
"Be strong and courageous. Do not be afraid or terrified because of them, for the LORD your God goes with you; he will never leave you nor forsake you." - Deuteronomy 31:6

User avatar
shadowsbane
CC Member
CC Member
Posts: 6580
Joined: November 18th, 2008, 1:12 pm
Steam Profile: STEAM_0:0:9248565
Location: ::1
Contact:

Re: Powershell - W7

Post by shadowsbane » May 22nd, 2017, 10:17 am

What if you have it write the results to a file instead?

https://technet.microsoft.com/en-us/lib ... 76924.aspx
Last edited by shadowsbane on May 22nd, 2017, 10:19 am, edited 1 time in total. word count: 21

User avatar
Cptn Merika
Posts: 1055
Joined: November 11th, 2014, 11:33 pm
Steam Profile: Cptn Merika

Re: Powershell - W7

Post by Cptn Merika » May 22nd, 2017, 10:18 am

I was trying to search for that, but all I could find was a

get-process | out-file c:\blah\blah

I could only locate how to export the process and not the actual results. You have any ideas on this?
word count: 41
191
"Be strong and courageous. Do not be afraid or terrified because of them, for the LORD your God goes with you; he will never leave you nor forsake you." - Deuteronomy 31:6

User avatar
shadowsbane
CC Member
CC Member
Posts: 6580
Joined: November 18th, 2008, 1:12 pm
Steam Profile: STEAM_0:0:9248565
Location: ::1
Contact:

Re: Powershell - W7

Post by shadowsbane » May 22nd, 2017, 10:19 am

Can you show the script you have so far?
word count: 9

User avatar
Cptn Merika
Posts: 1055
Joined: November 11th, 2014, 11:33 pm
Steam Profile: Cptn Merika

Re: Powershell - W7

Post by Cptn Merika » May 22nd, 2017, 10:21 am

Here is the code. The Asterisks are severs that I have protected, so just imagine a server name there:

Import-Module ActiveDirectory

$ip = Read-Host "Enter the ip"
$servers = @('**.***.****.tx.us','****.****.***.tx.us')

foreach ($s in $servers) { Get-ADComputer -Filter {IPv4Address -eq $ip} -properties * -server $s | Select Name, Ipv4Address, @{n='Domain';e={$s}} }
word count: 53
191
"Be strong and courageous. Do not be afraid or terrified because of them, for the LORD your God goes with you; he will never leave you nor forsake you." - Deuteronomy 31:6

User avatar
shadowsbane
CC Member
CC Member
Posts: 6580
Joined: November 18th, 2008, 1:12 pm
Steam Profile: STEAM_0:0:9248565
Location: ::1
Contact:

Re: Powershell - W7

Post by shadowsbane » May 22nd, 2017, 10:23 am

I'm pretty sure you'd just turn it into this:

Import-Module ActiveDirectory

$ip = Read-Host "Enter the ip"
$servers = @('**.***.****.tx.us','****.****.***.tx.us')

foreach ($s in $servers) { Get-ADComputer -Filter {IPv4Address -eq $ip} -properties * -server $s | Select Name, Ipv4Address, @{n='Domain';e={$s}} } | out-file c:\blah\blah

I'm not certain, but that should take everything being done on that line and write it to a file.

http://www.computerperformance.co.uk/po ... utfile.htm
word count: 78

User avatar
Cptn Merika
Posts: 1055
Joined: November 11th, 2014, 11:33 pm
Steam Profile: Cptn Merika

Re: Powershell - W7

Post by Cptn Merika » May 22nd, 2017, 10:26 am

I try that, it creates a txt.file, but nothing in the file...just empty.
word count: 15
191
"Be strong and courageous. Do not be afraid or terrified because of them, for the LORD your God goes with you; he will never leave you nor forsake you." - Deuteronomy 31:6

User avatar
shadowsbane
CC Member
CC Member
Posts: 6580
Joined: November 18th, 2008, 1:12 pm
Steam Profile: STEAM_0:0:9248565
Location: ::1
Contact:

Re: Powershell - W7

Post by shadowsbane » May 22nd, 2017, 11:14 am

Probably means your command isn't returning a value.

Why do you need to specify the servers?
word count: 17

User avatar
Cptn Merika
Posts: 1055
Joined: November 11th, 2014, 11:33 pm
Steam Profile: Cptn Merika

Re: Powershell - W7

Post by Cptn Merika » May 22nd, 2017, 11:31 am

Because there are multiple different servers within our AD, and I need to only search in two of them.
word count: 19
191
"Be strong and courageous. Do not be afraid or terrified because of them, for the LORD your God goes with you; he will never leave you nor forsake you." - Deuteronomy 31:6

User avatar
shadowsbane
CC Member
CC Member
Posts: 6580
Joined: November 18th, 2008, 1:12 pm
Steam Profile: STEAM_0:0:9248565
Location: ::1
Contact:

Re: Powershell - W7

Post by shadowsbane » May 22nd, 2017, 12:12 pm

But are your servers not syncing? I guess I'm not understanding the purpose.
word count: 14

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest