Showing posts with label Computer managment. Show all posts
Showing posts with label Computer managment. Show all posts

July 2, 2013

Find all files and folders with specific name

To find all files and folders with ‘excel’ within their name :

Get-ChildItem -filter "*excel*" -Recurse | select name, fullname, lastwritetime,PSIsContainer | Out-GridView

February 27, 2013

Register-ScheduledTasksEx add-on for PowershellPack

To manage the Task Scheduler service on Windows 8/2012, you can use the new Scheduledtasks module. On Windows Vista/7/2008/2008 R2 you have to download the PowershellPack (also included in Windows 7 Reskit) and install the taskscheduler module.
But there is one thing missing in the taskscheduler module, when you want to create a new task with the Register-ScheduledTasks : you can’t specified in witch folder you want it. So I’ve created a new cmdlet (Register-ScheduledTasksEx) that allow you to specified to folder to use. To install this new cmdlet (kind of a add-on) with the taskscheduler module, just follow these 2 steps :

Step 1 : Create the file Register-ScheduledTasksEx.ps1

Create a new file named Register-ScheduledTasksEx.ps1 in the directory where the taskscheduler module is installed (generally %USERPROFILE%\Documents\WindowsPowerShell\Modules) and paste the following code in it.
function Register-ScheduledTaskEx 
{
    <#
    .Synopsis
        Registers a scheduled task.
    .Description
        Registers a scheduled task.
        Modified to support Folders (path)
    #>
    param(
    # The name of the scheduled task to register
    [Parameter(Mandatory=$true,Position=0)]
    [string]
    $name,

    # The path of the scheduled task to register
    [Parameter(Mandatory=$false)]
    [ValidateNotNull()]
    [string]
    $path="",
        
    # The Scheduled Task to Register
    [Parameter(ValueFromPipeline=$true,
        Mandatory=$true)]
    [__ComObject]
    $Task,
        
    # The name of the computer to connect to.
    [string[]]
    $ComputerName,
    
    # The credential used to connect
    [Management.Automation.PSCredential]
    $Credential    
    )  
    
    begin {
        Set-StrictMode -Off
    }
    process {
        if ($task.Definition) { $Task = $task.Definition } 
        foreach ($c in $computerName) {
            $scheduler = Connect-ToTaskScheduler -ComputerName $c -Credential $Credential            
            if ($scheduler -and $scheduler.Connected) {
                $folder = $scheduler.GetFolder($path)
                if ($Credential) {
                    $folder.RegisterTaskDefinition($Name, 
                        $Task, 
                        6,
                        $credential.UserName,
                        $credential.GetNetworkCredential().Password,
                        6,
                        $null)
                } else {
                    $folder.RegisterTaskDefinition($Name, 
                        $Task, 
                        6,
                        "",
                        "",
                        3,
                        $null)                
                }                
            } 
        }
    }
}

Step 2 : Modify TaskScheduler.psm1 file

Add the following line to the TaskScheduler.psm1 file (In the TaskScheduler module directory).
. $psScriptRoot\Register-ScheduledTaskEx.ps1

Example

Here’s how to use the new cmdlet :
import-module TaskScheduler
$ScheduledTask = New-Task
$ScheduledTask | add-TaskAction -path "Notepad.exe" -Arguments "" -WorkingDirectory ""| out-null
# Note : The folder "\MyCustomFolder" must already  exist in the TaskScheduler
$ScheduledTask | Register-ScheduledTaskEx -Name "MyCustomScheduledTask" -path "\MyCustomFolder" -ComputerName Localhost | out-null

November 8, 2012

How to get a list of ADSI providers

If you “google” it, you might think that the following command should work to get the list of Active Directory Service Interface (ADSI) installed providers :

[adsi]"ADs:"

It does not work. I think it should (it works in VBS), but it does not.

There is a work arround, ADSI Provider are registered in the registry, si simply type this command :

dir HKLM:\SOFTWARE\Microsoft\ADs\Providers

February 10, 2012

List users connected to shares

Get-WmiObject win32_serverconnection | select username,computername,sharename