Any help

On Mon, Feb 1, 2016 at 9:43 AM, Kevin Ray <[email protected]> wrote:

> Hi All,
>
> Script we are using like.
>
>
> Below is my script which i need to do small changes like
> c:\temp\mymachines.txt have the list of machines.. in script we are
> passing the machine names to get the account names
>
>
>
> 1. Write now the result its showing on command prompt. I need to get the
> result in Excel
> 2. we have multiple domains.. In script we are passing the Domain name
> (XXXXXXXXX)... Instead of this like I have 10 machines in excel with
> headers of Machine name and Domain it should call in the script and result
> should get in the excel ...
>
> Expecting like::If i change the script to remove (* $Group.remove("WinNT://"
> + $domain + "/" + $username)   -----*
>
>
> *Machine name :::: Domain::::: Result:::::*
> *Computer1::::::::::: XXXX::::::  Removed   should showup inthe excel*
>
>
> *Usage:*
>
>
> run command.
>
> *{{{{{{{{{{{{{.\script.ps1 "Kevin" "C:\Temp\add_remove admin
> rights\mymachines.txt*"
>
> * $Group.add("WinNT://" + $domain + "/" + $username)   :::::::::::here i
> remove.Add and changes to remove it will remove the specified
> account..}}}}}}}}}}}}}*
>
> ____________________________________________________
>
> function ListAdministrators($Group)
> {
>   $members= $Group.psbase.invoke("Members") |
> %{$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
>   $members
> }
>
> function Ping-Server {
>    Param([string]$srv)
>    $pingresult = Get-WmiObject Win32_PingStatus -Filter  "Address='$srv'"
>    if($pingresult.StatusCode -eq 0) {$true} else {$false}
> }
>
> if ($args.Length -ne 2) {
>  Write-Host "`tUsage: "
> Write-Host "`t`t.\AddToLocalAdmin.ps1 < group or user > <file of machines>"
> Write-Host "`t`tExample: .\AddToLocalAdmin.ps1 FooBarGroup
> c:\temp\mymachines.txt"
> return
> }
>
> #Your domain, change this
> $domain = "*XXXXXXX*"
>
> #Get the user to Remove
> $username = $args[0]
>
> #File to read computer list from
> $strComputers = Get-content $args[1]
>
> foreach ($strComputer in $strComputers)
> {
>
>   if (Ping-Server($strComputer)) {
>
>       $computer = [ADSI]("WinNT://" + $strComputer + ",computer")
>       $Group = $computer.psbase.children.find("administrators")
>       # This will list what’s currently in Administrator Group so you can
> verify the result
>       write-host -foregroundcolor green "====== $strComputer BEFORE ====="
>       ListAdministrators $Group
>       write-host -foregroundcolor green "====== BEFORE ====="
>
>       # Even though we are adding the AD account
>       # It is being added to the local computer and so we will need to use
> WinNT: provider
>
>      * $Group.add("WinNT://" + $domain + "/" + $username)   *
>
>       write-host -foregroundcolor green "====== $strComputer AFTER ====="
>       ListAdministrators $Group
>       write-host -foregroundcolor green "====== AFTER ====="
>
>    }
>    else
>    {
>       write-host -foregroundcolor red "$strComputer is not pingable"
>    }
> }
>
>
>
>
>
>
>
>



Reply via email to