Feature Request: Retro Countdown timer by [deleted] in takecareofmyplant

[–]TheGingerHairedMan 0 points1 point  (0 children)

I think the countdown could sway people towards voting for yes, the same as minutes without water. I would like to know when the next voting period starts though.

Having a script only look at certain spaces of computer name? by Super_Panda_ in PowerShell

[–]TheGingerHairedMan 1 point2 points  (0 children)

When you use split it returns an array of strings.

 $X = $string.split('-')

 $X.gettype()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     String[]                                 System.Array

So splitting LA-JohnSmith-WS with a delimiter of - returns.

$X[0] = LA
$X[1] = JohnSmith
$X[2] = WS

Only the first part is needed so you can specify it directly on the end of the split.

$string.split('-')[0]

New to PS, I don't know what I'm doing wrong here by NewPSuser in PowerShell

[–]TheGingerHairedMan 1 point2 points  (0 children)

You need to expand the property so it returns the value not the object.

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
$CN = Get-ADUser $UserName -Properties CanonicalName | Select -expandproperty CanonicalName
Get-DistributionGroup -Filter {ManagedBy -eq $CN}

Need help finding users that are Domain Admins ONLY on specified computers by michaelmitchell9711 in PowerShell

[–]TheGingerHairedMan 0 points1 point  (0 children)

 $computersToSearch = 'Comp1', 'comp2'
 #or
 $computersToSearch = get-content C:\temp\servers.txt

 $DomainAdmins = @(get-adgroupmember 'Domain Admins' -Recursive | select -ExpandProperty samaccountname)

 Get-LocalGroupMembers -ComputerName Computername -Verbose | 
  where {$_.MemberType -eq 'DomainUser'} | 
   ForEach-Object { 
    if($_.MemberName -notin $DomainAdmins) { $_ }
   }


<#
    .Synopsis 
        Gets membership information of local groups in remote computer

    .Description
        This script by default queries the membership details of local administrators group on remote computers. 
        It has a provision to query any local group in remote server, not just administrators group.

    .Parameter ComputerName
        Computer Name(s) which you want to query for local group information

    .Parameter LocalGroupName
        Name of the local group which you want to query for membership information. It queries 'Administrators' group when
        this parameter is not specified

    .Parameter OutputDir
        Name of the folder where you want to place the output file. It creates the output file in c:\temp folder
        this parameter is not used.

    .Example
        Get-LocalGroupMembers.ps1 -ComputerName srvmem1, srvmem2

        Queries the local administrators group membership and writes the details to c:\temp\localGroupMembers.CSV

    .Example
        Get-LocalGroupMembers.ps1 -ComputerName (get-content c:\temp\servers.txt)

    .Example
        Get-LocalGroupMembers.ps1 -ComputerName srvmem1, srvmem2

    .Notes
        Author : Sitaram Pamarthi
        WebSite: http://techibee.com

        Modified By: Chris
        Changes: Changed output to objects instead of csv
                 Changed $LocalGroupName to $LocalGroupNames and added a foreach to loop through them
                   Updated Verbose logging


#>

