Working with DirectoryInfo

powershell

    Next

  • 1. How to 'set-location' to a registry key called "."
    This does not work because "*" is a wildcard... set-location hklm:\software\classes\* ...but this does... set-location -LiteralPath hklm:\software\classes\* This does not work because "." means current location... set-location hklm:\software\classes\. ...and *this* does not either... set-location -LiteralPath hklm:\software\classes\. How do I set-location to a registry key called "."?
  • 2. Install CTP3 in Windows 7?
    How can I install CTP 3 in Windows 7? It says I have to uninstall the previous version. However POwershell isn't listed in the Programs menu or the Updates or the turn on/off Windows features menu. Thanks
  • 3. powershell output format help -> MS Excel
    I have some SCVMM commands that query and output in the format Name : BELEMIR Status : Running Description : OperatingSystem : Windows Server 2003 Standard Edition (32-bit x86) CPUCount : 2 Memory : 2048 TotalSize (Gb) : 10.42 CustomProperties : {Mark , 172.18.148.108, , ...} HostName : blah1 Name : BRANDIR Status : Running Description : CostXpert OperatingSystem : 64-bit edition of Windows Server 2008 Datacenter CPUCount : 2 Memory : 1024 TotalSize (Gb) : 16.72 CustomProperties : {Al / Pierre , 172.18.148.105, , ...} HostName : blah2 Name : CALMACIL Status : Running Description : Universal Latent Workstation OperatingSystem : Windows XP Professional CPUCount : 2 Memory : 2048 TotalSize (Gb) : 12.66 CustomProperties : {Ted , 172.18.148.84, , ...} HostName : blah2 This is the correct data but the 'powers that be' want it in the following format: Name CPUCount Memory belemir 2 2048 brandir 2 1024 calmacil 2 2048 etc. The end result will be to put this in Excel. Any formatting experts want to put me on the right track (either directly to Excel or to a table)? Thanks Blake

Working with DirectoryInfo

Postby David Trimboli » Wed, 03 Mar 2010 02:19:41 GMT

I'm working on a function that removes files related to a virus. The files are called x[1], x[2], x[3], etc, 
and are found in "Local Settings\Temporary Internet Files\Content.IE5\<CacheFolder>". The script fails to 
detect and remove the files because the variable $CacheFolder (seems to return a string instead of a folder 
object (although the type is reported as DirectoryInfo). The Get-ChildItem cmdlet is trying to the cache 
folders in my home directory instead of the correct paths.

How can I adjust this function to correctly search the cache folders?

function Remove-Virut ($ComputerName = $env:ComputerName)
{

# First establish access to remote computer.
# Is it on the network?
     if (Test-Connection $ComputerName -Count 1)
     {
# Does the user have access?
         if (-not (Get-Item \\$ComputerName\c$ -ErrorAction SilentlyContinue))
	{
	    net use \\$ComputerName\c$
	}

# Delete bogus .scr files in \Windows\System32.
         $ScrFiles = Get-Item \\$ComputerName\Admin$\system32\*.scr -ErrorAction SilentlyContinue -Force |
	    Where-Object {$_.Name -match "^[0-9][0-9]?.scr$"}
	If ($ScrFiles)
        	{
	    Write-Host "Removing .scr files:"
	    Write-Host $ScrFiles
	    Remove-Item $ScrFiles
	}

# Delete x[#] files from Internet Explorer caches
         $XFilePath = "Local Settings\Temporary Internet Files\Content.IE5"
	$ServicePaths = "Documents and Settings\Default User", "Documents and Settings\LocalService",
	    "Documents and Settings\NetworkService"
	foreach ($ServicePath in $ServicePaths)
	{
	    $CacheFolders = Get-ChildItem "\\$ComputerName\c$\$ServicePath\$XFilePath" -Force |
	        Where-Object {$_.PSIsContainer}

# HERE COMES THE BIT THAT DOESN'T WORK!
	    foreach ($CacheFolder in $CacheFolders)
	    {
	        $XFiles = Get-ChildItem $CacheFolder -Force -ErrorAction SilentlyContinue |
	            Where-Object {$_.Name -match "^x\[[0-9]"}
		if ($XFiles) {
		    Write-Host "Removing x[] files from $CacheFolder.Name:"
		    Write-Host $XFiles
		    Remove-Item $XFiles
		}
             }
	}
     }
}


-- 
David Trimboli
Windows Systems Analyst
Cold Spring Harbor Laboratory

RE: Working with DirectoryInfo

Postby UGF1bENoYXZleg » Wed, 03 Mar 2010 04:06:01 GMT

Try specifying the fullname property. For some reason when you are working 
with File/DirectoryInfo objects within a foreach loop you need to specify 
fullname when passing into *-*Item cmdlets.

So the line:

$XFiles = Get-ChildItem $CacheFolder -Force -ErrorAction SilentlyContinue |

should be:

$XFiles = Get-ChildItem $CacheFolder.fullname -Force -ErrorAction 
SilentlyContinue |


Hope that helps,
Paul Chavez





Re: Working with DirectoryInfo

Postby David Trimboli » Wed, 03 Mar 2010 05:07:59 GMT

Thanks, Paul. That did it!






-- 
David Trimboli
Windows Systems Analyst
Cold Spring Harbor Laboratory

Similar Threads:

1.Works 8.5 in Vista: "Microsoft Works has stopped working"

   I frequently get this message, and finally MSN has added a page to how to 
correct the problem.  HOWEVER, I have followed the directions explicitly 
twice, and both times am told it is done, but the same problem occurs again:  
Works has stopped working.  I have tried logging off, same result.   
   Very frustrating.-- 
Maggie

2.extensions don't work and do work

When I publish my website, containing a counter, I get the message: "page 
will not work because the server you are publishing to does not have the 
Frontpage Server Extensions installed", but the provider changed the 
index-page on my website (he removed the theme, the shared borders and the 
navigation), resulting in a working counter.
However, when I publish this working page, it doesn't work anymore (because 
it doesn't recognize the server extensions).

How can I solve this?

3.webcam preview works, capture card is not working, black preview b

4.webcam preview works, capture card is not working, black preview but only with SDK

I'm doing some final alpha testing for a free live broadcasting service
that Vidiac.com will be offering soon.

We wrote an app that shows a preview and postview of the camera
connected to it and then broadcasts to a remote server.

Long story short, I run the program on my laptop, works perfect with
the built-in webcam. I get preview and postview, broadcasts fine, etc.

I run the program on my PC with a Winnov Videum capture card and I get
black for both preview and postview (it does broadcast correctly, just
black). If I run Windows Media Encoder on that PC I do see both preview
and postview.

What is WME doing that is different from the SDK in this regard? I save
the name of the video and audio source in the registry and I verified
on that PC that it is storing and retrieving the correct name.

Here's the relavent code that I'm using and as I said, it does work on
my laptop.

using WMEncoderLib;
using WMPREVIEWLib;

try
			{
					int port =
Convert.ToInt16(Application.UserAppDataRegistry.GetValue("Port_number"));
					IWMEncSourceGroupCollection SrcGrpColl;
					IWMEncSourceGroup SrcGrp;
					SrcGrpColl = Encoder.SourceGroupCollection;
					SrcGrp = SrcGrpColl.Add("SG_1");
					IWMEncSource SrcAud;
					IWMEncSource SrcVid;
					IWMEncSource SrcScript;
					SrcVid = SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO);
					SrcAud = SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO);
					SrcScript = SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_SCRIPT);
					SrcScript.SetInput("", "UserScript", "");
					SrcAud.SetInput(Convert.ToString(AudioSourceReg), "Device", "");
					SrcVid.SetInput(Convert.ToString(VideoSourceReg), "Device", "");
					SrcGrp.set_Profile("C:\\default.prx");

					IWMEncDataViewCollection DVColl_preview =
