Quantcast
Channel: Windows PowerShell forum
Viewing all 21975 articles
Browse latest View live

azure ad and reset password for user

$
0
0

hello,

is it possible to change a user's password in azure ad true powershell?

i use the azure cloud shell and i want to know witch command's i must use if it is possible.

thanx


Remove-Item command for all window profiles

$
0
0

I wanting to delete all files and folders from the desktop under all window profiles. 

I also want to keep a few .ppt that have specific names for under each profile.  Below is what I have tried and using -exclude "AppV" as an example.  Nothing works.

Remove-item -Path C:\$users\desktop\*.* -exclude "AppV" -force -erroraction 'silentlycontinue'

Remove-item c:\users\wcampbell\desktop\* -exclude "AppV" -force -erroraction 'silentlycontinue'

Remove-item C:\$users\desktop -exclude "AppV" -force -erroraction 'silentlycontinue'

Using get-adUser with Multiple Filter items

Connect/Dissconect ISCSI connections

$
0
0

I'm working on a powershell script that exports specific VMs from a given text file. What I would like to do now when I run this script from a scheduled task is to have the script connect to a ISCSI conection before the export happens and disconnect the ISCSI connection after all the exports are done.

Any help will be greatly appreciated!


Export powershell changes to csv format

$
0
0

I am running this script to add all employee IDs into my active directory 

>> Import-Module ActiveDirectory
>> $Users = Import-Csv -Path C:\excelfiles\importtest.csv
>> Get-Content -Path C:\excelfiles\importtest.csv | ft
>> sleep 10
>> foreach ($User in $Users)
>> {
>> Set-ADUser -identity $User.SamAccountName -replace @{"employeeID" = $User.employeeID} -verbose
>> } 
>> $results | Export-Csv -path c:\excelfiles\export.csv

The last part of it is my attempt to pull out the results into a csv file but no luck, it exports the file but with no data. Any idea of what im doing wrong? ive also tried it with was and same results.....

>>Import-Module ActiveDirectory
>>$Users = Import-Csv -Path C:\excelfiles\importtest.csv
>>Get-Content -Path C:\excelfiles\importtest.csv | ft
>>sleep 10
>>foreach ($User in $Users)
>>{
>>Set-ADUser -identity $User.SamAccountName -replace @{"employeeID" = $User.employeeID} -verbose | Export-Csv -path >>C:\excelfiles\export.csv -Append
>>}


How many profile there is in a computer?

$
0
0

My situatio is:

I need to get via network how many profiles there is in a computer with following information (bellow)  and save in a text file:

- Last time that the user logon;

- IP of the computer;

- Profile names (domain and local);

I've this script via powersheel that I found on internet, but this script only get information local computers and no of a remote computer.

$a = read-host "computername" 

$data = @() 

