Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - New-PS Drive on remote computer

Reply
 
Old 01-04-2007   #1 (permalink)
Terminator


 
 

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
Old 01-04-2007   #2 (permalink)
Brandon Shell


 
 

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
Old 01-04-2007   #3 (permalink)
Terminator


 
 

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
Old 01-05-2007   #4 (permalink)
Brandon Shell


 
 

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
Reply

Thread Tools


Similar Threads
Thread Forum
Remote desktop can not find remote computer Network & Sharing
Remote Desktop - copy from remote drive to local drive - DENIED! Vista General
How to setup Username/Password for a drive in a Windows XP computer to backup files from a Vista computer? Vista General
Vista: This Computer can't connect to the Remote Computer Vista networking & sharing
Computer Management: Can't connect to a remote computer Vista networking & sharing


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46