add file extension
thanks,
Windows Forms
Hi friends,
Does anyone know of a good resource that I could study and get some practice making forms using the .NET framework? I feel like things are scattered here and there but I haven't been able to find a resource that gives a systematic treatment of form-making.
Thanks!
Out-File help in Powershell
I hope this is the correct area to post this.
Powershell newbie here.
I have a script that I found that displays a list of servers last reboot taken from a text file. However, I need that to not be displayed within powershell but sent to a text file. Here is the script:
# The following references server list from a text file $Servers = Get-Content “c:\cscripts\Servers1.txt” foreach($Server in $Servers) { $wmi=Get-WmiObject -class Win32_OperatingSystem -computer $server $LBTime=$wmi.ConvertToDateTime($wmi.Lastbootuptime) [TimeSpan]$uptime=New-TimeSpan $LBTime $(get-date) Write-host $server “Uptime: ” $uptime.days “Days” $uptime.hours “Hours” $uptime.minutes “Minutes” $uptime.seconds “Seconds” }Could someone assist me with a means to use Out-File, if it can be used here, to get the output to a text file?
I tried this:
Write-host $server “Uptime: ” $uptime.days “Days” $uptime.hours “Hours” $uptime.minutes “Minutes” $uptime.seconds “Seconds” | out-file "c:\reboots.txt"but it didn't work. It created the file but the results were not recorded to the file.
Thanks.
Query User Group, send to array, and remove all groups except particular ones in array
Here's what I've been tossing around.
Query a user's group in AD with, most likely, the get-qadmemberof command. Send to an array. I also tried using this to possibly start things
off but I couldn't get it to find the two groups below and remove them. It works if only one "Name=" is used.
Get-QADMemberOf /domainuser -SearchAttributes @{Name= “Yearbook Students”; [Name= “Beacon Students”]} Remove-QADGroupMember –member \domainuser
I'm trying to do this....
If
Array contains group A, B, or C, then keep these groups and remove the rest in the member of tab (except primary group).
Else
remove all groups.
end of script
This is what I've been working on from a high-level standpoint. I don't need it written for me, but it would surely me if I could get some tips on how
to get this started and which commands would work best.
Regards,
Chris
Setting up scheduled tasks on a remote server, using Powershell
Hey scripting guy, I think I got a good one.
I have a function, that schedules a task on a remote server. but it will only seem to work if I use a hard coded /ST Start time.
Function CreateScheduledTask ($server, $cmd, $name, $user, $password) { WriteInformation "$server - Creating Task $name." $command = "schtasks /create /F /TN $name /TR `"$cmd`" /SC once /ST 01:00 /RL HIGHEST /RU `"$user`" /RP `"$password`" /S `"$server`"" Invoke-WmiMethod -Class win32_process -Name create -ArgumentList $command -ComputerName "." | Out-Null
}
I did some testing and found that I could run:(provided I populate the varibles)
schtasks /create /F /TN $name /TR `"$cmd`" /SC once /ST (get-date).addseconds(30).tostring("HH:mm:ss") /RL HIGHEST /RU `"$user`" /RP `"$password`" /S `"$server`""And that seems to have worked, task created, and set to run in 30secs.
But when I try to call the function from my main script, it won't load into memory. (ie . .\helperfunctions.ps1 is called in the main script, and it errors out.) Seems like its related to syntax, but I am not sure. But if I change it back to the hardcoded 1:00 time, everything seems to work again.
So I would think it has something to do with that bit of code I am trying to insert.
Thanks for any help!
Joshua Fuente Farm Administrator SharePoint Products & Technologies
I am tying to create 380 new distribution groups
I have the following script and it will not work for me.
import-csv c:\distributionlist.csv
New-DistributionGroup -Name $entry.name -SAMAccountName $entry.samAccountName -OrganizationalUnit "OU=Location,OU=Distribution,OU= Groups,DC=Domain name,DC=COM" -Type "Distribution"
the Csv file has 2 columns one named name and the other samAccountName.
What am I doing wrong. I am getting an error of New-DistributionGroup : Cannot bind argument to parameter 'Name' because it is null.
I have also tried -alias and -DisplayName
On another note how can I add notes to the CSV and put it in the script run and place the notes in the distribution group
Vbscript to retrieve information about Enforce GPO Links
Hello,
im trying to write several VBscript that will retrieve as much information about GPO's as possible.
i currently want to retrieve all the GPO Links in the domain and whether they are set to Enforced or not.
i kniw i can do this using the GPM Com object, which i used to get other information...
but i can only use it if i find an example script online or in the GPMC sample scripts.
i haven't found any documentation online that is clear enough so i can use it to write my own scripts.
The class that's supposed to have this information is the GPOLink Class under the GPM object:
http://msdn.microsoft.com/en-us/library/microsoft.grouppolicy.gpolink_properties(v=vs.85).aspx
This MSDN page has a lot of information about the GPM object, but it doesn't explain how to access all these from VBscript.
so:
1) if anyone has a solution for my specific issue, retrieving all the gpo links in the domain and whether they are enforced or not.
2) A more general solution, directing me to clear documentation or examples for using the GPM Object.
I know that this information can be retrieved easily through POWERSHELL,
but i have to use vbscript.
Thanks.
settings for executing vbscript in html using webbrowser control?
It may seem like im asking a vb.net question but I think i found an answer to my own question jrv about the dsf. I can trick the OS into loading correct scripting engine automatically by placing dsf code inside of html page and calling invoke script this way in vb.net:
Webbrowser1.document.invokescript("method to execute in html page")
Trouble is the script does like my vb.net code and executes the first part except it then skips to removing the device instead of acting like normal and performing the device installation.
Should i be using an hta page or xml page instead of html so it will execute the vbscript properly or is their some setting i need to set on webbrowser or internet explorer to get it to execute all of my code?
Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda
Using variable for SMTP addresses in Send-Mailmessage
Here is my dilemma; I’m trying to use a variable for a send message command. For the SMTP From and To.
The problem is the send-mailmessage only uses the first address in the variable and ignores the rest. Is this a bug? Is there some workaround? I have tried the `, for value and that creates a format failure error.
If I perform “write-output $MyAlertsFailTo”, the entire variable displays on the screen. I’m stuck...
My variable:
[String] $MySMTPServer = "server.domain.local"
[String] $MyAlertsfrom = "ExchangeAlerts@yourcompany.com"
[String] $MyAlertsFailTo = "support1@yourcompany.com, support2@yourcompany.com, support3@yourcompany.com"
My Command:
Send-MailMessage -From "$MyAlertsfrom" -To "$MyAlertsFailTo" -Subject "Serious Error!" -Body "Message Text enclosed here " -Priority High -SMTPserver "$MySMTPServer" -DeliveryNotificationOption onFailure
Tony
NPS Local User with MAC scripting
Hello,
I would like to pull username and msNPCallingStationID from AD via Powershell and create local users on an NPS server and use it for 802.1x authentication.
I have managed to pull the data from AD, create the local users however I am not successful in finding out how to add the MAC to msNPCallingStationID which I can find referenced under "Parameters":
$user = [ADSI]"WinNT://[SERVERNAME]/testuser"
$user.Parameters
I have also managed to find it via psbase, but that didnt help much :(
Does anybody have any suggestions on how to get there?
Exchange 2010 - distribution group - build from CSV
Hi, I'm working on a script that will update (add/remove) groupmembers based on a CSV file comming from our human ressources. The file contains only 2 columns (PIN and distgroup).
Using the PIN, we find the account in active directory, check if it has a mailbox, check if it's in the group already and if it isn't we add it. I'm having trouble figuring out how to remove members if they are not found in our CSV file.
For example, if our human ressources changes something, an employee might disapear from the CSV file completely. In that case, he needs to be remove from all distribution groups he was a member of.
An employee might disapear from some groups and he will need to be removed from these ones only.
Here is my script so far. Can someone help ?
########################################################################### # # NAME: Update distribution group from CSV file # # AUTHOR: pa302126 (Patrick Alphonso) # # COMMENT: # # VERSION HISTORY: # 1.0 02/06/2011 - Initial release ########################################################################### If ( (Get-PSSnapin -Name quest.activeroles.admanagement -ErrorAction SilentlyContinue) -eq $null ) { Add-PSSnapin quest.activeroles.admanagement } # File selection function Select-FileDialog { param([string]$Title,[string]$Directory,[string]$Filter="All Files (*.*)|*.*") [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null $objForm = New-Object System.Windows.Forms.OpenFileDialog $objForm.ShowHelp = $true $objForm.InitialDirectory = $Directory $objForm.Filter = $Filter $objForm.Title = $Title $Show = $objForm.ShowDialog() If ($Show -eq "OK") { Return $objForm.FileName } Else { Write-Error "Operation cancelled by user." } } $csvfile = Select-FileDialog -Title "Select a file" -Directory "C:\ExchangeScripts\Scripts" -Filter "CSV (Comma delimited) (*.csv)|*.csv" If ($csvfile -eq $null) { Exit } # Function that imports the content of the csv file and place the values into an hash Function BuildDistGroupFromCSV{ Param([string]$fileName) $users = Import-Csv $fileName foreach ($user in $users) { $ht = @{ 'empid' = $user.pin 'DistributionGroup' = $user.distgroup } Write-Output $ht } } # Function that checks if the users is found and if he has a mailbox before adding to a distribution group. Function BuildDistGroup{ Param($userInfo) $_user = get-qaduser -enabled -SearchAttributes @{employeeID=$userInfo['empid']} If (!$_user) { Write-Host "Unable to find an account for employee" $userInfo['empid'] } Else { If (($_user) -and (get-user -identity $_user.SamAccountName | where-object{$_.RecipientType –eq “UserMailbox”})) { $_mail = get-qaduser -Identity $_user | Select-Object Email Write-Host "Email address" $_mail.email "found for" $_user.Name AddToDistributionGroup $_ } Else { Write-Host "User:" $_user.Name "does not have a mailbox" } } } Function AddToDistributionGroup{ # Check if user is already a member of Distribution Group $_checkmember = Get-DistributionGroupMember $userInfo['DistributionGroup'] | where-object{$_.Name –eq $_user.Name} If ($_checkmember) { Write-Host "User" $_user.Name "is already in" $userInfo['DistributionGroup'] } Else { # Add user to distribution Group add-distributiongroupmember -identity $userInfo['DistributionGroup'] -member $_mail.email Write-Host "Added" $_user.Name "to" $userInfo['DistributionGroup'] } } Function DistGroup{ PROCESS { BuildDistGroup $_ } } # Runs the entire script BuildDistGroupFromCSV $csvfile | DistGroupDumping a list of shares and security permissions across a domain
Hello,
I have been assigned the fairly daunting task of creating a list of ALL shares that exist within a single domain and also generating a list of all security groups that are being used for each share. I'm trying to decide whether to use dumpsec or to write a powershell script for this and was hoping that I would find similar scripts that are already designed specifically for this purpose. Does anyone have any suggestions?
WSH: Access a mobile device subfolder
Hello,
I'm trying to copy files from a mobile phone's SD card subfolder to my hard drive. This mobile phone (running Winmo 6.5) is connected through activesync.
Before I copy the files or folder, I'd like to test if the source folder exists. So I have this line of code:
If (oFso.FolderExists("D:\temp\Mobile Device.{35786D3C-B075-49B9-88DD-029876E11C01}\HTC HD2\Storage Card\SomeSubfolder")) ThenThis line will always return "FALSE".
However, If I write:
If (oFso.FolderExists("D:\temp\Mobile Device.{35786D3C-B075-49B9-88DD-029876E11C01}")) ThenThe line will return "TRUE".
So it seems the script sees the root folder of the mobile device, but can't consider a subfolder.
Anyone has an idea of how to make this work?
Thanks
Grendizer
Can I use a variable to invoke a command?
I am trying to invoke a binary from a Powershell script, but it seems unnecessarily complicated in the scenario I have, which is:
- The package can be installed anywhere.
- Invoking scripts or binaries via relative paths are no problem.
- At one point, I have to go to a fixed location and invoke a binary in the package I've installed. I trapped the initial location and stored it in $HERE.
- References to $HERE/br14.exe either when invoking it nakedly like that, or Invoke-Command -filepath $HERE/br14.exe report failure in various different ways.
So, is what I'm trying to do possible? If so, then a hint would be appreciated!
Thanks, Sam
VBScript to get Symantec Endpoint Protection details
Hi All,
Can any one help me to get Symantec Endpoint Protection details, like
General Information
Server : 10.140.124.10
Group :
Location:
Location Awarness:
policy Serial Number:
Last Scan Details :
we are using SEP version 11.0
Thanks
Dominic Palraj
Change Network ProviderOrder using powershell
Hi Guys and Gals
I am in need of changing the order of the ProviderOrder in the system registry
Current providerorder key returns this
PICAClientNetwork,RDPNP,LanmanWorkstation,webclient,PnSson
With powershell I can get it to this
PICAClientNetwork
RDPNP
LanmanWorkstation
webclient
PnSson
And then I can search the array for "LanmanWorkstation" and "RDPNP" I want it to read as follows
RDPNP,LanmanWorkstation,PICAClientNetwork,webclient,PnSson
Any ideas how I can get to the above using powershell?
Current code I have started with
function Get-RegistryValue($key, $value)
{ (Get-ItemProperty $key $value).$value}
$proder = Get-RegistryValue 'HKLM:\SYSTEM\CurrentControlSet\Control\NetworkProvider\Order' 'ProviderOrder' |% {$_.split(",")}
Two wmi queries messes up the results of the second one
I am having the following experience: When I run two gwmi commands, the second one is incomplete. For example:
The following queries:
gwmi -Class win32_service | select name gwmi -Class win32_bios #| select *...returns the following results:
...
vmvss
VSS
W32Time
wbengine
WbioSrvc
wcncsvc
WcsPlugInService
WdiServiceHost
WdiSystemHost
WebClient
Wecsvc
wercplsupport
WerSvc
WinDefend
WinHttpAutoProxySvc
Winmgmt
WinRM
Wlansvc
wmiApSrv
WMPNetworkSvc
WPCSvc
WPDBusEnum
wscsvc
WSearch
wuauserv
wudfsvc
WwanSvc
PhoenixBIOS 4.0 Release 6.0
If I leave off the first query, the bios query gives the following results:
SMBIOSBIOSVersion : 6.00
Manufacturer : Phoenix Technologies LTD
Name : PhoenixBIOS 4.0 Release 6.0
SerialNumber : VMware-56 4d e6 79 d0 57 cf 26-77 71 4a 65 5b f9 ac 32
Version : INTEL - 6040000
I've tried this on two machines, one running PS2, and one running PS3, using different wmi classes. Always, this result.
Can anyone else confirm / explain this?
Grant Ward, a.k.a. Bigteddy
What's new in Powershell 3.0 (Technet Wiki)
How to get driver version info of the network adapters using scripts
My application
I neet to get list of network adapter type and driver versions from my application (C#)
If I use Win32_NetworkAdapter class to get Network Adapters details, I can get Adapter type info but Driver version info in not part of the NetworkAdapter class. I can see that registry is having key HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318} which can give details of Driver Version along with Adapter type (Drive Description field).
DriverDate, DriverVersion, DriverDesc etc..
Is it the right way to get driver version info using registry key or do we have some APIs or classes or command line tools to get such details.
--Sanyog
How to display individual records in a multivalued attribute field in CSV file
Get-QADGroup ADGroupName | Select groupname , dn , members | export-CSV -notype -path 'C:\temp\adgroup2.csv'
Now in the CSV file the Members are displaying with a weird string below.
The Groupname displays properly
The dn displays properly
But members is showing
System.String[]
I am a newbie so if this has been answered anyhelp you can provide would be helpful.
Web proxy for powershell - something like Terminal services gateway
It exists even in the imagination of people? If there is a solution please point me to it . Thank you!
