System Center Blog

    by Mikael Perhult (SCCMx)

    Browsing Posts in Powershell

    When there is a need for retrieve dhcp server info this cmd line can be used.

    The method will collect Last logon date and OS version so it can be used for dhcp server migration.

    Get-DhcpServerInDC | % { Get-ADComputer -Identity ($_.dnsname).Substring(0, ($_.dnsname).IndexOf(‘.’)-0) -Properties LastLogonDate,OperatingSystem | Select-Object Name,LastLogonDate,OperatingSystem }

    When ever there is a need for setting policy for powershell execution there is a nice way around this by querying the current setting and parsing this around the script.

     

    powershell.exe -noprofile -command “& {$variable = Get-ExecutionPolicy:If((Get-ExecutionPolicy) -ne ‘Unrestricted’){Set-ExecutionPolicy unrestricted -force;}; <ENTER SCRIPT NAME HERE>; Set-ExecutionPolicy $variable}”