Questions tagged «powershell-3.0»


11
如何在PowerShell中加载程序集?
以下PowerShell代码 #Get a server object which corresponds to the default instance $srv = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Server ... rest of the script ... 给出以下错误信息: New-Object : Cannot find type [Microsoft.SqlServer.Management.SMO.Server]: make sure the assembly containing this type is loaded. At C:\Users\sortelyn\ ... \tools\sql_express_backup\backup.ps1:6 char:8 + $srv = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Server + …


7
检查Windows PowerShell中是否存在文件?
我有这个脚本,可以比较磁盘两个区域中的文件,并在修改日期较旧的那个区域中复制最新文件。 $filestowatch=get-content C:\H\files-to-watch.txt $adminFiles=dir C:\H\admin\admin -recurse | ? { $fn=$_.FullName; ($filestowatch | % {$fn.contains($_)}) -contains $True} $userFiles=dir C:\H\user\user -recurse | ? { $fn=$_.FullName; ($filestowatch | % {$fn.contains($_)}) -contains $True} foreach($userfile in $userFiles) { $exactadminfile= $adminfiles | ? {$_.Name -eq $userfile.Name} |Select -First 1 $filetext1=[System.IO.File]::ReadAllText($exactadminfile.FullName) $filetext2=[System.IO.File]::ReadAllText($userfile.FullName) $equal = $filetext1 -ceq $filetext2 …

14
如何测试对象是否具有特定属性?
如何测试对象是否具有特定属性? 赞赏我能做的... $members = Get-Member -InputObject $myobject 然后foreach通过$members,但是是否有功能测试对象是否具有特定属性? 附加信息: 问题是我要导入两种不同类型的CSV文件,一种包含两列,另一种包含三列。我无法使用“属性”检查支票,只能使用“ NoteProperty” ...不管有什么区别 if ( ($member.MemberType -eq "NoteProperty" ) -and ($member.Name -eq $propertyName) )

6
PowerShell:按字段值检索JSON对象
考虑以下格式的JSON: "Stuffs": [ { "Name": "Darts", "Type": "Fun Stuff" }, { "Name": "Clean Toilet", "Type": "Boring Stuff" } ] 在PowerShell 3中,我们可以获得Stuffs的列表: $JSON = Get-Content $jsonConfigFile | Out-String | ConvertFrom-Json 假设我们不知道列表的确切内容,包括对象的顺序,我们如何检索名称字段具有特定值的对象? 蛮力,我们可以遍历列表: foreach( $Stuff in $JSON.Stuffs ) { 但我希望存在更直接的机制(类似于C#中的Lync或Lambda表达式)。
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.