Posts

Showing posts from September, 2017

Importing modules fails for C#.NET application - file cannot be loaded because running scripts is disabled on this system.

Image
When you're tying to import a PowerShell script into a C#.NET application you may see an error like this File C:\Program Files\WindowsPowerShell\Modules\AzureRM\4.4.0\AzureRM.psm1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170. When you check the execution policy using Get-ExecutionPolicy it looks fine. The issue here may be related to the application running in 32-bit mode, this has a different execution policy

The apply button of the PowerShell security descriptor dialog does not work as expected - Set-PSSessionConfiguration -ShowSecurityDescriptorUI -Name Microsoft.PowerShell

Image
When running the following command to modify the PowerShell security descriptor Set-PSSessionConfiguration -ShowSecurityDescriptorUI -Name Microsoft.PowerShell The following dialog is displayed. Be aware that clicking the Apply button does not apply the security setting until either the OK or cancel button is clicked. This behaviour can give confusing results when testing the access control lists.

Get-CimInstance PowerShell cmdlet doesn't have any methods

If you've moved from the Get-WmiObject to the new Get-CimInstance cmdlets you may find that these no longer have the methods available that you would have had when using Get-WmiObject. This is because everything is being routed correctly though the WS-MAN protocol and the objects that are returned are not code and cannot be executed. It's a simple work around - just pipe the object back to the Invoke-CimMethod cmdlet... $printers = Get-CimInstance Win32_Printer $descriptor = $printers[0] | Invoke-CimMethod -MethodName GetSecurityDescriptor

Get-Printer StartTime and UntilTime

Image
The Windows PowerShell Get-Printer cmdlet provides a start and finish time for printer availability but confusingly this value is returned as an integer value. More confusingly this is stored as a value of minutes from midnight GMT so if you print server is in GMT -5 and has a available from time of midnight you'll see the StartTime of 300. If you'd like to convert the time to a DateTime that is more understandable that reflects what is seen in the UI try the following $baseTime = [ System.DateTime ]:: MinValue . AddDays( 1 ) $baseTime = $baseTime . AddHours( [ System.TimeZoneInfo ]:: Local . BaseUtcOffset . TotalHours) $baseTime = $baseTime . AddMinutes( 150 )