SrcVid.PreviewCollection;
					IWMEncDataViewCollection DVColl_postview =
SrcVid.PostviewCollection;

					WMEncDataView Preview = new WMEncDataView();
					WMEncDataView Postview = new WMEncDataView();
					int lpreviewStream = DVColl_preview.Add(Preview);
					int lpostviewStream = DVColl_postview.Add(Postview);

					IWMEncBroadcast BrdCst = Encoder.Broadcast;

					if (Application.UserAppDataRegistry.GetValue("Port_number") !=
null &
Convert.ToString(Application.UserAppDataRegistry.GetValue("Port_number")).Length
> 0)
					{
						BrdCst.set_PortNumber
(WMENC_BROADCAST_PROTOCOL.WMENC_PROTOCOL_HTTP, port);
					}
					else
					{
						BrdCst.set_PortNumber
(WMENC_BROADCAST_PROTOCOL.WMENC_PROTOCOL_HTTP, 8080);
					}

					Encoder.PrepareToEncode(true);
					Encoder.Start();

					Preview.SetViewProperties(lpreviewStream,
(int)Panel_Preview.Handle);
					Preview.StartView (lpreviewStream);
					Postview.SetViewProperties(lpostviewStream,
(int)Panel_Postview.Handle);
					Postview.StartView (lpostviewStream);

5.Player.controls.play() doesn't work in IE, but works in Firefo


"Frances" wrote:

> In your javascript functions, try simply using
> 
> mediaPlayerObj.controls.play();
> mediaPlayerObj.controls.pause();
> 
> etc and remove the document.getElementbyID part.

But if you do that, the scripting will not work in Firefox. And besides if 
you read my playPauseVideo() function, I'm using the both forms and still it 
doesn't work.

function playPauseVideo() {
    document.getElementById('mediaPlayerObj').controls.play();
    mediaPlayerObj.controls.play();
} 

In the next function stopVideo() I'm using document.getElementById and this 
works in both IE and Firefox. 

function stopVideo() {
     document.getElementById('mediaPlayerObj').controls.stop();
} 


It appears that the controls.play() method has some unknown issues in IE. 

6. Player.controls.play() doesn't work in IE, but works in Firefox

7. Stopped Working---CD audio doesn't work anymore---

8. my speakers won't work and my mic won't work



Return to powershell

 

Who is online

Users browsing this forum: No registered users and 41 guest