$NetLogs = Get-WmiObject Win32_NetworkLoginProfile -ComputerName $a
foreach ($NetLog in $NetLogs) { 
if ($NetLog.LastLogon -match "(\d{14})") { 
$row = "" | Select Name,LogonTime 
$row.Name = $NetLog.Name 
$row.LogonTime=[datetime]::ParseExact($matches[0], "yyyyMMddHHmmss", $null) 
$data += $row 


$data

You cannot call a method on a null-valued expression.

$
0
0

Can someone please help me fix the error below. 

 

You cannot call a method on a null-valued expression.
At C:\SHAREGATE\CreateFoldersInODFB.ps1:88 char:2
+     $newFolder = $spoFolder.Folders.Add($Folder1)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Cannot find an overload for "Load" and the argument count: "1".
At C:\SHAREGATE\CreateFoldersInODFB.ps1:89 char:2
+     $web.Context.Load($newFolder)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

Here is the code

The full script can be found here

https://gallery.technet.microsoft.com/office/This-script-will-create-941c58af#content

Thanks in advanced. 

Loop in continue to check if my network cards are UP

$
0
0

Hi,

I would like to create a script (a continue loop) to check if my networks cards are always UP. 

How can I do it please using :

$NIC1 = (Get-NetAdapter -Name "NIC1").Status
$NIC2 = (Get-NetAdapter -Name "NIC2").Status

Do nothing 
While {
         (($NIC1 -eq "Up") -and ($NIC2 -eq "Up"))
         }

Thank you


Powershell Error with Register-ClusteredScheduledTask function

$
0
0

Hello !

I'm facing an issue with the custom script i'm writing, it basically create a scheduled action, then create a trigger, then create a registered clustered task as wrote in the documentation here https://docs.microsoft.com/en-us/powershell/module/scheduledtasks/Register-ClusteredScheduledTask?view=win10-ps#parameters

I wrote 3 functions to automate action creation, trigger creation and register the task.

Here's my 3 functions code :

function CreateAction {
    Param
    ( 
        [Parameter(Mandatory = $true, Position = 0)]$script,
        [Parameter(Mandatory = $false, Position = 1)]$exec_dir
    )

    $action1 = "New-ScheduledTaskAction -Execute $script"
    if ($exec_dir) { $action1 = $action1 + " -WorkingDirectory " + $exec_dir }
    Invoke-Expression $action1   
}


function CreateTrigger {
    Param
    (
        [Parameter(Mandatory = $true, Position = 0)]$freq,
        [Parameter(Mandatory = $true, Position = 1)]$starttime
      
    )   
    $trigger = 'New-ScheduledTaskTrigger ' + $freq + ' -At ' + $starttime
    Invoke-Expression $trigger  
    }


function CreateTask {
    Param
    (
        [Parameter(Mandatory = $true, Position = 0)]$taskname,
        [Parameter(Mandatory = $true, Position = 1)]$action,
        [Parameter(Mandatory = $true, Position = 2)]$trigger,
        [Parameter(Mandatory = $true, Position = 3)]$resource_name           
    ) 

    $task = "Register-ClusteredScheduledTask -TaskName $taskname -TaskType ResourceSpecific -Action  $action  -Trigger $trigger -Resource $resource_name"
    Invoke-Expression $task | Out-Null
}

Here's how i use them :

$ActionCopylog = CreateAction $task_script_copylog $task_dir_copylog

$TriggerCopylog = CreateTrigger $trigger_freq $task_starttime_copylog

$TaskCopylog = CreateTask $task_name_copy_log $ActionCopylog $TriggerCopylog $base_SID

2 of my 3 functions work well (CreateAction and CreateTrigger) BUT i always have the same error while the CreateTask function is used :

Register-ClusteredScheduledTask : Cannot bind argument to parameter 'Action', because PSTypeNames of the argument do not match the PSTypeName required by the parameter: 
Microsoft.Management.Infrastructure.CimInstance#MSFT_TaskAction.
At line:1 char:95+ ... pyLog -TaskType ResourceSpecific -Action  MSFT_TaskExecAction  -Trigg ...+                                               ~~~~~~~~~~~~~~~~~~~+ CategoryInfo          : InvalidArgument: (:) [Register-ClusteredScheduledTask], ParameterBindingArgumentTransformationException+ FullyQualifiedErrorId : MismatchedPSTypeName,Register-ClusteredScheduledTask

When i do a getType() of my 3 variables, i get the same type as the 3 in the Microsoft examples :

PS C:\Users\xxx\Desktop> $Action.GetType()
IsPublic IsSerial Name                                     BaseType                                                                  
-------- -------- ----                                     --------                                                                  
True     True     CimInstance                              System.Object                                                             


PS C:\Users\xxx\Desktop> $ActionCopyLog.GetType()
IsPublic IsSerial Name                                     BaseType                                                                  
-------- -------- ----                                     --------                                                                  
True     True     CimInstance                              System.Object                                                             


PS C:\Users\xxx\Desktop> $Trigger.GetType()
IsPublic IsSerial Name                                     BaseType                                                                  
-------- -------- ----                                     --------                                                                  
True     True     CimInstance                              System.Object                                                             


PS C:\Users\xxx\Desktop> $TriggerCopylog.GetType()
IsPublic IsSerial Name                                     BaseType                                                                  
-------- -------- ----                                     --------                                                                  
True     True     CimInstance                              System.Object                                                             

Any idea what missing ?

Thanks !

 



Merge two arrays

$
0
0

I have the following code, which creates two arrays with different headers. I want to merge those two arrays into a single array called $array, with the data from all four headers and their data:

$array = @()
$array1 = @()
$array2 = @()

$path = "\\sever\path\script"
$date = Get-Date -Format d
$csvfile = "$path\$date.csv"

$array1 = Get-ChildItem -Path $path -Filter *.xlsx | Import-Excel | select @{Name = 'Brugernavn'; Expression = {$_.'Seneste bruger'}}, "Computernavn"

$array2 = foreach($username in $array1.Brugernavn)
        {
        Get-ADUser $username | select @{Name = 'FuldeNavn'; Expression = {$_.'Name'}}, @{Name = 'Email'; Expression = {$_.'UserPrincipalName'}}
        }



Get adgroupmember and find aduser from diffrent domain

$
0
0

My requirement is need to get adgrouopmember from domain A and need to search the users in domain B.

I'm trying with below command and it is working if the output file without double quotes.

Ex: if the output displayname is peter john then working

but unbale to get if it is "peter john". unable to export the list without double quotes 

Get-ADGroupMember -identity "GROUPNAME" | Get-ADUser -Property DisplayName | Select DisplayName | Export-Csv C:\output.csv

$UserNamesList = get-content -path "C:\output.csv "

foreach ($name in $UserNamesList)

{Get-ADUser -filter { DisplayName -eq $name } -Properties * -Server diffdomainserver:3268 | Select-Object Name}

Instade of two output i'm trying to get the list directly from the group but im getting the below error.

$UserNamesList = Get-ADGroupMember -identity "GROUPNAME" | Select Nameforeach

($name in $UserNamesList)

{Get-ADUser -filter { DisplayName -eq $name } -Properties * -Server diffdomainserver:3268 | Select-Object Name}


Get-ADUser : Invalid type 'System.Management.Automation.PSCustomObject'.
Parameter name: displayName
At line:1 char:35
+ foreach ($name in $UserNamesList){Get-ADUser -filter { DisplayName -eq $name } - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-ADUser], ArgumentException
    + FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.ArgumentException,Microsoft.ActiveDirectory.Management.Commands.GetADUser

Export to csv not working in foreach loop

$
0
0

Need your support with the script below.

What I try to do:

- Connect to Power BI Service to gather some data via Rest Api (https://docs.microsoft.com/en-us/rest/api/power-bi/groups/getgroupusers#code-try-0)

- Loop through the Api's Urls replacing part of them with the values from: 

C:\WorkspaceId.csv
WorkspaceID
  c3ac3fd4-ad18-442d-acb6-0da3a63ce3b0
  b0df3876-22d3-4df8-87fd-269c14c911c3
  622e598c-a72e-475a-b779-c5c06dd8c9ec

- then I wanna save the output to:

"C:\output.csv"

Script:

Connect-PowerBIServiceAccount

$WorkspaceFile = Import-CSV -Path "C:\WorkspaceId.csv"
$ExportPath = "C:\output.csv"

$Output = foreach ($Line in $WorkspaceFile)
    {
    $Item = $Line.WorkspaceID
    $url =  "https://api.powerbi.com/v1.0/myorg/groups/"+$Item+"/users"
    Invoke-PowerBIRestMethod -Url $url -Method Get 
    }

$Output | Export-Csv $ExportPath

Disconnect-PowerBIServiceAccount

As a result I want the output for each iteration to be saved in a the same csv.

There is a problem with looping or exporting to csv. It doesn't work.

I am Powershell beginner so please to have this in mind.

Thanks in advance

powershell command to remove permission for a group

$
0
0

Hi,

Group scope is GLOBAL and  Group type is SECURITY. 

Permission "Write-ms-Mcs-AdmPwd"  needs to be removed for many groups.  Is there a way to remove it using powershell command. please help


Regards, Boopathi

Im trying to send to files with winscp

$
0
0

Hi All,

Im trying to send two files with winscp to an sftp server. I tried so many things. Im lost.

It need to find the files created in the last 8 hours and then send them to the sftp. I only can do one file.

try
{
    # Load WinSCP .NET assembly
    Add-Type -Path 'C:\Program Files (x86)\WinSCP\WinSCPnet.dll'
    # Setup session options
    $sessionOptions = New-Object WinSCP.SessionOptions -Property @{    Protocol = [WinSCP.Protocol]::Sftp    HostName = "*************"    UserName = "*************"    Password = "*********"    SshHostKeyFingerprint = "ssh-rsa 2048 ******"
    }
    $session = New-Object WinSCP.Session

    if (-not (get-psdrive K -ErrorAction SilentlyContinue)) {
    $pass="********"|ConvertTo-SecureString -AsPlainText -Force
    $Cred = New-Object System.Management.Automation.PsCredential('********\*******',$pass)
    New-PSDrive -name K -Root \\********\test -Credential $cred -PSProvider filesystem -Persist
    }
    try
    {
        # Connect
        $session.Open($sessionOptions)
        $localPath = "K:\"
        $remotePath = "/incoming/*********/"
        # Select the most recent file.
        # The !$_.PsIsContainer test excludes subdirectories.
        # With PowerShell 3.0, you can replace this with -File switch of Get-ChildItem. 
        $latest =
            Get-ChildItem -Path $localPath |
            Where-Object {$_.CreationTime -gt $(get-date).addhours(-8)} |
            Sort-Object LastWriteTime -Descending |
            Select-Object -First 1
        # Any file at all?
        if ($latest -eq $Null)
        {
            Write-Host "No file found"
            exit 1
        }
        # Upload the selected file
        $sourcePath = Join-Path $localPath $latest.Name
        $session.PutFiles(
            [WinSCP.RemotePath]::EscapeFileMask($sourcePath),
            [WinSCP.RemotePath]::Combine($remotePath, "*")).Check()
    }
    finally
    {
        # Disconnect, clean up
        $session.Dispose()
    }
    exit 0
}
catch
{
    Write-Host "Error: $($_.Exception.Message)"
    exit 1
}

How do I parse through multiple inputs?

$
0
0

Morning! So I have a PowerShell server build script that does the following as part of it:

Asks if you want to add an AD group to Administrators on the server you're building, or if you want to search a different server for the groups and users in Administrators and use one of those.

 1. If you want to add an AD group to Administrators, it asks you what
    AD group and saves that in a variable ($OSAdministrators)
 2. If you want to search a server for the groups and users, you put in
    the server, it searches, and displays the results of all groups and
    users in Administrators. It then asks you to type out which group
    you want to use, and saves that in the same variable
    ($OSAdministrators).

Example code for #2:

    $OSAdministratorsSearchHost = Read-Host "Enter the hostname of the server to search for Administrators groups"

    function Get-LocalAdmin {
        $admins = Gwmi win32_groupuser –Computer $OSAdministratorsSearchHost
        $admins = $admins |? {$_.GroupComponent –like '*"Administrators"'}
        $admins |% {
            $_.partcomponent –match “.+Domain\=(.+)\,Name\=(.+)$” > $nul
            $matches[1].trim('"') + “\” + $matches[2].trim('"')
            }
        }
    Get-LocalAdmin

    $OSAdministrators = Read-Host "Enter the name of the AD group from the list above to add to Administrators on the new server; press Enter to skip"

This works great if you only want to add 1 group. The problem is that sometimes you may have a couple groups you'd like to add to a server, and I'm not sure how to deal with that. For example, for #2 above I'd love to have it like this:

    $OSAdministrators = Read-Host "Enter the name(s) of the AD group(s) from the list above to add to Administrators on the new server. If entering multiple, separate them with a comma (e.g. "Server Group 1,Server Group 2")"

But I'm not sure how to break out "Server Group 1" and "Server Group 2" and use that later in my code where it actually adds the group to Administrators on the server you're building:

    $DomainName = "[where the domain FQDN would be]"
    $AdminGroup = [ADSI]"WinNT://$HostName/Administrators,group"
    $Group = [ADSI]"WinNT://$DomainName/$OSAdministrators,group"
    $AdminGroup.Add($Group.Path)

I've tried searching online, but the way I'm searching it's not finding anything for this specific use-case, or the solutions seem to be overly complicated for what I'm trying to do (I'm talking 30 lines of code just to parse through inputs). I would think there'd be a simpler way I'm just missing.

Any direction would be greatly appreciated. Thanks!

How to refresh a PowerBI Report using Invoke-RestMethod?

$
0
0

we are using the following command to try refreshing a report:

before refreshing, we test to see if the report API works good

Invoke-RestMethod -UseDefaultCredentials -uri "https://pbi.dev.company.com/reports/api/v2.0/CacheRefreshPlans(CC1A4569-B890-9633-7H33-908762F54436)" -verbose

that returns for us the something, so we know that part is working

VERBOSE: received 946-byte response of content type application/json; odata.metadata=minimal; odata.streaming=true

@odata.context      : https://pbi.dev.company.com/reports/api/v2.0/$metadata#CacheRefreshPlans/$entity
Id                  : CC1A4569-B890-9633-7H33-908762F54436
Owner               : user
Description         :
CatalogItemPath     : /Prototypes/Test/TestReport
EventType           : DataModelRefresh
Schedule            : @{ScheduleID=; Definition=}
ScheduleDescription :
LastRunTime         : 2019-09-03T17:19:18.143-04:00
LastStatus          : Data Refresh failed, contact the administrator, SessionId: 123456-874356-8738764
ModifiedBy          : user
ModifiedDate        : 2019-08-29T16:55:29.173-04:00
ParameterValues     : {} 

now we found this command that supposedly would refresh a report, but we dont see any changes/updates made to a report (i.e. if we delete a record in the database it still keeps showing up on the report)

Invoke-RestMethod -UseDefaultCredentials -method POST -uri "https://pbi.dev.company.com/reports/api/v2.0/CacheRefreshPlans(CC1A4569-B890-9633-7H33-908762F54436)/Model.Execute" -verbose

this returns 0 bytes, and no response. so we're assuming that Model.Execute is not the right command or we are still missing something...

0-byte payload VERBOSE: received 0-byte response of content type

try remote from linux powershell wot einods server

$
0
0

I have done the following steps on Windows server

winrmsetwinrm/config/Service/Auth@{Basic="true"}

winrmsetwinrm/config/Service@{AllowUnencrypted="true"}

on linux centos 7

in powershell I tryed

$creds = Get-Credential

Enter-PSSession -ComputerName target server ip  -Authentication Negotiate -Credential $creds

get the following error  

Enter-PSSession : Connecting to remote server target server ip failed with the following error message : acquiring creds with username only failed Unspecified GSS failure.  Minor code may provide more information SPNEGO cannot find mechanisms to negotiate For more information, see the about_Remote_Troubleshooting Help topic.

Not sure what I am missing please assist

Powershell -ExecutionPolicy ByPass in script

$
0
0

Hi,

I have a powershell script and I don't want to change the ExecutionPolicy on my machine. When I run PS command line and type the following command:

 powershell -ExecutionPolicy ByPass -File test.ps1
the script will run but I dont know how to add this command into my powershell script because I want to run it from context(linke in image) menu when I right click on this powershell script.



PowerShell code to delete all the unique permission associated to a sub-site.

$
0
0

PowerShell code to delete all the unique permissions associated to a sub-site.

 

asnp *sh*

$webUrl="https://XXXXX/sites/opstest/Aditest/"
 $web = Get-SPweb  $webUrl   
 if($Web.HasUniqueRoleAssignments -ne $null)

{

#delete all unique permissions

}

PowerShell : Ping Test and Traceroute from particular source to list of destination IPs

$
0
0

Hello All,

I am working on a script from which all the source IPs must do a ping and traceroute to all provided destination IPs. And the output should be directed to CSV.

Below is the script. I don't know how to make the traceroute happen from the source.

I need the output as 

Source  Destination       IP               PingStatus

S1             D1                  x.x.x.x           Up

S1             D2                  x.x.x.x           Down

S2             D1                  x.x.x.x           Up

S2             D2                  x.x.x.x           Up

Once all these ping tests are completed, the Trace route details needs to be populated below these even if it is up and down.

I tried to populate in a formatted table, but the values are not getting out.

PS C:\Magesh> Test-NetConnection ServerNAME -TraceRoute


ComputerName           : ServerNAME
RemoteAddress          : 10.10.10.10
InterfaceAlias         : Ethernet0
SourceAddress          : SourceServer
PingSucceeded          : True
PingReplyDetails (RTT) : 297 ms
TraceRoute             : 10.10.10.1
10.10.10.2
10.10.10.3
...........
10.10.10.10

Kindly request to help me on this.

Script 1:

[CmdletBinding()]
param (
        [parameter(Mandatory=$true)]
        [string]$targetIP,
        [parameter(Mandatory=$true)]
        [string]$sourceIP
       )
$targets = get-content -path $targetIP | foreach{ $_.Trim() }
$source = get-content -Path $sourceIP | foreach{ $_.Trim() }

$time = Get-Date -Format d

FOREACH ($target in $targets) {

    $result = Test-Connection -Source $source -ComputerName $target
    
    IF (-not ($result)) {
           
           Write-host "$target Failed to respond at $time. Starting Traceroute now...." | Out-File "C:\Tracey.csv" -Append
           Tracert $target | Out-File "C:\Tracey.csv" -Append
           }
    ELSE 
    {Write-Host "$target responds to pings." 
     Tracert $target | Out-File "C:\Tracey.csv" -Append}
    }

Script 2 :

[CmdletBinding()]
param (
        [parameter(Mandatory=$true)]
        [string]$targetIP,
        [parameter(Mandatory=$true)]
        [string]$sourceIP
       )
$targets = get-content -path $targetIP | foreach{ $_.Trim() }
$source = get-content -Path $sourceIP | foreach{ $_.Trim() }
#$ErrorActionPreference = 'SilentlyContinue'

$headerObj  = New-Object -Type PSObject
Add-Member -InputObject $headerObj -MemberType NoteProperty -Name Source -value ""
Add-Member -InputObject $headerObj -MemberType NoteProperty -Name Server -value ""
Add-Member -InputObject $headerObj -MemberType NoteProperty -Name State -value ""
Add-Member -InputObject $headerObj -MemberType NoteProperty -Name ComputerName -value ""
Add-Member -InputObject $headerObj -MemberType NoteProperty -Name RemoteAddress -value ""
Add-Member -InputObject $headerObj -MemberType NoteProperty -Name SourceAddress -value ""
Add-Member -InputObject $headerObj -MemberType NoteProperty -Name PingSucceeded -value ""
Add-Member -InputObject $headerObj -MemberType NoteProperty -Name TraceRoute -value ""
$headerObj| export-csv -Force -path ServerStatus.csv

foreach ($target in $targets)
{

    $result = Test-Connection -Source $source -ComputerName $target -Count 1

    if($result -eq "True")

    {

    $route = Test-NetConnection $target –TraceRoute | Select-Object -Property ComputerName,RemoteAddress,SourceAddress,PingSucceeded,TraceRoute
        
        foreach($dat in $route){
            $OutputObj  = New-Object -Type PSObject            
            $OutputObj | Add-Member –MemberType NoteProperty –Name Source –Value $source
            $OutputObj | Add-Member –MemberType NoteProperty –Name Server –Value $target            
            $OutputObj | Add-Member –MemberType NoteProperty –Name State –Value "Up"
	        $OutputObj | Add-Member –MemberType NoteProperty –Name ComputerName –Value $($dat.ComputerName)
            $OutputObj | Add-Member –MemberType NoteProperty –Name RemoteAddress –Value $($dat.RemoteAddress)
            $OutputObj | Add-Member –MemberType NoteProperty –Name SourceAddress –Value $($dat.SourceAddress)
            $OutputObj | Add-Member –MemberType NoteProperty –Name PingSucceeded –Value $($dat.PingSucceeded)
            $OutputObj | Add-Member –MemberType NoteProperty –Name TraceRoute –Value $($dat.TraceRoute -join(','))
            #$OutputObj
            $OutputObj | export-csv -append -path -Force ServerStatus.csv
            

    } 
    }
    else 
    { 
            $OutputObj  = New-Object -Type PSObject            
            $OutputObj | Add-Member –MemberType NoteProperty –Name Source –Value $source           
            $OutputObj | Add-Member –MemberType NoteProperty –Name Server –Value $target            
            $OutputObj | Add-Member –MemberType NoteProperty –Name State –Value "Down"
	        $OutputObj | Add-Member –MemberType NoteProperty –Name ComputerName –Value $($dat.ComputerName)
            $OutputObj | Add-Member –MemberType NoteProperty –Name RemoteAddress –Value $($dat.RemoteAddress)
            $OutputObj | Add-Member –MemberType NoteProperty –Name SourceAddress –Value $($dat.SourceAddress)
            $OutputObj | Add-Member –MemberType NoteProperty –Name PingSucceeded –Value $($dat.PingSucceeded)
            $OutputObj | Add-Member –MemberType NoteProperty –Name TraceRoute –Value $($dat.TraceRoute -join(','))
            $OutputObj
            #$OutputObj | export-csv -append -Force "$outFile"
    }
    }
$OutputObj | export-csv -append -path -Force ServerStatus.csv


Viewing all 21975 articles
Browse latest View live