Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
CzarChasm
Mar 14, 2009

I don't like it when you're watching me eat.
That's super helpful. I will check both of those things.

Had another related thing that I could use help with. After processing the attachments and pulling the various bits of information and saving that to a text file, I want to move the email from the Inbox to a "Processed" folder. Taking a quick look at Jethro's link - https://docs.microsoft.com/en-us/previous-versions/office/office-365-api/api/version-1.0/mail-rest-operations-v1#move-or-copy-messages I wonder if I can do this:

code:
POST 'https://outlook.office.com/api/v1.0/me/messages/{message_id}/copy
Content-Type: application/json
{
  "DestinationId": "Processed"
}
DELETE 'https://outlook.office.com/api/v1.0/me/messages/{message_id}
So, if I do this right it will put a copy in the Processed folder, then delete the message from the Inbox? Or can I just change the first line to
code:
POST 'https://outlook.office.com/api/v1.0/me/messages/{message_id}/move
And then not use the DELETE?

I really appreciate the help

Adbot
ADBOT LOVES YOU

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!
Yes, move usually has the same effect as copy and delete original. The verbiage "This creates a new copy of the message in the destination folder." is a little ambiguous, but I take that to mean that the message in the destination folder has a new message_id and the old message_id now refers to a message that doesn't exist (or is in some deleted location or status).

Pile Of Garbage
May 28, 2007



Definitely test it if at all possible first though. I've encountered countless "REST" APIs that don't work as expected and Microsoft doco isn't as good as it used to be (lol I know).

Submarine Sandpaper
May 27, 2007


I was told to do this after a review and don't think it's possible but want to confirm before ignoring it.

Old

code:
for each ($shithead in $shitheads)
$description = "Hey, $shithead, change this"
call-script -description $description.
Next shithead
It was suggested to remove "Hey, $shithead, change this" to a variable outside the loop to make it easier to read and modify

New
code:
$description = "Hey, $shithead, change this"
for each ($shithead in $shitheads)
call-script -description $description.
Next shithead
Obviously $description isn't being updated since it's outside of the loop. Any way to make this work?

Inspector_666
Oct 7, 2003

benny with the good hair
You can try scoping the variable with $global:description or $script:description depending on what's defining it? (I'd start with $script: if it's possible.)

mystes
May 31, 2006

Submarine Sandpaper posted:

I was told to do this after a review and don't think it's possible but want to confirm before ignoring it.

Old

code:
for each ($shithead in $shitheads)
$description = "Hey, $shithead, change this"
call-script -description $description.
Next shithead
It was suggested to remove "Hey, $shithead, change this" to a variable outside the loop to make it easier to read and modify

New
code:
$description = "Hey, $shithead, change this"
for each ($shithead in $shitheads)
call-script -description $description.
Next shithead
Obviously $description isn't being updated since it's outside of the loop. Any way to make this work?
You can do
code:
$description = 'Hey, $shithead, change this'
foreach ($shithead in $shitheads) {
    $ExecutionContext.InvokeCommand.ExpandString($description)
}
If you're just moving it one line outside of the loop it's probably better just to keep it how you have it to avoid confusion, though. Also, you have to be careful about scope when using ExpandString.

Happiness Commando
Feb 1, 2002
$$ joy at gunpoint $$

When I do Invoke-VMScript in PowerCLI - which feeds strings of code into a VM - and I need to dynamically update variables, I call the variable #variable and then to a $string.replace(#variable,$variable). For instance:
code:
foreach ($i in $ImportedCSV){
$VMName = $i.Name
$lanIP = $i.IP
[etc]

$Scriptblock = @'
Remove-NetIPAddress [stuff]
New-NetIPAddress - InterfaceIndex $Index -IPAddress "#LanIP" -PrefixLength 24 -DefaultGateway "#LanGW"
Set-DNSClientServerAddress -InterfaceIndex $Index -ServerAddresses #DNS1,#DNS2
Rename-Computer -NewName "#VMName"

'@

$Scriptblock = Scriptblock.Replace("#VMName",$VMName).Replace("#LanIP",$LanIP) [etc]
Invoke-VMScript -vm $VMName [etc]
}
Where those variables are read from an import-CSV that reads a manifest file of all the VMs I am building in that go-around. The beginning of the loop seems overly declaratory, and there's almost certainly a slicker way to do it, but it definitely reads the values again for each loop and then the string.replace object definitely inserts them into my code string each time. I've never seen Call-Script before, but possibly you could implement something like that?

