powershell

How do I debug a Windows PowerShell module in Visual Studio?

一笑奈何 提交于 2021-01-20 18:09:47
问题 I'm trying to write a PowerShell module as a VB.NET project with Visual Studio 2015. I've been able to put a few commands together, compile the class library into a DLL, import the module into a PowerShell session and call the command I created. All good so far. But as I'm expanding this module I'm going to need to be able to debug it. So I added another project to the solution, a console application. I set it as the startup project and referenced the PowerShell class in the first project. So

How do I debug a Windows PowerShell module in Visual Studio?

可紊 提交于 2021-01-20 18:09:40
问题 I'm trying to write a PowerShell module as a VB.NET project with Visual Studio 2015. I've been able to put a few commands together, compile the class library into a DLL, import the module into a PowerShell session and call the command I created. All good so far. But as I'm expanding this module I'm going to need to be able to debug it. So I added another project to the solution, a console application. I set it as the startup project and referenced the PowerShell class in the first project. So

How do I debug a Windows PowerShell module in Visual Studio?

自古美人都是妖i 提交于 2021-01-20 18:09:19
问题 I'm trying to write a PowerShell module as a VB.NET project with Visual Studio 2015. I've been able to put a few commands together, compile the class library into a DLL, import the module into a PowerShell session and call the command I created. All good so far. But as I'm expanding this module I'm going to need to be able to debug it. So I added another project to the solution, a console application. I set it as the startup project and referenced the PowerShell class in the first project. So

Cannot remove item. The directory is not empty

℡╲_俬逩灬. 提交于 2021-01-20 15:20:09
问题 I am trying to delete a folder with subfolders/files. Remove-Item -Force -Recurse -Path $directoryPath I am getting the error Cannot remove item. The directory is not empty. My PowershellScript.ps1 has executionPolicy unrestricted . The root folder I try to delete with the current logged in user has full permission on this folder. On my local pc the code works but not on my Windows Server 2012 R2 . 回答1: You could try the following: Remove-Item -Force -Recurse -Path "$directoryPath\*" Note

PowerShell order sensitive Compare-Objects diff

≡放荡痞女 提交于 2021-01-20 07:55:54
问题 Is it possible to do the order comparison of items in arrays with Compare-Object aka diff in PowerShell? if not, suggest a workaround. $a1=@(1,2,3,4,5) $b1=@(1,2,3,5,4) if (Compare-Object $a1 $b1) { Write-Host 'Wrong order ' } else { Write-Host 'OK' } 回答1: Use -SyncWindow 0 : $a1=@(1,2,3,4,5) $b1=@(1,2,3,5,4) if (Compare-Object $a1 $b1 -SyncWindow 0) { Write-Host 'Wrong order ' } else { Write-Host 'OK' } More info: Comparing Arrays in Windows PowerShell. 回答2: You could compare items in arrays

store the output of powershell command in a variable

*爱你&永不变心* 提交于 2021-01-20 05:02:59
问题 The following commnad: $sun=PowerShell [DateTime]::Today.AddDays(-8).ToString('dd-MMM-yyyy') echo %sun % the output of the echo is PowerShell [DateTime]::Today.AddDays(-8).ToString('dd-MMM-yyyy') how do i get it to output something like 22-Sep-2013 回答1: You need to use for /f : for /f "usebackq" %%x in (`powershell "(Get-Date).AddDays(-8).ToString('dd-MMM-yyyy')"`) do set sun=%%x 来源: https://stackoverflow.com/questions/19089736/store-the-output-of-powershell-command-in-a-variable

store the output of powershell command in a variable

霸气de小男生 提交于 2021-01-20 05:01:44
问题 The following commnad: $sun=PowerShell [DateTime]::Today.AddDays(-8).ToString('dd-MMM-yyyy') echo %sun % the output of the echo is PowerShell [DateTime]::Today.AddDays(-8).ToString('dd-MMM-yyyy') how do i get it to output something like 22-Sep-2013 回答1: You need to use for /f : for /f "usebackq" %%x in (`powershell "(Get-Date).AddDays(-8).ToString('dd-MMM-yyyy')"`) do set sun=%%x 来源: https://stackoverflow.com/questions/19089736/store-the-output-of-powershell-command-in-a-variable

Is it possible to position a window when starting a process with PowerShell (Start-Process)?

假装没事ソ 提交于 2021-01-20 04:12:24
问题 I'm running the command as follows. Start-Process dotnet -ArgumentList "run" The window can be managed using -WindowStyle flag to be maximized, minimized, hidden and normal. However, what I usually do is to push the frame to the left (and the second to the right). Is it possible to tell PowerShell to float the window to the edge? Something like this wishful pseudo-code? Start-Process dotnet -ArgumentList "run" -WindowStyle FloatLeft 回答1: Try this, which uses the -Passthru option for Start

Is it possible to position a window when starting a process with PowerShell (Start-Process)?

大兔子大兔子 提交于 2021-01-20 04:12:14
问题 I'm running the command as follows. Start-Process dotnet -ArgumentList "run" The window can be managed using -WindowStyle flag to be maximized, minimized, hidden and normal. However, what I usually do is to push the frame to the left (and the second to the right). Is it possible to tell PowerShell to float the window to the edge? Something like this wishful pseudo-code? Start-Process dotnet -ArgumentList "run" -WindowStyle FloatLeft 回答1: Try this, which uses the -Passthru option for Start

Windows DHCP最佳实践(四)

落花浮王杯 提交于 2021-01-19 23:40:20
这是Windows DHCP最佳实践和技巧的最终指南。 如果您有任何最佳做法或技巧,请在下面的评论中发布它们。 在本指南(四)中,我将分享以下 DHCP最佳实践和技巧 。 使用DHCP中继代理 防止恶意DHCP服务器 备用DHCP服务器 DHCP MAC地址过滤 结论 DHCP中继代理 如果您有一个具有多个网络的集中式DHCP服务器,则需要使用DHCP中继代理。 广播DHCP消息,路由器不转发广播数据包。要解决此问题,您可以在路由器/交换机上启用DHCP中继代理功能,以允许DHCP广播数据包到达设备。 您将需要查看路由器文档,以获取启用中继代理的命令。 资料来源 思科配置DHCP中继代理 HP配置DHCP中继 防止恶意DHCP服务器 您是否曾经有用户或IT部门中的某人将交换机/路由器插入墙上的可用端口?然后,导致用户无法连接到Internet或其他资源,Helpdesk电话开始爆炸? 流氓DHCP服务器令人头疼。此外,它们可能会带来安全隐患,并且会被用于各种攻击。 阻止恶意DHCP服务器的最佳方法是在网络交换机上,可以通过称为DHCP侦听或基于802.1x端口的网络访问选项来完成。 DHCP监听 DHCP侦听是第2层交换功能,可阻止未经授权的(恶意)DHCP服务器向设备分配IP地址。 DHCP通过将交换端口分类为受信任或不受信任的端口来工作。可信端口允许DHCP消息