none
aa RRS feed

All replies

  • Please post code correctly.  The code is unreadable and cannot be correctly copied unless it is formatted and posted correctly.  Use code posting tool provided on the edit bar.

    What are the local admin details?  Which local Admin?  Where do you wan tit printed?


    \_(ツ)_/


    • Edited by jrv Friday, January 12, 2018 11:35 AM
    Friday, January 12, 2018 11:33 AM
  • is this more detailed/ pasted correctly for you?
    Friday, January 12, 2018 11:54 AM
  • The following is wrong.  You cannot call a function by pasting it into line of code.

    $cells.item($row,$col2)=function get-localadmin { 
    				param ($strcomputer) 
    	 
    				$admins = Gwmi win32_groupuser –computer $strcomputer  
    				$admins = $admins |? {$_.groupcomponent –like '*"Administrators"'} 
     
    				$admins |% { 
    				$_.partcomponent –match “.+Domain\=(.+)\,Name\=(.+)$” > $nul 
    				$matches[1].trim('"') + “\” + $matches[2].trim('"') 
    				"." 
    				} 
    				}
    
    help about_functions


    \_(ツ)_/

    • Marked as answer by schmidtj98 Friday, January 12, 2018 12:15 PM
    • Unmarked as answer by schmidtj98 Friday, January 12, 2018 12:15 PM
    Friday, January 12, 2018 11:58 AM
  • Yeah, thats one of the things i want to know, how would i call the function to run in the code, and then from the result of that function write to the specified cell. 
    Friday, January 12, 2018 12:13 PM
  • $ServerListFile = "ErrorLog.txt"  
    $ServerList = Get-Content $ServerListFile
    $Result = @() 
    $user= whoami
    $date = (get-Date).tostring()
    $excel = New-Object -ComObject Excel.Application
    $workbook = $excel.Workbooks.add()
    $excel.visible = $true
    $s1 = $workbook.sheets | where {$_.name -eq 'Sheet1'}
    $s1.Delete()
    $s3 = $workbook.sheets | where {$_.name -eq 'Sheet3'}
    $s3.Delete()
    $s2 = $workbook.sheets | where {$_.name -eq 'Sheet2'}
    $s2.name = "Ping Result"
    $cells= $s2.Cells
    $s2.range("A2:A2").cells="Hostname"
    $s2.range("A2:A2").font.bold = "true"
    $s2.range("A2:A2").interior.colorindex=48
    $s2.range("A2:A2").HorizontalAlignment = -4108
    $s2.range("B2:B2").cells="Ping Result"
    $s2.range("B2:B2").font.bold = "true"
    $s2.range("B2:B2").interior.colorindex=48
    $s2.range("B2:B2").HorizontalAlignment = -4108
    $s2.range("A3:b3").EntireColumn.autofit() | out-Null
    $row=3
    $col1=1
    $col2=2
    $s2.Cells.EntireColumn.AutoFilter()
    write-host "Please wait..."
    ForEach($computername in $ServerList)		
    {
    	if (test-Connection -ComputerName $computername -Count 3 -Quiet ) 
    	{  
    		$cells.item($row,$col1)=$computername
    		$cells.item($row,$col2)=
    	}  
    			
    			
    
    	else 
        { 
    		$cells.item($row,$col1)=$computername
    		$cells.item($row,$col1).Interior.ColorIndex = 46
    		$cells.item($row,$col2)="Server seems dead not pinging"
    		$cells.item($row,$col2).Interior.ColorIndex = 46
    	}
    	$row++
    	$col1=1
    	$col2=2
    	$s2.range("A3:b3").EntireColumn.autofit() | out-Null
    }
    $row=$row+2
    write-host "Script Completed !!!"
    "`n"
    $workbook.SaveAs("$env:userprofile\desktop\Multiple_Ping_Testandadminrights.xlsx")
    so if i did this, and wanted to call the function to get local admin to run once i know the asset is pingable, how would i do that? and then type the result into 1 cell of the excell spreadsheet?
    Friday, January 12, 2018 12:17 PM
  • help about_functions

    https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions?view=powershell-5.1

    Learn PowerShell  

    The above will teach you how to use functions with PowerShell.

    We cannot teach you PowerShell or rewrite scripts you have collected from the Internet. 


    \_(ツ)_/

    Friday, January 12, 2018 12:25 PM