Happiness Commando fucked around with this message at 18:31 on Nov 12, 2018

Submarine Sandpaper
May 27, 2007


Call Script was a generic and I should have written call-function,
$ExecutionContext.InvokeCommand.ExpandString($description) ended up working out. Hope I won't forget this one.

Submarine Sandpaper fucked around with this message at 18:51 on Nov 12, 2018

FISHMANPET
Mar 3, 2007

Sweet 'N Sour
Can't
Melt
Steel Beams
That seems way harder to read and understand compared to what you originally wrote.

Jowj
Dec 25, 2010

My favourite player and idol. His battles with his wrists mirror my own battles with the constant disgust I feel towards my zerg bugs.
What issue is moving the line out of the foreach block solving? I'm sort of confused as to what the end goal is.

code:
$shitheads = (
    "methanar",
    "a big pile of garbage",
    "jowj",
    "submarine sandpaper"
)
foreach($shithead in $shitheads)    {
    $someText = "hi this policy is dumb, how else will i know which $shithead to blame?"
    Write-Host $someText
}
this works just fine and is a fuckload more readable than setting the variable scope or anything outside of the loop unless i'm missing something.

Submarine Sandpaper
May 27, 2007


Jowj posted:

What issue is moving the line out of the foreach block solving? I'm sort of confused as to what the end goal is.

code:
$shitheads = (
    "methanar",
    "a big pile of garbage",
    "jowj",
    "submarine sandpaper"
)
foreach($shithead in $shitheads)    {
    $someText = "hi this policy is dumb, how else will i know which $shithead to blame?"
    Write-Host $someText
}
this works just fine and is a fuckload more readable than setting the variable scope or anything outside of the loop unless i'm missing something.
It's not solving an issue and the $ExecutionContext.InvokeCommand.ExpandString($description) has potential security concerns but I don't get paid enough to care or fight. I got to learn something new which is cool though. The next review may tell me to revert it due to the security concerns, which I'll then function it or do the replace like Commando.

Jowj
Dec 25, 2010

My favourite player and idol. His battles with his wrists mirror my own battles with the constant disgust I feel towards my zerg bugs.

Submarine Sandpaper posted:

It's not solving an issue and the $ExecutionContext.InvokeCommand.ExpandString($description) has potential security concerns but I don't get paid enough to care or fight. I got to learn something new which is cool though. The next review may tell me to revert it due to the security concerns, which I'll then function it or do the replace like Commando.

Ah. I've been there. Good luck and glad you're learning poo poo :)

mystes
May 31, 2006

The only real reason I can see is if you're going to move the string template to the top of the file as some sort of setting that can be easily edited later, but in that case it wouldn't be clear what variables would be in scope when you call ExpandString later, so that probably wouldn't be a great solution either.

Pile Of Garbage
May 28, 2007



mystes posted:

You can do
code:
$description = 'Hey, $shithead, change this'
foreach ($shithead in $shitheads) {
    $ExecutionContext.InvokeCommand.ExpandString($description)
}
If you're just moving it one line outside of the loop it's probably better just to keep it how you have it to avoid confusion, though. Also, you have to be careful about scope when using ExpandString.

DON'T DO THIS! Just create a string with a placeholder keyword and then use the Replace() method to insert the required string inside the loop:

code:
$Description = 'Hey, #SHITHEAD#, change this'

foreach ($Shithead in $Shitheads) {
    $description.Replace('#SHITHEAD#', $Shithead)
}
That said there's not really much benefit to moving the string outside of the loop apart from maybe separating logic and data.

Remember ya'll, everything in PowerShell is a .NET object which exposes all of the methods and properties available to that class in the .NET Framework. If you use the GetType() method on an object and then Google the type name you'll get the MSDN (Or Microsoft Docs now I gues) page which details all of the methods and properties available for that type.

mystes
May 31, 2006

Pile Of Garbage posted:

DON'T DO THIS! Just create a string with a placeholder keyword and then use the Replace() method to insert the required string inside the loop:
I assume you're saying "don't do this" because of security but the template string isn't being provided by the user here. It's the same as using printf in c or most server side html templating languages (almost all allow arbitrary code execution).

mystes fucked around with this message at 02:48 on Nov 13, 2018

