Create folder with WMI with alternate credentials

Erik Groen 1 Reputation point
2021-11-10T09:43:55.53+00:00

Goodday,

I have a powershell script to create a folder on a remote computer with WMI. But i need to run this with alternate credentials. Normally we would just ad -credential $cred to the command but i don't know where to put it in this case.

$computer = "COMPUTERNAME" //add the computername where the folder needs to bee created
$pathname = "PATHNAME''//Add the path and foldername to be added
$p = [WMIClass]"\$computer\root\cimv2:Win32_Process" //Start local proces with help of WMI
$p.Create("cmd.exe /c md $pathname") // run CMD to execute the action

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,362 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 44,776 Reputation points
    2021-11-10T21:57:09.747+00:00
    0 comments No comments