Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Create a folder on a remote machine?

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 03-16-2008   #1 (permalink)
Gerry Hickman
Guest


 

Create a folder on a remote machine?

Hi,

Is there a way to create a folder on a remote machine using PowerShell
(not FileSystemObject), e.g. create a new folder "D:\My Folder".

<if possible>

It should not rely on UNC paths, because it's part of a bigger program
that needs to continue running if there's a network outage.

Thanks.

--
Gerry Hickman (London UK)

My System SpecsSystem Spec
Old 03-16-2008   #2 (permalink)
RichS
Guest


 

RE: Create a folder on a remote machine?

If you are running PowerShell V2 CTP then you could use the remoting
facilities. otherwise you could use WMI

$computer = "."
$p = [WMIClass]"\\$computer\root\cimv2:Win32_Process"
$p.Create("cmd.exe /c md c:\test452")

replace the . with the computer name in $computer = "."

and put the folder name you need into the create statement

--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"Gerry Hickman" wrote:
Quote:

> Hi,
>
> Is there a way to create a folder on a remote machine using PowerShell
> (not FileSystemObject), e.g. create a new folder "D:\My Folder".
>
> <if possible>
>
> It should not rely on UNC paths, because it's part of a bigger program
> that needs to continue running if there's a network outage.
>
> Thanks.
>
> --
> Gerry Hickman (London UK)
>
My System SpecsSystem Spec
Old 03-16-2008   #3 (permalink)
Gerry Hickman
Guest


 

Re: Create a folder on a remote machine?

Hi,
Quote:

> If you are running PowerShell V2 CTP then you could use the remoting
> facilities. otherwise you could use WMI
What is the syntax I'd use with V2 CTP? I don't mean the exact code,
just a rough example.
Quote:

> $computer = "."
> $p = [WMIClass]"\\$computer\root\cimv2:Win32_Process"
> $p.Create("cmd.exe /c md c:\test452")
No, no, no! This is clueless! It starts a process who's output and
RetVal are NOT referenced the calling process. Obviously I want the
RetVal from the CreateFolder call, plus any error messages, plus a
handle to the newly created folder.

I was hoping for some professional grade PowerShell answers.

I though PowerShell was going to replace CMD.exe? Having read about how
"powerful" it is, and how it's a "shell". It's a joke if we have to
shell out to the old CMD.exe for such a simple task.

It's also a bit strange that we keep hearing about how PowerShell is so
"Powerful" with it's calls to .NET, and yet every non-beginner post
keeps jumping back to using WMI which is actually the old COM technology.

--
Gerry Hickman (London UK)
My System SpecsSystem Spec
Old 03-16-2008   #4 (permalink)
Kryten
Guest


 

Re: Create a folder on a remote machine?



Quote:

> It's also a bit strange that we keep hearing about how PowerShell is so
> "Powerful" with it's calls to .NET, and yet every non-beginner post
> keeps jumping back to using WMI which is actually the old COM technology.
>
> --
> Gerry Hickman (London UK)


How odd!

WMI was good (new?) enough in your post 2 hours ago to
microsoft.public.adsi.general:-
<<SNIP>>
Bear in mind none of this will work with IIS7, they took out the ADSI
so
it's best to look to new ways of doing it anyway (maybe WMI?)
<<SNIP>>

What you get from Rich S is about as "Professional Grade" as it gets.

I on the other hand am anything but "Professional Grade", but even I
can see that given the parameters
you provided in your OP the response was fit for purpose and did not
deserve your inelegant response.

Hope you get the answer your looking for though!

Kind regards,
--
Stuart




My System SpecsSystem Spec
Old 03-16-2008   #5 (permalink)
Oisin (x0n) Grehan [MVP]
Guest


 

Re: Create a folder on a remote machine?

On Mar 16, 3:35*pm, Gerry Hickman <gerry66...@xxxxxx> wrote:
Quote:

> Hi,
>
Quote:

> > If you are running PowerShell V2 CTP then you could use the remoting
> > facilities. * otherwise you could use WMI
>
> What is the syntax I'd use with V2 CTP? I don't mean the exact code,
> just a rough example.
>
Quote:

> > $computer = "."
> > $p = [WMIClass]"\\$computer\root\cimv2:Win32_Process"
> > $p.Create("cmd.exe /c md c:\test452")
>
> No, no, no! This is clueless! It starts a process who's output and
> RetVal are NOT referenced the calling process. Obviously I want the
> RetVal from the CreateFolder call, plus any error messages, plus a
> handle to the newly created folder.
>
> I was hoping for some professional grade PowerShell answers.
>
> I though PowerShell was going to replace CMD.exe? Having read about how
> "powerful" it is, and how it's a "shell". It's a joke if we have to
> shell out to the old CMD.exe for such a simple task.
>
> It's also a bit strange that we keep hearing about how PowerShell is so
> "Powerful" with it's calls to .NET, and yet every non-beginner post
> keeps jumping back to using WMI which is actually the old COM technology.
>
> --
> Gerry Hickman (London UK)
Hi Gerry,

