简体   繁体   English

使用Powershell选择IIS物理路径后,如何删除/创建/重命名文件?

[英]How do you delete/create/rename files after selecting the IIS Physical Path using Powershell?

I can query IIS and get the current physical path: $sitepath = get-website xyz.net | 我可以查询IIS并获取当前的物理路径:$ sitepath = get-website xyz.net | select-object PhysicalPath but then need to find a file within a subdirectory of this and delete/create/rename. 选择对象PhysicalPath,但随后需要在此对象的子目录中查找文件并删除/创建/重命名。 The trouble I am having is that I see error "Cannot find drive. A drive with the name '@{physicalPath=d' does not exist." 我遇到的问题是我看到错误“找不到驱动器。名称为'@ {physicalPath = d'的驱动器不存在。” for any cmdlet I try to apply to $sitepath. 对于任何cmdlet,我尝试将其应用于$ sitepath。 Many thanks, 非常感谢,

You'll need to get a fileinfo or directoryinfo item from the path first. 您首先需要从路径中获取fileinfo或directoryinfo项。

This will work as long as the PhysicalPath doest contain environment variables (like %SystemDrive%\\inetpub\\wwwroot): 只要PhysicalPath不包含环境变量(例如%SystemDrive%\\ inetpub \\ wwwroot),此方法就可以工作:

$SiteFolder = get-item (get-website xyz.net).physicalpath
$fileInFolder="$($SiteFolder.fullname)\index.html")
$fileInFolder | gm;
$newFileHandle = $fileInFolder.Copy("C:\New\Path\Of\copiedFile")
$fileInFolder.Move("newfilename.htm"); 
$fileInFolder.Move("c:\new\Path\Of\File")
$FileInFolder.Delete()
$fileinFolder | Remove-Item

If the PhysicalPath does have system variables in it, Expand the variables into the full path by Expanding it: Expand Environmental Variables in PowerShell Strings and then using the above method to get a reference to the file object. 如果PhysicalPath中确实包含系统变量,请通过展开将其展开为完整路径: 在PowerShell字符串中展开环境变量 ,然后使用上述方法获取对文件对象的引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM