Windows Vista Forums

New-PS Drive on remote computer
  1. #1


    Terminator Guest

    New-PS Drive on remote computer

    Hi,

    I am using this script to get the list of all softwares installed on a
    computer.

    New-PSDrive -Name Uninstall -PSProvider Registry -Root
    HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

    Get-ChildItem -Path Uninstall: | ForEach-Object -Process {
    $_.GetValue("DisplayName") } | sort-object DisplayName

    While this works fine for a local computer, how would I extend this script
    to work on a remote computer and that also in a loop for hundreds of
    computers.

    Is it possible to connect to a remote computer and then create the drive,
    extract the data and then delete the drive and then move on to the next
    computer.

    Thanks



    Terminator.

      My System SpecsSystem Spec

  2. #2


    Brandon Shell Guest

    Re: New-PS Drive on remote computer

    You could use the .NET provider:

    function Get-Apps {
    Param([string]$server)
    $regKey =
    [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,
    $Server)
    $regKey =
    $regKey.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")
    $regKey.GetSubKeyNames()
    # $regKey | gm # uncomment for methods\properties you can use.
    }

    Of course you could pretty up the code a bit and get different information,
    but this is basically it.
    You could also add begin/process/end to process piped information.

    function Get-Apps {
    Param([string]$server)
    Begin{
    function CheckRegKey{
    param([string]$srv)
    $regKey =
    [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,
    $Srv)
    $regKey =
    $regKey.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")
    $regKey.GetSubKeyNames()
    # $regKey | gm # uncomment for methods\properties you can use.
    }
    }
    Process{
    if($_){
    CheckRegKey $_
    }
    }
    End{
    if($Server){
    CheckRegKey $server
    }
    }
    }


    p.s. Sorry for the formatting... Blasted News Readers!!!

    "Terminator" <Terminator@discussions.microsoft.com> wrote in message
    news:4DAA344B-77BD-4AD8-A4A6-D0E9E2418AAE@microsoft.com...
    > Hi,
    >
    > I am using this script to get the list of all softwares installed on a
    > computer.
    >
    > New-PSDrive -Name Uninstall -PSProvider Registry -Root
    > HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
    >
    > Get-ChildItem -Path Uninstall: | ForEach-Object -Process {
    > $_.GetValue("DisplayName") } | sort-object DisplayName
    >
    > While this works fine for a local computer, how would I extend this script
    > to work on a remote computer and that also in a loop for hundreds of
    > computers.
    >
    > Is it possible to connect to a remote computer and then create the drive,
    > extract the data and then delete the drive and then move on to the next
    > computer.
    >
    > Thanks
    >
    > Terminator.



      My System SpecsSystem Spec

  3. #3


    Terminator Guest

    Re: New-PS Drive on remote computer

    Hi Brandon,

    Thanks for the reply. Could you please help on how to invoke this function
    from a ps1 file. and how would you write all the information to a file for
    each server that is passed to the function.

    Thanks

    Terminator.

    "Brandon Shell" wrote:

    > You could use the .NET provider:
    >
    > function Get-Apps {
    > Param([string]$server)
    > $regKey =
    > [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,
    > $Server)
    > $regKey =
    > $regKey.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")
    > $regKey.GetSubKeyNames()
    > # $regKey | gm # uncomment for methods\properties you can use.
    > }
    >
    > Of course you could pretty up the code a bit and get different information,
    > but this is basically it.
    > You could also add begin/process/end to process piped information.
    >
    > function Get-Apps {
    > Param([string]$server)
    > Begin{
    > function CheckRegKey{
    > param([string]$srv)
    > $regKey =
    > [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,
    > $Srv)
    > $regKey =
    > $regKey.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")
    > $regKey.GetSubKeyNames()
    > # $regKey | gm # uncomment for methods\properties you can use.
    > }
    > }
    > Process{
    > if($_){
    > CheckRegKey $_
    > }
    > }
    > End{
    > if($Server){
    > CheckRegKey $server
    > }
    > }
    > }
    >
    >
    > p.s. Sorry for the formatting... Blasted News Readers!!!
    >
    > "Terminator" <Terminator@discussions.microsoft.com> wrote in message
    > news:4DAA344B-77BD-4AD8-A4A6-D0E9E2418AAE@microsoft.com...
    > > Hi,
    > >
    > > I am using this script to get the list of all softwares installed on a
    > > computer.
    > >
    > > New-PSDrive -Name Uninstall -PSProvider Registry -Root
    > > HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
    > >
    > > Get-ChildItem -Path Uninstall: | ForEach-Object -Process {
    > > $_.GetValue("DisplayName") } | sort-object DisplayName
    > >
    > > While this works fine for a local computer, how would I extend this script
    > > to work on a remote computer and that also in a loop for hundreds of
    > > computers.
    > >
    > > Is it possible to connect to a remote computer and then create the drive,
    > > extract the data and then delete the drive and then move on to the next
    > > computer.
    > >
    > > Thanks
    > >
    > > Terminator.

    >
    >


      My System SpecsSystem Spec

  4. #4


    Brandon Shell Guest

    Re: New-PS Drive on remote computer

    You have two options...

    1 - You could copy the function to a text file. Name it anything.ps1.
    - You can then . source the file (this puts the function in your current
    context.):
    PS> . \PathtoScript\anything.ps1
    When its in your context you can just call the function directly:
    PS> Get-Apps ServerName
    or
    PS> $slist | Get-Apps

    2 - Remove the function Get-Apps { and ending }.
    - Save the text file as Get-Apps.ps1
    PS> PathtoScript\Get-Apps.ps1 ServerName
    or
    PS> $slist | PathtoScript\Get-Apps.ps1
    --
    Brandon Shell
    http://mybsinfo.blogspot.com/

    "Terminator" <Terminator@discussions.microsoft.com> wrote in message
    news:E2767453-2605-4619-935B-83BFE6A41CA8@microsoft.com...
    > Hi Brandon,
    >
    > Thanks for the reply. Could you please help on how to invoke this function
    > from a ps1 file. and how would you write all the information to a file for
    > each server that is passed to the function.
    >
    > Thanks
    >
    > Terminator.
    >
    > "Brandon Shell" wrote:
    >
    >> You could use the .NET provider:
    >>
    >> function Get-Apps {
    >> Param([string]$server)
    >> $regKey =
    >> [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,
    >> $Server)
    >> $regKey =
    >> $regKey.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")
    >> $regKey.GetSubKeyNames()
    >> # $regKey | gm # uncomment for methods\properties you can use.
    >> }
    >>
    >> Of course you could pretty up the code a bit and get different
    >> information,
    >> but this is basically it.
    >> You could also add begin/process/end to process piped information.
    >>
    >> function Get-Apps {
    >> Param([string]$server)
    >> Begin{
    >> function CheckRegKey{
    >> param([string]$srv)
    >> $regKey =
    >> [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,
    >> $Srv)
    >> $regKey =
    >> $regKey.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")
    >> $regKey.GetSubKeyNames()
    >> # $regKey | gm # uncomment for methods\properties you can use.
    >> }
    >> }
    >> Process{
    >> if($_){
    >> CheckRegKey $_
    >> }
    >> }
    >> End{
    >> if($Server){
    >> CheckRegKey $server
    >> }
    >> }
    >> }
    >>
    >>
    >> p.s. Sorry for the formatting... Blasted News Readers!!!
    >>
    >> "Terminator" <Terminator@discussions.microsoft.com> wrote in message
    >> news:4DAA344B-77BD-4AD8-A4A6-D0E9E2418AAE@microsoft.com...
    >> > Hi,
    >> >
    >> > I am using this script to get the list of all softwares installed on a
    >> > computer.
    >> >
    >> > New-PSDrive -Name Uninstall -PSProvider Registry -Root
    >> > HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
    >> >
    >> > Get-ChildItem -Path Uninstall: | ForEach-Object -Process {
    >> > $_.GetValue("DisplayName") } | sort-object DisplayName
    >> >
    >> > While this works fine for a local computer, how would I extend this
    >> > script
    >> > to work on a remote computer and that also in a loop for hundreds of
    >> > computers.
    >> >
    >> > Is it possible to connect to a remote computer and then create the
    >> > drive,
    >> > extract the data and then delete the drive and then move on to the next
    >> > computer.
    >> >
    >> > Thanks
    >> >
    >> > Terminator.

    >>
    >>



      My System SpecsSystem Spec

New-PS Drive on remote computer problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Remote Desktop - Cannot Connect To The Remote Computer timrye Server General 1 12 Oct 2009
Remote desktop can not find remote computer bitterpill Network & Sharing 5 26 Mar 2009
Remote Desktop - copy from remote drive to local drive - DENIED! scotteh Vista General 2 28 May 2008
Vista: This Computer can't connect to the Remote Computer Wes Vista networking & sharing 0 20 Jun 2007
Computer Management: Can't connect to a remote computer Paul Vista networking & sharing 0 08 May 2007