Despite what its MS marketing droid bestowed "marquee name" implies
with the hyperbolous prefix, Powershell is not magic. It is a
framework, a shell and a scripting language that is designed to
abstract out the differing APIs on the windows platform such as WMI,
COM, .NET etc. Yes, it comes with a handful of built-in cmdlets, and
perhaps they are lacking a fair chunk of functionality for v1, but
this is by-design. Great extensibility is a better goal for an initial
release than an inextensible and purely subjective view of what they
felt would be "feature complete" for functionality. I'm sorry if
you're having a hard time understanding what the product is and does
-- and clearly you are having a hard time -- but hurling insults and
calling people clueless will not get you any help, or sympathy for
that matter.

Ultimately, powerSHELL is a shell. It's job is to allow you to
manipulate external services like WMI. It doesn't try to replace it,
on the contrary - it is designed to make it easier to use WMI. RichS's
solution is perfectly valid. The irony is, if such a "remote folder
creation" cmdlet is ever implemented for powershell in the future, it
will most likely use COM and/or WMI to do it. Do bash, tcsh, ksh
implement internal magic such as what you're suggesting for
powershell? No, they do not. They provide a way to execute and
manipulate 3rd party executables and leverage CIFS through UNC paths.
What you are asking for is not within a reasonable expectations for a
"shell."

If you don't want to end up in any more killfiles, I suggest you tone
down your rhetoric and start reading here:

http://www.microsoft.com/windowsserv...l/default.mspx

- Oisin
My System SpecsSystem Spec
Old 03-17-2008   #6 (permalink)
Brandon Shell [MVP]
Guest


 

Re: Create a folder on a remote machine?

You guys way over think this stuff

new-item \\$computer\c$\FolderName -itemType Directory

"RichS" <RichS@xxxxxx> wrote in message
news:B58F5F2B-7D9C-44EB-8599-A55C9CBCAB25@xxxxxx
Quote:

> If you are running PowerShell V2 CTP then you could use the remoting
> facilities. otherwise you could use WMI
>
> $computer = "."
> $p = [WMIClass]"\\$computer\root\cimv2:Win32_Process"
> $p.Create("cmd.exe /c md c:\test452")
>
> replace the . with the computer name in $computer = "."
>
> and put the folder name you need into the create statement
>
> --
> Richard Siddaway
> Please note that all scripts are supplied "as is" and with no warranty
> Blog: http://richardsiddaway.spaces.live.com/
> PowerShell User Group: http://www.get-psuguk.org.uk
>
>
> "Gerry Hickman" wrote:
>
Quote:

>> Hi,
>>
>> Is there a way to create a folder on a remote machine using PowerShell
>> (not FileSystemObject), e.g. create a new folder "D:\My Folder".
>>
>> <if possible>
>>
>> It should not rely on UNC paths, because it's part of a bigger program
>> that needs to continue running if there's a network outage.
>>
>> Thanks.
>>
>> --
>> Gerry Hickman (London UK)
>>
My System SpecsSystem Spec
Old 03-17-2008   #7 (permalink)
Brandon Shell [MVP]
Guest


 

Re: Create a folder on a remote machine?

See my example. It is one line and returns a system.io.directoryinfo object

"Gerry Hickman" <gerry666uk@xxxxxx> wrote in message
news:ueIMmz5hIHA.4320@xxxxxx
Quote:

> Hi,
>
Quote:

>> If you are running PowerShell V2 CTP then you could use the remoting
>> facilities. otherwise you could use WMI
>
> What is the syntax I'd use with V2 CTP? I don't mean the exact code, just
> a rough example.
>
Quote:

>> $computer = "."
>> $p = [WMIClass]"\\$computer\root\cimv2:Win32_Process"
>> $p.Create("cmd.exe /c md c:\test452")
>
> No, no, no! This is clueless! It starts a process who's output and RetVal
> are NOT referenced the calling process. Obviously I want the RetVal from
> the CreateFolder call, plus any error messages, plus a handle to the newly
> created folder.
>
> I was hoping for some professional grade PowerShell answers.
>
> I though PowerShell was going to replace CMD.exe? Having read about how
> "powerful" it is, and how it's a "shell". It's a joke if we have to shell
> out to the old CMD.exe for such a simple task.
>
> It's also a bit strange that we keep hearing about how PowerShell is so
> "Powerful" with it's calls to .NET, and yet every non-beginner post keeps
> jumping back to using WMI which is actually the old COM technology.
>
> --
> Gerry Hickman (London UK)
My System SpecsSystem Spec
Old 03-17-2008   #8 (permalink)
Brandon Shell [MVP]
Guest


 

Re: Create a folder on a remote machine?