Wicaeed
Feb 8, 2005
Anyone used the module here before? https://gallery.technet.microsoft.com/scriptcenter/PowerShell-FTP-Client-db6fe0cb/view/Discussions/4

It's useful (in that it works), but I'm having issues when dling large files (50+GB) over and over as the Get-FTPItem always overwrites the local file, even if they are the same and already present on local disk

MF_James
May 8, 2008
I CANNOT HANDLE BEING CALLED OUT ON MY DUMBASS OPINIONS ABOUT ANTI-VIRUS AND SECURITY. I REALLY LIKE TO THINK THAT I KNOW THINGS HERE

INSTEAD I AM GOING TO WHINE ABOUT IT IN OTHER THREADS SO MY OPINION CAN FEEL VALIDATED IN AN ECHO CHAMBER I LIKE

Right in the comments section a guy mentions using overwrite:$false, except that he gets a prompt asking him if he wants to overwrite files or not, though that's about a year old now and the module was updated a few months later, no clue if that behavior changed or not...

quote:

Overwrite:$false without prompt
1 Posts | Last post March 01, 2017

Written March 01, 2017
DK_1
Can we get a method of not overwriting that doesn't then give the promptforchoice option i.e. if I use the -overwrite:$false switch, then it shouldn't prompt and ask me if I want to overwrite a file? I have tried using -confirm:$false but this doesn't seem to work with the promptforchoice. This would make syncing folders easier for automation.

Judge Schnoopy
Nov 2, 2005

dont even TRY it, pal
I need to write an empty array to json instead of $null. What's the least hacky way to do this?

$json = @{}
[array]$array = @()
$json.add('Thing',$array)
$json | convertto-json

Results are:
"Thing" : $null

Desired results are:
"Thing" : [ ]

Toshimo
Aug 23, 2012

He's outta line...

But he's right!

Judge Schnoopy posted:

I need to write an empty array to json instead of $null. What's the least hacky way to do this?

$json = @{}
[array]$array = @()
$json.add('Thing',$array)
$json | convertto-json

Results are:
"Thing" : $null

Desired results are:
"Thing" : [ ]

ConvertTo-JSON is broken when pipelining. "ConvertTo-JSON $json" should do what you expect.

Pile Of Garbage
May 28, 2007



Judge Schnoopy posted:

I need to write an empty array to json instead of $null. What's the least hacky way to do this?

$json = @{}
[array]$array = @()
$json.add('Thing',$array)
$json | convertto-json

Results are:
"Thing" : $null

Desired results are:
"Thing" : [ ]

That snippet worked fine for me with PowerShell 5.1:

code:
PS C:\> $json = @{}
PS C:\> [array]$array = @()
PS C:\> $json.add('Thing',$array)
PS C:\> $json | convertto-json
{
    "Thing":  [

              ]
}
What version of PowerShell are you using? Also here's a more compact version:

code:
@{ 'Thing' = @() } | ConvertTo-Json

Toshimo posted:

ConvertTo-JSON is broken when pipelining. "ConvertTo-JSON $json" should do what you expect.

I've never had issues pipelining to ConvertTo-Json. The only instance where it appears to break is if you pass it an array but that's to be expected because JSON is a key/value format.

Edit: lol why did I say pipelining? It's piping, I'm a dingus.

Pile Of Garbage fucked around with this message at 16:06 on Nov 22, 2018

PBS
Sep 21, 2015
Edit: too slow

MJP
Jun 17, 2007

Are you looking at me Senpai?

Grimey Drawer
I have this script that successfully returns correct results against a csv of computer names. How do I make it show "X is True, Y is false" so I know which is which? When I run it, it just kinda runs randomly against the list, so it may not always be 1:1 against the CSV.

code:
# Read input file of computer names
   $computers = Get-Content C:\support\testnames.csv

   # Test for RPC reg key that will hold port config value
   invoke-command -computername $computers -scriptblock {test-path -Path "HKLM:\Software\Microsoft\RPC\Internet"}

The Fool
Oct 16, 2003


Instead of passing the array to Invoke-Command, wrap it in a For-Each so you know which computer it is running against, and it will run in the order specified by the csv.

code:
  # Read input file of computer names
  $computers = Get-Content C:\support\testnames.csv
  For-Each ($computer in $computers) {
    # Test for RPC reg key that will hold port config value
    $result = invoke-command -computername $computers -scriptblock {test-path -Path "HKLM:\Software\Microsoft\RPC\Internet"}
    Write-Host "$computer returned $result"
  }
