SQLM_M
asked on
Creating Folder in Remote Servers Using Powershell
I want to create a folder in list of servers that i specify in a .csv file. The format of csv file is
server user password
192.168.14.15 sa password1
I get the following error when i execute the below code from local machine where i have installed Powershell v2.
Powershell has not been installed on the server where i need to create a folder.
Please provide me a solution.
Cannot convert value "\\@{server=192.168.15.14; user=sa; password=password1}.server \root\cimv 2:Win32_Pr ocess" to type
"System.Management.Managem entClass". Error: "The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)"
At line:4 char:16
+ $p = [WMIClass] <<<< "\\$computer\root\cimv2:Wi n32_Proces s"
+ CategoryInfo : NotSpecified: (:) [], RuntimeException
+ FullyQualifiedErrorId : RuntimeException.
If i execute the same code for local machine i get the same error but i get the folder created.
server user password
192.168.14.15 sa password1
I get the following error when i execute the below code from local machine where i have installed Powershell v2.
Powershell has not been installed on the server where i need to create a folder.
Please provide me a solution.
Cannot convert value "\\@{server=192.168.15.14;
"System.Management.Managem
At line:4 char:16
+ $p = [WMIClass] <<<< "\\$computer\root\cimv2:Wi
+ CategoryInfo : NotSpecified: (:) [], RuntimeException
+ FullyQualifiedErrorId : RuntimeException.
If i execute the same code for local machine i get the same error but i get the folder created.
$Path="D:\Test1"
$servers = Import-csv "C:\Powershell\serverlist.csv"
ForEach ($server in $servers)
{
$computer = "$server.server"
$p = [WMIClass]"\\$computer\root\cimv2:Win32_Process"
$p.Create("cmd.exe /c md $Path")
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
in your CSV file is the header on the column for the servers "ServerName". So it should look like this
Servername
Server1
Server2
Server3
Servername
Server1
Server2
Server3
ASKER
Hi,
I changed the csv header but still i get the login failure error.
New-Item : Logon failure: unknown user name or bad password.
At line:1 char:39
+ ForEach ($server in $servers){New-Item <<<< "\\$($server.servername)\d $\Test1" -type directory}
+ CategoryInfo : WriteError: (\\192.168.151.38\d$\Test1 :String) [New-Item], IOException
+ FullyQualifiedErrorId : CreateDirectoryIOError,Mic rosoft.Pow erShell.Co mmands.New ItemComman d
I changed the csv header but still i get the login failure error.
New-Item : Logon failure: unknown user name or bad password.
At line:1 char:39
+ ForEach ($server in $servers){New-Item <<<< "\\$($server.servername)\d
+ CategoryInfo : WriteError: (\\192.168.151.38\d$\Test1
+ FullyQualifiedErrorId : CreateDirectoryIOError,Mic
The account you are using does not have access to the remote server.
Are you able to access
\\192.168.151.38\d$
Are you able to access
\\192.168.151.38\d$
ASKER
It prompts for login credentials. I could able to access if i give the credentials...
try this
{New-Item "\\$($Server.Servername)\d $\Test1" -type directory -credentials DOMAIN\USERNAME}
{New-Item "\\$($Server.Servername)\d
ASKER
Thanks for your solution.
ASKER
I've requested that this question be closed as follows:
Accepted answer: 0 points for SQLM_M's comment http:/Q_27321945.html#36580325
for the following reason:
Thanks for your solution.
Accepted answer: 0 points for SQLM_M's comment http:/Q_27321945.html#36580325
for the following reason:
Thanks for your solution.
ASKER
Sorry i have wrongly chosen the solution. The exact solution is provided by KenMcF solution id is 36580114
ASKER
I get the following error when i execute this code
$servers = Import-csv "C:\Powershell\serverlist.
ForEach ($server in $servers){New-Item "\\$($Server.Servername)\d
New-Item : The path is not of a legal form.
At line:1 char:39
+ ForEach ($server in $servers){New-Item <<<< "\\$($server.servername)\d
+ CategoryInfo : InvalidArgument: (\\\d$\Test1:String) [New-Item], ArgumentException
+ FullyQualifiedErrorId : CreateDirectoryArgumentErr