1. 判断一个对象是不是空可以用 $null来比较
2. 判断一个字符串是不是空的: [string]::IsNullOrEmpty(...)
3. 在powershell中把结果输出为一个CSV格式的文本文件的方法, 好处自己想
# Get the current script execution path so our CSV file gets saved back there [string]$curloc = get-location out-file -filepath "$curlocWADBs.csv" # Create the empty CSV array $arrCSV = @() # Create the empty record object and start populating it with information $objDB = "" | select DBName,DBStatus,WebApplication $objDB.DBName = $database.name $objDB.DBStatus = $database.status $objDB.WebApplication = $webapp.URL # Add the new record as a new node in the CSV array $arrCSV += $objDB # Now that we’ve added all of the records to the array we need to write the CSV array out to the file system $arrCSV | Export-Csv "$curlocWADBs.csv" -NoTypeInformation
4. Powershell在遍历SharePoint的时候也要注意释放spsite和spweb,要不然也会占用服务器大量的空间。最简单的方法是在代码开始的时候写
start-spassignment -global
结束的时候用 stop-spassignment -global来释放空间。