This was brought up in a side bar. So for clarity.

I ignored the UNC restriction purposely. If you lose your network... aint
nothing gonna work.

"Brandon Shell [MVP]" <tshell._rem_@xxxxxx> wrote in message
news:41922DAE-7989-4FA0-B620-946876BD603A@xxxxxx
Quote:

> You guys way over think this stuff
>
> new-item \\$computer\c$\FolderName -itemType Directory
>
> "RichS" <RichS@xxxxxx> wrote in message
> news:B58F5F2B-7D9C-44EB-8599-A55C9CBCAB25@xxxxxx
Quote:

>> If you are running PowerShell V2 CTP then you could use the remoting
>> facilities. otherwise you could use WMI
>>
>> $computer = "."
>> $p = [WMIClass]"\\$computer\root\cimv2:Win32_Process"
>> $p.Create("cmd.exe /c md c:\test452")
>>
>> replace the . with the computer name in $computer = "."
>>
>> and put the folder name you need into the create statement
>>
>> --
>> Richard Siddaway
>> Please note that all scripts are supplied "as is" and with no warranty
>> Blog: http://richardsiddaway.spaces.live.com/
>> PowerShell User Group: http://www.get-psuguk.org.uk
>>
>>
>> "Gerry Hickman" wrote:
>>
Quote:

>>> Hi,
>>>
>>> Is there a way to create a folder on a remote machine using PowerShell
>>> (not FileSystemObject), e.g. create a new folder "D:\My Folder".
>>>
>>> <if possible>
>>>
>>> It should not rely on UNC paths, because it's part of a bigger program
>>> that needs to continue running if there's a network outage.
>>>
>>> Thanks.
>>>
>>> --
>>> Gerry Hickman (London UK)
>>>
>
My System SpecsSystem Spec
Old 03-17-2008   #9 (permalink)
Gerry Hickman
Guest


 

Re: Create a folder on a remote machine?

Hi Brandon,
Quote:

> This was brought up in a side bar. So for clarity.
>
> I ignored the UNC restriction purposely. If you lose your network...
> aint nothing gonna work.
Not correct. Part of robust systems programming is designing for the
unexpected, such as resume after power failure. One of the reasons for
wanting to do it without UNC is that my project is a large batch job
that runs unattended, it's quite possible some servers will be rebooted
while the job is running, it's therefore important that my job runs
"locally" (albeit on the remote machine).

Actually this is quite common. Most Microsoft technology is designed to
work this way (e.g. Windows Update, Vista SP1 etc).

So, do you have a PowerShell/.NET means of creating a folder on a remote
machine?

--
Gerry Hickman (London UK)
My System SpecsSystem Spec
Old 03-17-2008   #10 (permalink)
Gerry Hickman
Guest


 

Re: Create a folder on a remote machine?

Hi Oisin,
Quote:

> Despite what its MS marketing droid bestowed "marquee name" implies
> with the hyperbolous prefix,
Hehe!
Quote:

> Powershell is not magic. It is a
> framework, a shell and a scripting language that is designed to
> abstract out the differing APIs on the windows platform such as WMI,
> COM, .NET etc. Yes, it comes with a handful of built-in cmdlets, and
> perhaps they are lacking a fair chunk of functionality for v1, but
> this is by-design.
None of this helps, so it's broken "by design", great!

I'm interested in how to make it WORK, NOT excuses about why it doesn't.
Quote:

> Great extensibility is a better goal for an initial
> release than an inextensible and purely subjective view of what they
> felt would be "feature complete" for functionality.
Good grief. You're starting to sound like "marketing droid" referenced
above!
Quote:

> I'm sorry if
> you're having a hard time understanding what the product is and does
> -- and clearly you are having a hard time -- but hurling insults and
> calling people clueless will not get you any help, or sympathy for
> that matter.
The reason I said "clueless" is not because of my understanding of
PowerShell, His example is FLAWED is ANY language, I should have
x-posted it to the C++ group, at least they'd confirm it's flawed. It's
not RichS's fault, he copied it from Microsoft own clueless website.

--
Gerry Hickman (London UK)
My System SpecsSystem Spec
Closed Thread
Update your Vista Drivers Update Your Drivers Now!!

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Exch 2003, create Mailbox from Vista machine? Gerry Hickman PowerShell 11 04-16-2008 09:47 AM
checked for logged on user on remote machine + remote reboot Ben Christian PowerShell 2 03-10-2008 06:52 PM
getting remote machine directory IT Staff PowerShell 3 07-19-2007 04:11 AM
Can't create a new file or folder with in a shared folder on a Windows XP machine. Basic Vista networking questions Nate Goulet Vista installation & setup 4 04-18-2007 04:20 AM
HowTo: Run a Command (.exe or .cmd) on a Remote Machine Brandon Shell PowerShell 6 09-18-2006 06:17 AM


Vistax64.com 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 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14