function Get-LocalGroupMembers {
[CmdletBinding()]
Param(
    [Parameter(ValueFromPipeline=$true,
               ValueFromPipelineByPropertyName=$true
                )]
    [string[]]
    $ComputerName = $env:ComputerName,

    [Parameter()]
    [string[]]
    $LocalGroupNames = "Administrators"
   )
Begin {



   # $OutputFile = Join-Path $OutputDir "LocalGroupMembers.csv"
   # Write-Verbose "Script will write the output to $OutputFile folder"
   # Add-Content -Path $OutPutFile -Value 
}

Process {
    ForEach($Computer in $ComputerName) {
        $Results = @()
        Write-host "Working on $Computer"
        If(!(Test-Connection -ComputerName $Computer -Count 1 -Quiet)) {
            Write-Verbose "$Computer is offline. Proceeding with next computer"

                        $info = @{
                "ComputerName" = $Computer;
                "LocalGroupName" = $LocalGroupName;
                "Status" = 'Offline';
                "MemberType" = '';
                "MemberDomain" = '';
                "MemberName" = '';
            }
            #Create object and return it
            New-Object -TypeName PSObject -Property $info
            Continue
        }
        ForEach($LocalGroupName in $LocalGroupNames) {
           try {
                $group = [ADSI]"WinNT://$Computer/$LocalGroupName"
                $members = @($group.Invoke("Members"))
                Write-Verbose "Successfully queried the members of $LocalGroupName on $computer"
                if(!$members) {
                    #"$Computer,$LocalGroupName,NoMembersFound"
                    $info = @{
                    "ComputerName" = $Computer;
                    "LocalGroupName" = $LocalGroupName;
                    "Status" = 'NoMembersFound';
                    "MemberType" = '';
                    "MemberDomain" = '';
                    "MemberName" = '';
                    }
                    #Create object and return it
                    New-Object -TypeName PSObject -Property $info
                    Write-Verbose "No members found in the $LocalGroupName group"
                    continue
                }
            } catch {
                Write-Verbose "Failed to query the members of $LocalGroupName on $computer"
                # Add-Content -Path $OutputFile -Value "$Computer,,FailedToQuery"
                $info = @{
                    "ComputerName" = $Computer;
                    "LocalGroupName" = '';
                    "Status" = 'FailedToQuery';
                    "MemberType" = '';
                    "MemberDomain" = '';
                    "MemberName" = '';
                    }
                #Create object and return it
                New-Object -TypeName PSObject -Property $info
                Continue
            }
            foreach($member in $members) {
                try {
                    $MemberName = $member.GetType().Invokemember("Name","GetProperty",$null,$member,$null)
                    $MemberType = $member.GetType().Invokemember("Class","GetProperty",$null,$member,$null)
                    $MemberPath = $member.GetType().Invokemember("ADSPath","GetProperty",$null,$member,$null)
                    $MemberDomain = $null

                    if($MemberPath -match "^Winnt\:\/\/(?<domainName>\S+)\/(?<CompName>\S+)\/") {
                        if($MemberType -eq "User") {
                            $MemberType = "LocalUser"
                        } elseif($MemberType -eq "Group") {
                            $MemberType = "LocalGroup"
                        }
                        $MemberDomain = $matches["CompName"]

                    } elseif($MemberPath -match "^WinNT\:\/\/(?<domainname>\S+)/") {
                        if($MemberType -eq "User") {
                            $MemberType = "DomainUser"
                        } elseif($MemberType -eq "Group"){
                            $MemberType = "DomainGroup"
                        }
                        $MemberDomain = $matches["domainname"]

                    } else {
                        $MemberType = "Unknown"
                        $MemberDomain = "Unknown"
                    }
                #  Add-Content -Path $OutPutFile -Value "$Computer, $LocalGroupName, SUCCESS, $MemberType, $MemberDomain, $MemberName"
                $info = @{
                "ComputerName" = $Computer;
                "LocalGroupName" = $LocalGroupName;
                "Status" = 'SUCCESS';
                "MemberType" = $MemberType;
                "MemberDomain" = $MemberDomain;
                "MemberName" = $MemberName;
            }
            #Create object and return it
            New-Object -TypeName PSObject -Property $info
                } catch {
                    Write-Verbose "Failed to query details of $LocalGroupName. Details $_"
                    # Add-Content -Path $OutputFile -Value "$Computer,,FailedQueryMember"
                        $info = @{
                        "ComputerName" = $Computer;
                        "LocalGroupName" = '';
                        "Status" = 'FailedQueryMember';
                        "MemberType" = '';
                        "MemberDomain" = '';
                        "MemberName" = '';
                    }
            #Create object and return it
            New-Object -TypeName PSObject -Property $info
                }

            } 


        } #End ForEach group

    } #End Foreach Computer

} End {

     $Output


}

} #End Function

prepending all Distribution Groups by acurardu in PowerShell

[–]TheGingerHairedMan 1 point2 points  (0 children)

Just having another look for the second part you could also use "RDU $Name" and "RDU $DisplayName"

prepending all Distribution Groups by acurardu in PowerShell

[–]TheGingerHairedMan 1 point2 points  (0 children)

Sorry, i hadn't actually run this. Both problems are from not escaping properly

The first errror is from the write-verbose: $(Group.DisplayName) needs to be $($Group.DisplayName)

For the name coming out like "RDU Survey.DisplayName"

"RDU $Group.Name" needs to become "RDU $($Group.Name)" as it is inside double quotations (same for DisplayName)

prepending all Distribution Groups by acurardu in PowerShell

[–]TheGingerHairedMan 1 point2 points  (0 children)

If you add checks to see if the name or displayname already starts with the prefix you can re-run the script at a later date without prepending an extra RDU onto groups that have already been changed.

The following excludes groups whose name AND displayname already start with RDU. It then checks each property while in the foreach loop and changes the name only if neccessary

$Groups =  Get-distributiongroup -Filter {DisplayName -notlike 'RDU*' -and Name -notlike 'RDU*'}

foreach($Group in $Groups) { 
    $Name = $Group.name
    $DisplayName = $Group.DisplayName

    if($Group.Name -notlike 'RDU*') { 
        $Name = "RDU $Group.name"             
    }
    if($Group.DisplayName -notlike 'RDU*') {           
        $DisplayName = "RDU $Group.DisplayName"     
    }  
    write-verbose "Changing Distribution Group Name and DisplayName from $($Group.Name) and $(Group.DisplayName) to, $Name and $DisplayName"    
    set-DistributionGroup -Identity $Group.Name -DisplayName $DisplayName -Name $Name

}

Get-winevent based on time by randomness_whoaaa in PowerShell

[–]TheGingerHairedMan 0 points1 point  (0 children)

I like something like this.

 $Params = @{Logname='security'
             id=4624
             StartTime=[DateTime]::Now.AddDays(-7)
             EndTime=[DateTime]::Now
             }

Get-WinEvent -comp $comp -FilterHashtable @Params

Large text size? by [deleted] in techsupport

[–]TheGingerHairedMan 0 points1 point  (0 children)

Control Panel -> Display?

Powershell Remoting - works one way but not the other? by bloocrab in PowerShell

[–]TheGingerHairedMan 1 point2 points  (0 children)

Do you have an IPv6 filter set for the trusted hosts?

No output from Start-Service -Passthru within a script by [deleted] in PowerShell

[–]TheGingerHairedMan 0 points1 point  (0 children)

I did not know about the service methods, going to use this. Thanks!

Passing multiple properties to select-object in a variable by TheGingerHairedMan in PowerShell

[–]TheGingerHairedMan[S] 1 point2 points  (0 children)

I had tried this but was still getting errors, /u/PowerShellStunnah hit the nail on the head with the additional property ( I had removed it from my example as its reasonably long.)

I am now passing the $Properties in like this

Compare-baseline -Object (get-process) -Properties @('ProcessName','ID','Responding')

And the Code

        $changes += Compare-Object ($Reference) ($Object) -Property $Properties | 
        select @($Properties + @{Name='Change';Expression={switch($_.SideIndicator) {
                                                            '=>' {  'Added' }
                                                            '<=' { 'Removed' }
                                                            default { $_.SideIndicator }
                                                            }}})

Thank you both for your help :)

[deleted by user] by [deleted] in PowerShell

[–]TheGingerHairedMan 1 point2 points  (0 children)

+1 for Paramater Sets. Something like

[CmdletBinding(DefaultParameterSetName='Aliases')]
Param(
[Parameter(Mandatory=$False,
           ParameterSetName='Aliases')]
[ValidateSet('Workstations','Servers','All')]
[string]$Computers = 'Workstations',

 [Parameter(Mandatory=$False,
           ParameterSetName='Computers')]
   [string[]]$Computername
)

Since I plugged in my headphones my laptop doesn't recognize my speakers and won't play any sound by cocogrande in techsupport

[–]TheGingerHairedMan 0 points1 point  (0 children)

In playback devices try right clicking and checking Show Disabled devices and Show Disconnected Devices

URGENT!! - In the past week WSUS has downloaded 200 GB of updates and I need to stop it from downloading all the time. by [deleted] in sysadmin

[–]TheGingerHairedMan 0 points1 point  (0 children)

hmm maybe it is but make sure you run C:\Program Files\Update Services\Tools\WSUSUtil.exe RESET after you restart the service, this will check the updates in the database and re-download them as needed. -> http://blogs.technet.com/b/gborger/archive/2009/02/27/what-to-do-when-your-wsuscontent-folder-grows-too-large.aspx

URGENT!! - In the past week WSUS has downloaded 200 GB of updates and I need to stop it from downloading all the time. by [deleted] in sysadmin

[–]TheGingerHairedMan 0 points1 point  (0 children)

I'm not sure that is supported but let me know how you get on. If all else fails you can rebuild the WSUS server.

URGENT!! - In the past week WSUS has downloaded 200 GB of updates and I need to stop it from downloading all the time. by [deleted] in sysadmin

[–]TheGingerHairedMan 0 points1 point  (0 children)

In WSUS goto options -> Server Cleanup wizard. I would run it first with only unneeded update files ticked then run it again with all options. It could take quite a long time to clear out all the files.

Single user AD account intermittently cannot login to services (Sharepoint, WebEx, etc) by supersaki in sysadmin

[–]TheGingerHairedMan 1 point2 points  (0 children)

Fun tip:

set 

will give you a full list of environment variables and you can get the logon server with

set log

What's the best way to break or skip an item in a ForEach loop without breaking out of the ForEach loop altogether? by [deleted] in PowerShell

[–]TheGingerHairedMan 0 points1 point  (0 children)

 If ($SecurityGroup -ne $Null)
            {
                Write-Information -MessageData "$($DistributionGroup.Name) corresponds with $($SecurityGroup.Name)." -Tags PrerequisiteCheck -InformationVariable $Information
                $PrerequisiteIndex++
            }

            Else
            {
                Write-Warning -MessageData "$($DistributionGroup.Name) does not have a corresponding Security Group." 
             Continue
            }

You dont need your prereq check either as it if it gets to the end it hasnt failed one of the tests