What difference between ConvertFrom-CSV and ConvertFrom-StringData?
来源:互联网 发布:piano软件 编辑:程序博客网 时间:2024/05/16 10:28
在Windows PowerShell中,我们会发现有两个类似的命令如标题所言:ConvertFrom-CSV 与 ConvertFrom-StringData 而从表现呈现的表单看他们的样子是一样的,但到底有何不同呢?
先来看看两者各自的命令说明我们在来进行一番比较:
ConvertFrom-StringData
ConvertFrom-StringData cmdlet 将包含一个或多个键-值对的字符串转换为哈希表。由于每个键-值对必须位于一个单独的行上,所以经常使用 here-string 作为输入格式。
可将 ConvertFrom-StringData cmdlet 视为可在脚本或函数的 DATA 节中使用的安全 cmdlet。在 DATA 节中使用时,字符串的内容必须遵循 DATA 节的规则。有关详细信息,请参阅 about_Data_Sections。
ConvertFrom-CSV
ConvertFrom-CSV cmdlet 通过 ConvertTo-CSV cmdlet 生成的 CSV 长度可变字符串来创建对象。
可使用 ConvertFrom-CSV cmdlet 的参数来指定列标题行(列标题行确定所获得的对象的属性名称)、指定项目分隔符,或指示 ConvertFrom-CSV 使用当前区域性的列表分隔符作为分隔符。
ConvertFrom-CSV 创建的对象是原始对象的 CSV 版本。CSV 对象的属性值是原始对象的属性值的字符串版本。对象的 CSV 版本不含任何方法。
也可使用 Export-CSV 和 Import-CSV cmdlet 将对象转为 CSV 字符串(或将 CSV 字符串转换为变量)。这些 cmdlet 和 ConvertTo-CSV、ConvertFrom-CSV cmdlet 一样,只是它们是将 CSV 字符串保存在文件中。
接下来让我们进行实际比较,先赋值一段内容给Process变量,内容如下。
PS C:\> $Process=@'>> "Name","CPU">> "notepad","0.9828063">> "calc","0.436323">> '@>>
然后将变量传递给ConvertFrom-CSV看下结果:
PS C:\> ConvertFrom-Csv -InputObject $ProcessName CPU---- ---notepad 0.9828063calc 0.436323
再通过获得类型我们可以发现,ConvertFrom-CSV生成的其实是一个数组。
PS C:\> (ConvertFrom-Csv -InputObject $Process).GetType()IsPublic IsSerial Name BaseType-------- -------- ---- --------True True Object[] System.Array
以同样的形式我们将声明的对象赋值给ConvertFrom-StringData看下结果:
PS C:\> $b=@'>> Name = Disks.ps1>> Category = Storage>> Cost = Free>> '@
PS C:\> $b|ConvertFrom-StringDataName Value---- -----Cost FreeName Disks.ps1Category Storage
而ConvertFrom-StringData生成的其实是一个哈希表:
PS C:\> ($b|ConvertFrom-StringData).gettype()IsPublic IsSerial Name BaseType-------- -------- ---- --------True True Hashtable System.Object
- What difference between ConvertFrom-CSV and ConvertFrom-StringData?
- What is difference between UIModalTransitionStyle and UIModalPresentationStyle ?
- what is difference between IRQ and FRQ
- What's difference between PMP and PRINCE2
- What is the difference between test, [ and [[ ?
- WPF TypeConvert中 ConvertFrom的行为
- What is the difference between AWT and SWT?
- What's the difference between an event and a delegate?
- what's the difference between OnDraw and OnPaint
- What is the difference between User Control and Custom Control?
- What is the difference between an EXE and a DLL?
- What is the difference between XML and C or C ?
- What is the difference between SMOD and CMOD?
- what is the difference between little-endian and big-endian.
- What is the difference between procedural and nonprocedural language?
- What are the difference between DDL, DML and DCL commands?
- What are the difference between DDL, DML and DCL commands?
- what is the difference between the setTimeout and setInterval
- MCG格式监控录像数据恢复成功
- ATMS V1.0发布,修改了QTP Agent的一些bug!
- 使用SoapUI从数据库中随机获取数据做WS压力测试
- C++面试宝典2011版 .
- 通用JS验证(手机,电话,邮箱,QQ)
- What difference between ConvertFrom-CSV and ConvertFrom-StringData?
- Unity 3D游戏开发工具
- hdu 4547 Tarjan LCA 离线算法
- [转]提高android ContentProvider的效率
- 合唱队形
- 产品程序 单片机程序 规划
- SmsManager发短信(—)
- vc 消息与事件的区别
- 二叉排序树的创建与删除