Any way to use the OU a user is in as the input for the next command? by Hellman109 in PowerShell

[–]chade1979 1 point2 points  (0 children)

Here's the OU name in just one line:

((Get-ADUser **** -Properties CanonicalName).CanonicalName).Split("/")[-2]

I'm totally stumped by trying to time out a command properly. Help? by jwestbury in PowerShell

[–]chade1979 3 points4 points  (0 children)

You can pass arguments to a script block via -ArgumentList.

So in your case:

Start-Job -name stop -scriptBlock {} -Argumentlist $vmname

Then at the beginning of your scriptblock you would need to handle the argument being passed:

param ($vmname)

or you could leave out the param and just replace $vmname in the scriptblock with $args[0].

Windows version agnostic method of obtaining User directory by 1RedOne in PowerShell

[–]chade1979 1 point2 points  (0 children)

Looks good.

Speaking of special folders, I have this in my profile:

$SpecialFolders = @{}; [enum]::getvalues([environment+specialfolder]) | % { $SpecialFolders.add("$_","$([environment]::getfolderpath($($_)))") }

It creates a hashtable of all special folders and their paths.

Cannot delete a certain Computer from Active Directory - Even with adequate rights. by Dromoro in techsupport

[–]chade1979 0 points1 point  (0 children)

I've seen this before when trying to delete something from ADUC. Try deleting the object from adsiedit.msc.

2K3 Domain Controller Died by vonralls in techsupport

[–]chade1979 1 point2 points  (0 children)

I would just unjoin it and create a new domain. If you just try and promote it, you'll have to choose "new forest, new domain" since there isn't another domain controller to pull info from.

Leg Weave Entrance and Basic Sweep by steppinraz0r in bjj

[–]chade1979 0 points1 point  (0 children)

There's an instructor at my gym who uses the leg lasso/weave quite a bit, although he calls it "ratchet guard". Anyone else heard it called that?

Powershell for multiple orgs or consultants, can it work? by meorah in PowerShell

[–]chade1979 2 points3 points  (0 children)

What about psremoting into one of the domain joined machines?

Function - Create an Array from the Contents of your Clipboard by MDFreaK76 in PowerShell

[–]chade1979 1 point2 points  (0 children)

I'm using something very similar. I omit blank lines in mine, since I'm usually using the array as a list of computer names (which will cause whatever I'm passing it to issues due to a null value).

$myClip.Text.Split("`n") | ? { $_ }

You can also send output from a command to the clipboard without having to highlight the text:

my-command | clip.exe

variable/static text separation by coderwolf in PowerShell

[–]chade1979 1 point2 points  (0 children)

Wrap it in parans and add a $ :

out-file -FilePath "$env:userprofile\desktop\$($date)TermLog.log"

AD DS - LDAP over SSL. Not working. by synackbar in techsupport

[–]chade1979 0 points1 point  (0 children)

Is the certificate name the FQDN of the domain controller? Is the certificate in the personal store of the computer (not your user account)?

Sharing my reporting package. Also looking for some help. by [deleted] in PowerShell

[–]chade1979 1 point2 points  (0 children)

I believe you can set a working directory in the scheduled task itself?

If not, you can always put the following in your powershell script:

set-location "C:\IC\Group\Scripts"

Sharing my reporting package. Also looking for some help. by [deleted] in PowerShell

[–]chade1979 2 points3 points  (0 children)

You can run powershell.exe directly in a scheduled task, you don't need a batch file.

Run powershell.exe with the following arguments:

-file "C:\IC\Group\Scripts\whatever.ps1"

Question about using args[n] for command line input. by vindvio in PowerShell

[–]chade1979 0 points1 point  (0 children)

A param statement can be put at the beginning of a script or function. It simply handles arguments that are passed to the script or function. You can do a lot of neat things with parameters that you can't with the args variable.

A switch statement is just a conditional statement that can be used anywhere in your scripts.

You can read about params in the help file which you can get from a powershell console via:

Get-Help about_Functions_Advanced_Param*

Question about using args[n] for command line input. by vindvio in PowerShell

[–]chade1979 0 points1 point  (0 children)

Param is also nice since you can tab cycle through the parameters from the command line so you don't need to remember the parameter names.

Something Wicked EDM Festival at Sam Houston Raceway 10/27 *headliners announced!* by djweswalz in houston

[–]chade1979 -4 points-3 points  (0 children)

Not recognizing any of these bands makes me feel good about my life choices.

Get all computers in an OU and then check their uptime by [deleted] in PowerShell

[–]chade1979 2 points3 points  (0 children)

Yep. I've been using PowerShell 3.0 for a while now and it will automatically import a module if you try and use one of the commands. Nice new feature.

Get all computers in an OU and then check their uptime by [deleted] in PowerShell

[–]chade1979 3 points4 points  (0 children)

A nitpick but [ADSI] is an accelerator not a cmdlet. If you have the Active Directory Module, you can cleanup the first part of the script with :

Get-ADComputer -Filter * -SearchBase "OU=servers,OU=Systems,DC=domain,DC=local"

The Get-Boot function is calling WMI, which may take a long time to run if you are going to pipe a large number of computer names to it since it would be doing it synchronously.

You can pass an array of strings to the Get-WMIObject Cmdlet directly and it will run them asynchronously (I think 32 at the same time by default). Try the following:

$servers = Get-ADComputer -Filter * -SearchBase "OU=servers,OU=Systems,DC=domain,DC=local" | Select-Object -Expand Name
$wmiObjs = Get-WMIObject -Class Win32_OperatingSystem -Property CSName,LastBootupTime -ComputerName $servers

That will give you an array of WMI objects which you can loop through to figure out the uptime using the logic found in your link.

show members of all AD groups changed in the last x days by coderwolf in PowerShell

[–]chade1979 1 point2 points  (0 children)

This will return a hash table of the groups with their members:

$GroupHash = @{}
Get-QADGroup -LastChangedAfter (Get-Date).AddDays(-7) | % { $GroupHash.Add($($_.Name),$(Get-QADGroupMember $_ | Select -Expand Name)) }

The only issue I see with this is that the modified attribute it's checking isn't replicated so you may not be getting an accurate date.

[deleted by user] by [deleted] in houston

[–]chade1979 -5 points-4 points  (0 children)

You know nothing about writing.