e: seriously, 3 spaces? you monster

The Fool fucked around with this message at 19:34 on Nov 29, 2018

MJP
Jun 17, 2007

Are you looking at me Senpai?

Grimey Drawer

The Fool posted:

Instead of passing the array to Invoke-Command, wrap it in a For-Each so you know which computer it is running against, and it will run in the order specified by the csv.

So something like this? I had started out here, but was advised to run it in an array passed to invoke-command so it'd run faster.

code:
    # Read input file of computer names
    $computers = Get-Content C:\support\testnames.csv

    # Loop through each computer name in the array
    foreach ($computer in $computers) {

        # Test for RPC reg key that will hold port config
        $path = invoke-command -computername $computers -scriptblock {test-path -Path "HKLM:\Software\Microsoft\RPC\Internet"}

        # Report if templates are found or not
        If ($path -eq $true ) { Write-Host 'RPC port reg key is present on' $computer }
    
        Else { Write-Host 'RPC reg key is not present on' $computer }

    }

The Fool
Oct 16, 2003


Yeah, the for-each will be slower, but as you have observed, you lose control.

MJP
Jun 17, 2007

Are you looking at me Senpai?

Grimey Drawer
Unfortunately when I run that latest version, I get false results. it says that the key is present, but I have one server in there where the key is not present.

Is there no way for me to get names to results with it piped from an array, when everything returns correct results?

PBS
Sep 21, 2015

MJP posted:

Unfortunately when I run that latest version, I get false results. it says that the key is present, but I have one server in there where the key is not present.

Is there no way for me to get names to results with it piped from an array, when everything returns correct results?

Try this.

code:
# Read input file of computer names
$computers = Get-Content C:\support\testnames.csv

# Loop through each computer name in the array
foreach ($computer in $computers) {

	# Test for RPC reg key that will hold port config
	$path = invoke-command -computername $computer -scriptblock {test-path -Path "HKLM:\Software\Microsoft\RPC\Internet"}

	# Report if templates are found or not
	If ($path -eq $true ) { Write-Output 'RPC port reg key is present on' $computer }
	Else { Write-Output 'RPC reg key is not present on' $computer }

	Clear-Variable path
}
Personally I tend to not output sentences. Best way IMO is for your final output to just be two columns, Computer Name and True/False.

Edit: Comments are great, but aren't needed when what you are doing is fairly obvious. It depends on your audience ofc.

PBS fucked around with this message at 19:45 on Nov 29, 2018

MJP
Jun 17, 2007

Are you looking at me Senpai?

Grimey Drawer

PBS posted:

Try this.

code:
# Read input file of computer names
$computers = Get-Content C:\support\testnames.csv

# Loop through each computer name in the array
foreach ($computer in $computers) {

	# Test for RPC reg key that will hold port config
	$path = invoke-command -computername $computer -scriptblock {test-path -Path "HKLM:\Software\Microsoft\RPC\Internet"}

	# Report if templates are found or not
	If ($path -eq $true ) { Write-Output 'RPC port reg key is present on' $computer }
	Else { Write-Output 'RPC reg key is not present on' $computer }

	Clear-Variable path
}
Personally I tend to not output sentences. Best way IMO is for your final output to just be two columns, Computer Name and True/False.

Edit: Comments are great, but aren't needed when what you are doing is fairly obvious. It depends on your audience ofc.

The comments are more for my own sanity.

How would I output as columns? I'm happy to do so. As of now it outputs it like this, which is no good:

RPC port reg key is present on
Contoso1
RPC reg key is not present on
Contoso2
RPC port reg key is present on
Contoso-CLUS1
RPC port reg key is present on
ContosoMSQCLUS1

MJP fucked around with this message at 19:53 on Nov 29, 2018

The Fool
Oct 16, 2003


You could do the cheap way:
code:
Write-Host "$computer, $path"
Or the right way:
code:
#at beginning of script
$output | Select-Object Computer,Result

#put this next line inside your for-each, after your invoke-command
$output.Computer = $computer
$output.Result = $path

#then, after the for-each
$output | Export-CSV "destinationpathto.csv" -NoTypeInformation

The Fool fucked around with this message at 20:03 on Nov 29, 2018

PBS
Sep 21, 2015

MJP posted:

The comments are more for my own sanity.

How would I output as columns? I'm happy to do so. As of now it outputs it like this, which is no good:

RPC port reg key is present on
Contoso1
RPC reg key is not present on
Contoso2
RPC port reg key is present on
Contoso-CLUS1
RPC port reg key is present on
ContosoMSQCLUS1

You can get them all on one line fairly easily,

Write-Output 'Test' $test will get you two lines
Write-Output ('Test ' + $test) will get you one

If you just wanted columns for your output, this is how I'd do it.

code:
# Read input file of computer names
$computers = Get-Content C:\support\testnames.csv

#If you want to store the output in an array
$finalOutput = @()

# Loop through each computer name in the array
foreach ($computer in $computers) {
	
	$tmpOutput = New-Object psobject
	
	# Test for RPC reg key that will hold port config
	$path = invoke-command -computername $computer -scriptblock {test-path -Path "HKLM:\Software\Microsoft\RPC\Internet"}

	$tmpOutput | Add-Member -NotePropertyName 'Computer' -NotePropertyValue $computer
	$tmpOutput | Add-Member -NotePropertyName 'Result' -NotePropertyValue $path
	#If you just want to write to console
	$tempOutput
	#If you want to store it in an array
	$finalOutput += $tmpOutput
	Clear-Variable path
}

#Output of entire array
$finalOutput
My style is a little more verbose than necessary, there's always a number of ways to arrive at the same answer. I rarely just output to console and almost always write to custom objects for later use, my example is written with that in mind.

PBS fucked around with this message at 20:09 on Nov 29, 2018

MJP
Jun 17, 2007

Are you looking at me Senpai?

Grimey Drawer

PBS posted:

You can get them all on one line fairly easily,

Write-Output 'Test' $test will get you two lines
Write-Output ('Test ' + $test) will get you one

If you just wanted columns for your output, this is how I'd do it.

code:
# Read input file of computer names
$computers = Get-Content C:\support\testnames.csv

#If you want to store the output in an array
$finalOutput = @()

# Loop through each computer name in the array
foreach ($computer in $computers) {
	
	$tmpOutput = New-Object psobject
	
	# Test for RPC reg key that will hold port config
	$path = invoke-command -computername $computer -scriptblock {test-path -Path "HKLM:\Software\Microsoft\RPC\Internet"}

	$tempOutput | Add-Member -NotePropertyName 'Computer' -NotePropertyValue $computer
	$tempOutput | Add-Member -NotePropertyName 'Result' -NotePropertyValue $path
	#If you just want to write to console
	$tempOutput
	#If you want to store it in an array
	$finalOutput += $tempOutput
	Clear-Variable path
}

#Output of entire array
$finalOutput
My style is a little more verbose than necessary, there's always a number of ways to arrive at the same answer.

Yours just gives an error for each line in the CSV:

code:
Add-Member : Cannot bind argument to parameter 'InputObject' because it is null.
At line:16 char:16
+ ... empOutput | Add-Member -NotePropertyName 'Result' -NotePropertyValue  ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Add-Member], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Co 
   mmands.AddMemberCommand

The Fool posted:

You could do the cheap way:
code:
Write-Host "$computer, $path"
Or the right way:
code:
#at beginning of script
$output | Select-Object Computer,Result

#put this next line inside your for-each, after your invoke-command
$output.Computer = $computer
$output.Result = $path

#then, after the for-each
$output | Export-CSV "destinationpathto.csv" -NoTypeInformation

I'm sorry, but I'm totally confused by where you want me to put these. I don't know if this is what you meant.

code:
# Read input file of computer names
$computers = Get-Content C:\support\testnames.csv
$output | Select-Object Computer,Result
# Loop through each computer name in the array
foreach ($computer in $computers) $output | Export-CSV "destinationpathto.csv" -NoTypeInformation
{

	# Test for RPC reg key that will hold port config
	$path = invoke-command -computername $computer -scriptblock 
$output.Computer = $computer
$output.Result = $path
{test-path -Path "HKLM:\Software\Microsoft\RPC\Internet"}

	# Report if templates are found or not
	If ($path -eq $true ) { Write-Output 'RPC port reg key is present on' $computer }
	Else { Write-Output 'RPC reg key is not present on' $computer }

	Clear-Variable path
}

PBS
Sep 21, 2015

MJP posted:

Yours just gives an error for each line in the CSV:

Yeah, I just fixed a mistake with my variable names. Check my edited post and try again. (Or just search/replace "$tempObject" with "$tmpObject")

nielsm
Jun 1, 2009



Wouldn't this work?
code:
invoke-command -computername $computers -scriptblock {
    [PSCustomObject]@{
        "Exists" = Test-Path -Path "HKLM:\Software\Microsoft\RPC\Internet";
        "Computer" = [System.Environment]::MachineName
    }
}
In fact, I'm pretty sure PS remoting automatically decorates returned objects with note properties containing the host that produced it.

nielsm fucked around with this message at 20:15 on Nov 29, 2018

The Fool
Oct 16, 2003


Because I felt like wasting time at work:

code:
invoke-command -computername (Get-Content C:\support\testnames.csv) -scriptblock {test-path -Path "HKLM:\Software\Microsoft\RPC\Internet"} | Select-Object @{ Name="Computer"; Expression = {$_.PSComputerName}}, @{ Name = "Result"; Expression = {$_}}

nielsm posted:

In fact, I'm pretty sure PS remoting automatically decorates returned objects with note properties containing the host that produced it.


It does, it's the PSComputerName member, I had to look it up

PBS
Sep 21, 2015
Yeah, those are certainly more elegant solutions.

The Fool
Oct 16, 2003


MJP posted:

I'm sorry, but I'm totally confused by where you want me to put these. I don't know if this is what you meant.

I wasn't very clear, and was wrong anyway. I will fix it in this space.

edit:

If you have a thing returning results like your script, usually what you want to do is to build a custom object that you can easily export to a CSV.

There are a number of different ways to create custom objects in Powershell, but I like using Select-Object for simple objects since I feel it is easier to read.

For Example, this creates a custom object with the properties "Computer" and "Result"
code:
$result | Select-Object Computer,Result
Used in a script, it would look something like this:
code:
$results = @() #this creates an empty array

For-Each ($computer in $computers) {
  $result = invoke-command -computername $computer -scriptblock {test-path -Path "HKLM:\Software\Microsoft\RPC\Internet"}
  $result | Select-Object Computer,Result # creates our custom object with the properties you want
  $result.Computer = $computer # sets the computer name
  $result.Result = $result # sets the result

  $results += $result  #append custom object to array
}

$results | Export-CSV "destination.csv" -NoTypeInformation # write results to csv for review

The Fool fucked around with this message at 20:37 on Nov 29, 2018

skipdogg
Nov 29, 2004
Resident SRT-4 Expert

I would have done it like PBS posted, I'm not very good at PS or elegant, but I did something similar a while back and this is what I did. I usually use import-csv for actual CSVs with headers, and get-content with txt files with single entries per line, but I'm guessing that CSV is single entry per line as well.

code:
$computers = get-content C:\support\testnames.csv
$array= @()

foreach ($computer in $computers){

$pathresult = Test-Path -Path "HKLM:\Software\Microsoft\RPC\Internet"

$results = New-Object -TypeName PSObject -Property @{
"Hostname" = $computer
"Path Exists" = $pathresult
}
$array += $results

}
$array | Export-CSV c:\support\Pathresults.csv -NoTypeInformation

It should pop out a CSV report for you. The columns on my test report are backwards, and I don't know how to fix that, but that's an easy fix in excel. I'm sure there are 50 different better ways to do this, but it should work.

MJP
Jun 17, 2007

Are you looking at me Senpai?

Grimey Drawer
PBS' latest iteration is running. It's taking its time but it ran with columns against the test script, now it's running against 103 hosts.

Edit: Completed, and the vast majority (90 machines D: ) threw errors that the server name could not be resolved. Should I be redoing this against FQDNs rather than just hostnames?

MJP fucked around with this message at 20:48 on Nov 29, 2018

The Fool
Oct 16, 2003


Yes

Adbot
ADBOT LOVES YOU

PBS
Sep 21, 2015

MJP posted:

PBS' latest iteration is running. It's taking its time but it ran with columns against the test script, now it's running against 103 hosts.

Edit: Completed, and the vast majority threw errors that the server name could not be resolved. Should I be redoing this against FQDNs rather than just hostnames?

Really depends on your network, if DNS & Search Suffixes are properly setup it shouldn't matter. To answer the question it's usually better to be as explicit as you can be.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply