dhomya
running powershell cmdlets from windows 7 against windows 2003
Why is my compare script finding group inheritance ?
Hello,
When I run my script it is returning groups that do not have the user AD group membership in it directly.
Example if the person is a member of the Local Admins Group it is returning that he is a member of power user, backup operators, remote desktop users.
I just want to know if the AD group is in the local group or not.
Clear-Host
#This script gets the group and nested members of a user and compares it to the local groups on a server.
# If the user group is part of the local group it returns TRUE otherwise FALSE.
#*******************************************************
#Gets nested group members for an user
function GetGroups ($object)
{
Get-ADPrincipalGroupMembership $object | ForEach `
{
$_
# Get-ADPrincipalGroupMembership $_
GetGroups $_
}
}
#*********************************************************
# Uncomment this line to grab list of computers from a file
$Servers = Get-Content c:\temp\!_listv2.txt
#$Server = $env:computername # for testing on local computer
#$Servers = "xxxxxxx" # for testing on local computer
# User Information to run against a server.
$User = Get-ADUser "UserABC" -properties memberOf # user ID to compare against.
#$User = Read-Host 'What is the username?'
# Retrieves AD groups that the user is a member of
#$ADGroups = GetGroups $user | select name -Unique
[Array] $ADGroups = GetGroups $User | Where-Object -FilterScript {
$psitem -notin ('CN=Domain Users,CN=Builtin,DC=hteeter,DC=ht', 'CN=Users,CN=Builtin,DC=hteeter,DC=ht','CN=CERTSVC_DCOM_ACCESS,CN=Builtin,DC=hteeter,DC=ht')
}
# Change these two to suit your needs
#$ChildGroups = "domain users" # Compare to a single local domain group
$ChildGroups = $adgroups.name
#$LocalGroups = "Remote Desktop Users" # Compare to a single local group
$localgroups = Get-WMIObject win32_group -filter "LocalAccount='$true'" -computername $Servers | select name
$MemberNames = @()
foreach ($localgroup in $LocalGroups.name)
{ foreach ($Server in $Servers)
{
$Group= [ADSI]"WinNT://$Server/$LocalGroup,group"
$Members = @($Group.psbase.Invoke("Members"))
$Members | ForEach-Object {
$MemberNames += $_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)
}
$ChildGroups | ForEach-Object {
$output = "" | Select-Object Server, LocalGroup, AD_Group, InLocalGrp
$output.Server = $Server
$output.LocalGroup = $LocalGroup
$output.AD_Group = $_
$output.InLocalGrp = $MemberNames -contains $_
Write-Output $output
$output | Export-Csv c:\temp\compare.csv -Append -NoTypeInformation
}
}
}
problem with try catch
i am creating a function which first checks the existence of these two GPOs in GPMC.msc and if they don't exist,it doesn't generates error& instead it creates them. note that we can't use test-path because when we want to specify the address (DN) of these GPO in AD, we must write their GUID and we can't write their name. so i have to use try catch
function MyCreatADOUs { [Array]$GPOs = "GPO-OU-Users","GPO-OU-computers" $GPOs | foreach-object { try { Get-GPO -name $_ } catch { New-GPO -name $_} } New-GPLink "GPO-OU-Users" -target 'ou=ou-users,dc=hp,dc=lab' -LinkEnabled yes -ea Ignore New-GPLink "GPO-OU-computers" -target 'ou=ou-computers,dc=hp,dc=lab' -LinkEnabled yes -ea Ignore }
but i get these errors:
get-gpo : The "GPO-OU-Users" GPO was not found in the HP.lab domain.
Parameter name: gpoDisplayName
At C:\Users\Administrator\Desktop\Untitled2.ps1:7 char:24
+ get-gpo -name $GPO }
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.GroupPolicy.GPDomain:GPDomain)
[Get-GPO], ArgumentException
+ FullyQualifiedErrorId : GpoWithNameNotFound,Microsoft.GroupPolicy.Commands.GetGpoC
ommand
get-gpo : The "GPO-OU-computers" GPO was not found in the HP.lab domain.
Parameter name: gpoDisplayName
At C:\Users\Administrator\Desktop\Untitled2.ps1:7 char:24
+ get-gpo -name $GPO }
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.GroupPolicy.GPDomain:GPDomain)
[Get-GPO], ArgumentException
+ FullyQualifiedErrorId : GpoWithNameNotFound,Microsoft.GroupPolicy.Commands.GetGpoC
ommand
PS C:\> [Array]$GPOs = "GPO-OU-Users","GPO-OU-computers"
$GPOs | % {
try {
get-gpo -name $_ }
catch {
New-GPO -name $_}
}
New-GPLink "GPO-OU-Users" -target 'OU=OU-users,DC=HP,DC=lab' -LinkEnabled yes -ea Ignore
New-GPLink "GPO-OU-computers" -target 'OU=OU-computers,DC=HP,DC=lab' -LinkEnabled yes -ea Ignore
get-gpo : The "GPO-OU-Users" GPO was not found in the HP.lab domain.
Parameter name: gpoDisplayName
At line:4 char:24
+ get-gpo -name $_ }
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.GroupPolicy.GPDomain:GPDomain)
[Get-GPO], ArgumentException
+ FullyQualifiedErrorId : GpoWithNameNotFound,Microsoft.GroupPolicy.Commands.GetGpoC
ommand
get-gpo : The "GPO-OU-computers" GPO was not found in the HP.lab domain.
Parameter name: gpoDisplayName
At line:4 char:24
+ get-gpo -name $_ }
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.GroupPolicy.GPDomain:GPDomain)
[Get-GPO], ArgumentException
+ FullyQualifiedErrorId : GpoWithNameNotFound,Microsoft.GroupPolicy.Commands.GetGpoC
ommand
i also tried this code:
PS C:\> [Array]$GPOs = "GPO-OU-Users","GPO-OU-computers" $GPOs | % { $GOP = "$_" try { get-gpo -name $GPO } catch { New-GPO -name $GPO} } New-GPLink "GPO-OU-Users" -target 'OU=OU-users,DC=HP,DC=lab' -LinkEnabled yes -ea Ignore New-GPLink "GPO-OU-computers" -target 'OU=OU-computers,DC=HP,DC=lab' -LinkEnabled yes -ea Ignore
but again this error:
New-GPLink "GPO-OU-Users" -target 'OU=OU-users,DC=HP,DC=lab' -LinkEnabled yes -ea Ignore
New-GPLink "GPO-OU-computers" -target 'OU=OU-computers,DC=HP,DC=lab' -LinkEnabled yes -ea Ignore
get-gpo : The "GPO-OU-Users" GPO was not found in the HP.lab domain.
Parameter name: gpoDisplayName
At line:5 char:24
+ get-gpo -name $GPO }
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.GroupPolicy.GPDomain:GPDomain)
[Get-GPO], ArgumentException
+ FullyQualifiedErrorId : GpoWithNameNotFound,Microsoft.GroupPolicy.Commands.GetGpoC
ommand
get-gpo : The "GPO-OU-computers" GPO was not found in the HP.lab domain.
Parameter name: gpoDisplayName
At line:5 char:24
+ get-gpo -name $GPO }
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.GroupPolicy.GPDomain:GPDomain)
[Get-GPO], ArgumentException
+ FullyQualifiedErrorId : GpoWithNameNotFound,Microsoft.GroupPolicy.Commands.GetGpoC
command
any help please
thanks in advanced
Hide disabled accounts form GAL but exclude functional mailboxes
Hello,
The requirement is to hide disabled users form GAL however we have to exclude functional mailboxes whose accounts are already disabled.
One powershell script was found
Get-Mailbox -ResultSize unlimited |Where{($_.UserAccountControl -like “AccountDisabled*”)} | set-mailbox -HiddenFromAddressListsEnabled $true
However need to exclude functional mailboxes form this as running this cmdlet will hide functional mailboxes also in GAL.
The functional mailbox reside in separate OU under user accounts OU.Regards, Ajit
Help with Powershell - moving files to folders based on date
I have spent about a week on this task, and I know I am nowhere near an expert on Powershell, I am running into a wall.
Here is what I want to accomplish - I have a folder with 1000's of files going back three years. I want to write a PS script that will move all the files older than three months into archive folders based on the file creation date. I need two levels, Year and inside the year, month.
Here is what I have so far
$location = "C:\scripts\Test1"
cd $location
dir | ?{$_.psiscontainer -eq $false}| %{$a="$($_.creationtime.year.ToString())";mkdir -ea 0 $a;mv $_ $a}
$locationYear = "C:\Scripts\Test1\$a"
cd $locationYear
dir | ?{$_.psiscontainer -eq $false}| %{$b="$($_.creationtime.month.ToString())";mkdir -ea 0 $b;mv $_ $b}
I know its basic, but it is working so far, except the folder month is in numeral format, 3 not 03. This is a requirement from our development team.
Any help would be appreciated, Thanks!
Raise a PowerShell events from within a runspace (which has no GUI elements) to the Powershell host
Hello everyone,
I saw this PS code snippet on stackoverflow from the PS MVP Bo Prox;
$Global:x = [Hashtable]::Synchronized(@{}) $x.Host = $Host $rs = [RunspaceFactory]::CreateRunspace() $rs.ApartmentState,$rs.ThreadOptions = "STA","ReUseThread" $rs.Open() $rs.SessionStateProxy.SetVariable("x",$x) $cmd = [PowerShell]::Create().AddScript({ Add-Type -AssemblyName PresentationFramework,PresentationCore,WindowsBase $x.w = [Windows.Markup.XamlReader]::Parse(@"<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" MaxWidth="800" WindowStartupLocation="CenterScreen" WindowStyle="None" SizeToContent="WidthAndHeight"><Button Name="test" Content="Starte Installation"/></Window>"@) $x.test = $x.w.FindName('test') $x.test.Add_Click({ $x.Host.Runspace.Events.GenerateEvent( "TestClicked", $x.test, $null, "test event") } ) $x.w.ShowDialog() }) $cmd.Runspace = $rs $handle = $cmd.BeginInvoke() Register-EngineEvent -SourceIdentifier "TestClicked" -Action {$Global:x.host.UI.Write("Event Happened!")}
My question is whether it is possible to raise a non-GUI based event from the runspace which can be handled in the PowerShell host using the Register-EngineEvent?
I tried New-Event from within the runspace which is "-forward"ed through another engine event in the same run space hoping that it will be received by the PowerShell Host Engine Event but it does not appear to have worked. The fact that the above GUI based event has worked, I am hopeful there has to be a way for the non-gui based runspace.
Thanks in advance
script not working
Hi,
I am trying to create a script on rdpmanager to import details from a csv file.
function global:Add-RDCManConfig { #Requires -Version 2.0 [CmdletBinding()] Param ( [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] -[Array[]]$ComputerName=import-csv "C:\PS\xml\serverlist.csv", [String]$Template = "C:\ps\XML\RDCTemplate.rdg", [String]$NewTemplate = "C:\ps\XML\RDCTemplateUpdate.rdg" )#End Param Begin { Write-Verbose "Adding computers to RDCManConfig . . ." [XML]$RDCConfig = Get-Content -Path $Template } Process { $ComputerName | ForEach-Object { $Computer = $_.host $Disp = $_.connectionname [XML]$Server ="<server><name>$Computer</name><displayName>$Disp</displayName> $New = $RDCConfig.ImportNode($Server.Server, $true) $RDCConfig.RDCMan.file.group.AppendChild($New) }#Foreach-Object(ComputerName) } End { $RDCConfig.Save($NewTemplate) } }
Due to some reasons the script doesn't run and throws the below messgage
This is the reference script.
https://gallery.technet.microsoft.com/49207d61-721d-4522-879b-2634d2d02cc6#content
Best Regards, Arun http://whynotsql.blogspot.com/
Is there a way to have your PS script Query the name of your local Mail Server?
Hey Guys,
Really hoping someone can help me out here. I am currently working on a script that Automates the entire user creation process (AD account, Exchange Mailbox, UCM Soft phone). I want this script to be universal for all systems I have to work with. By this I mean that I can run the script on various systems (Different Domains) without ever having to modify the code.
I have run into a bit of a problem while trying to automate the PSSession component of my script. I would like to be able to run he script and it inserts the relevant Mail server name based on some sort of Lookup or query. I am currently circumventing the issue by having a text box pop up asking for the mail server name. It works, but its not really what I want for the end product. Its frustrating seeing as I have overcome similar issues for things like UPNs, AD Server, etc....
I have though about having it pull from the DNS MX records, but there are a number of different records for different Mail servers.
Any help would be awesome!
Call get-credential from within a Runspace
Hey all so I'm having some trouble calling get-credential from within a runspace. Popup messages work fine so I would think this should too. I know I can use get-credential outside of the runspace and pass the value to it but is there anyway I can do it inside?
Here's my test:
$hash = [hashtable]::Synchronized(@{}) $hash.Host = $host $hash.flag = $false $runspace = [runspacefactory]::CreateRunspace() $runspace.Open() $runspace.SessionStateProxy.SetVariable('Hash',$hash) $powershell = [powershell]::Create() $powershell.Runspace = $runspace $powershell.AddScript({ Get-Credential }) | Out-Null $handle = $powershell.BeginInvoke() While (-Not $handle.IsCompleted) { Start-Sleep -Milliseconds 100 } $powershell.EndInvoke($handle) $runspace.Close() $powershell.Dispose()
Thanks I'm still really knew to runspaces and would love any help.
PowerShell scripts
Hello There,
i need to know about bulk email address hide in office 365 cloud and want know if there is any way through by PowerShell
script. because there are large number of unwanted users in our Office 365 cloud and want to hide the from Global Address List. any idea how to hide the unwanted email with PowerShell scripts.
Execute commands remote with PSSession
Hi,
I am trying to write a script that is executed on Server A but connects to Server B and executes the commands with remote Powershell.
I am currently just trying some simple commands since it's the first time I have tried the remote Powershell function. I connect to a server which is working fine, but if I do a simple command like:
$FoundFiles = Get-ChildItem - Path "C:\Temp"
it returns an error telling me that it cannot find the path. If I do the same and use "C:\Windows" it works.
If I enter the commands manually in a console everything also works as expected.
?
Lasse
/Lasse
help with encoding and decoding a file
I'm writing a couple of scripts that will transfer a file using UDP.
I'm testing reading in a file and writing it back out on the same computer and need some guidance.
#this reads in the file, encodes it, writes it back out in the encoded form.
$localpath = "c:\test\test.log"
$contents = [IO.File]::ReadAllBytes($localPath)
$contents = [Text.Encoding]::ASCII.GetBytes($contents)
[io.file]::WriteAllBytes('c:\test\test1.log',$contents)
#I'm trying to read in the encoded data and decode and write it back out, but I get an error
$localpath1 = "c:\test\test1.log"
$contents1 = [IO.File]::ReadAllBytes($localPath1)
$contents1=[Text.Encoding]::ASCII.GetString($contents1)
[io.file]::WriteAllBytes('c:\test\test2.log',$contents1)
Here is the error I get
Cannot convert argument "1", with value: "91 50 48 49 52 45 48 57 45 50 57 32 49 48 58 52 50 58 48 51 44 48 56 56 93 32 91 73 78 70 79 93 32 67 108105 101 110 116 32 82 80 67 32 108 105 115 116 101 110 105 110 103 32 111 110 32 49 50 55 46 48 46 48 46 49 58 54 48 54 51 32 46 46 46 13 10 91 50 4
8 49 52 45 48 57 45 50 57 32 49 55 58 48 49 58 52 54 44 53 48 57 93 32 91 73 78 70 79 93 32 71 111 116 32 108 111 103 111 117 116 32 97 108 101 114
116 32 102 111 114 32 101 108 111 103 101 115 111 110", for "WriteAllBytes" to type "System.Byte[]": "Cannot convert value "91 50 48 49 52 45 48 57
45 50 57 32 49 48 58 52 50 58 48 51 44 48 56 56 93 32 91 73 78 70 79 93 32 67 108 105 101 110 116 32 82 80 67 32 108 105 115 116 101 110 105 110 103
32 111 110 32 49 50 55 46 48 46 48 46 49 58 54 48 54 51 32 46 46 46 13 10 91 50 48 49 52 45 48 57 45 50 57 32 49 55 58 48 49 58 52 54 44 53 48 57 9
3 32 91 73 78 70 79 93 32 71 111 116 32 108 111 103 111 117 116 32 97 108 101 114 116 32 102 111 114 32 101 108 111 103 101 115 111 110" to type "Sy
stem.Byte[]". Error: "Cannot convert value "
Thanks for any advice.
Server Manager complains Domain Controller isn't promoted if Install-ADDSForest run twice
We were scripting an install of Active Directory Forest on our Domain Controller on a Windows Server 2012 R2 machine.
On some occasions, we would see cases where Server Manager would have a flag indicating the Domain Controller needed to be promoted, even though it was done by the script. When clicking on the link to promote, the Active Directory Domain Services Configuration Wizard would pop up, but have an error: "Error determining whether the target server is already a domain controller. Failed to open the runspace pool..."
We finally traced it down to the install-addsforest command. If for some reason, this command is run again, on a domain controller already configured, Server Manager will be the state mentioned above. As far as I can tell, the Domain controller is running ok. However, I do not know how to correct the Flag, without rebuilding the domain controller.
The command we ran was
Install-ADDSForest -DomainName "tmmukunn.contoso.com" -installdns -force -DomainNetBiosName "tmmukunn" -databasepath "D:\NTDS" -sysVolPath "D:\SysVol" -LogPath "D:\NTDS"
After specifying the SafeModeAdministrator Password, the install works fine and the computer reboots.
After reboot, Server Manager indicates no issue.
If we re-run the command, we'll get an error: Install-addsforest : Verification of prerequisites for Domain Controller promotion failed. The specified argument 'DataBasePath' was not recognized.
Even if I trim down to just the Domain Name, it will complain the argument NewDomainName was not recognized.
After bringing up Server manager, the flag will now be set with an exclamation point, and it will indicate configuration required for Active Directory Domain Services and a link will be present to Promote this server to a domain controller. As mentioned above, clicking on the link will bring up the ADDS Configuration Wizard, with the red banner error: Failed to open the runspace pool. The Server Manager WinRM plug-in might be corrupted or missing.
I also believe if you run the Test-ADDSForestInstallation will cause the same issue with Server Manager before an install of an AD Forest. However, running the Install-ADDSForest afterwards will make that issue disappear.
Copy Files From Remote Machines
Hi,
I've got a script i've modified and does the job if i'm logged on that machine if i wanted to change it so it will use a Get-Content to grab machine names and then get the last logged on users profile?
$destination = "C:\Backup" $folder = "Desktop","Favorites","Documents","AppData\Roaming\Microsoft\Signatures","AppData\Roaming\Microsoft\Outlook" ############################################################################################################### ###### Restore data section ###### if ([IO.Directory]::Exists($destination + "\" + $username + "\")) { { write-host -ForegroundColor yellow "Aborting process Folder Exists" exit } } ###### Backup Data section ######## else { write-host -ForegroundColor green "Backing up data from local machine for $username" foreach ($f in $folder) { $currentLocalFolder = $userprofile + "\" + $f $currentRemoteFolder = $destination + "\" + $username + "\" + $f $currentFolderSize = (Get-ChildItem -ErrorAction silentlyContinue $currentLocalFolder -Recurse -Force | Measure-Object -ErrorAction silentlyContinue -Property Length -Sum ).Sum / 1MB $currentFolderSizeRounded = [System.Math]::Round($currentFolderSize) write-host -ForegroundColor cyan " $f... ($currentFolderSizeRounded MB)" Copy-Item -ErrorAction silentlyContinue -recurse $currentLocalFolder $currentRemoteFolder } write-host -ForegroundColor green "Backup complete!" }
Powershell commands to loop through organization wide Outlook personal (not global) contact folder for each person
I have a 3 line query that lists the contents on the personal contacts folder in Outlook for a user. How can I pipe a list of mailbox users names into the script so that I can get a list of contacts in the personal contacts folder for each person, along with the mailbox they are associated with. Here are the 3 lines in a simple powershell script I have so far
$Outlook=NEW-OBJECT –ComObject Outlook.Application
$Contacts=$Outlook.session.GetDefaultFolder(10).items
$Contacts | Format-Table FullName,CompanyName,BusinessTelephoneNumber,Email1Address
If someone already has a script they'd share or would build and share that would be great
Thanks,
Paul
quiestion on understanding the @ in powershell and needing confirmation
I came across the following script:
-----------------
Get-ADUser -Filter * -SearchScope Subtree -SearchBase "ou=East,ou=SalesRegion,dc=Nutex,dc=com" | Set-AdUser -Replace @{title="Account Executive"}
---------------
I did not really understand the why the @ is used I did some searches on it
http://stackoverflow.com/questions/363884/what-does-the-symbol-do-in-powershell
they spoke about this being used to denote arrays. However, they said if a value is comma separated its seen as an array anyway. They did go on to say this is required for Associative arrays. I looked up associative arrays and got the following:
- Associative arrays. Thus, you can access each property by entering the name of the property as a string into this array. Such an arrayassociates each key with a value (in this case the key Home is associated with the value normal).
--------------
This tells me I think that the script I was looking at after the pipe had an associative array as we entered the name of the property "title" and then it was associated with the value "=Account Executive".
So when I see something like that I am seeing what is called a associative array, and these are vehicles that can be used to change or work with properties? Its an array because it can be dealing with multiple (or single depending on how many) objects. In this case the object was the title property in AD.
Thats kind of how I am seeing this but its complex ideas and I am trying to break it down to simple thinking in my head.
Anyway before I commit this theory in my thinking I was just wanted some with more experience to let me know if I am on the correct path.
strange problem with select-string
Hello
i wonder why the first command delivers desired output but the second doesn't. is there any technical explanation for this issue?
1st command:
PS C:\>IPConfig | Select-String -Pattern 'IPV4'
output: IPv4 Address. . . . . . . . . . . : 10.1.1.1
2nd set of commands:
# none of the following commands generates output !!!!
(Get-WmiObject Win32_OperatingSystem) | Select-String -Pattern 'version'
#or
Get-WmiObject Win32_OperatingSystem | Select-String -Pattern 'version'
#or
[string]$var = Get-WmiObject win32_operatingSystem
$var | Select-String -Pattern 'version'
#or
[Array]$var = Get-WmiObject win32_operatingSystem
$var | Select-String -Pattern 'version'
what can be the reason?
( i do know that there are lots of workarounds to achieve that, for example redirecting Get-WmiObject win32_operatingSystem to a text file & the Get-content that text file piped into select string. but i need to know the reason about above examples since
the mechanism is the same !)
thanks in advanced
Directing Powershell Parameter to floating variable in VB.net code
Hello,
I am currently working on a small application created in visual studio 2013. This is a very simple application in which I have a button, and once clicked, a powershell script is run. Within the script are 2 parameters...one is directed to a text
file, which is read. The other is directed to a folder path.
The program works as it should if I place the folder somewhere on the machine running the application, however, I wish to to run this completely off a USB drive. I have done this in the past with code similar to that found below:
Note that the running files folder is on the same level as the exe created in visual studio.
Private Sub SystemprepExecute()Dim str As String
str = ""
Process.Start("running files\Firewall bat files\Firewall - Turn Off.bat").WaitForExit()
I have attempted to to take similar action with my pawershell script, however, it doesnt seem to like the floating variable of the folder path (param1). Please view code below:
Private Sub TEST_Click(sender As Object, e As EventArgs) Handles TEST.ClickProcess.Start("powershell", "-noexit -file gpo\Import.ps1 -param1 gpo\ -param2 gpo\test.txt")
End Sub
I am new to both powershell and vb.net, so any help would be greatly appreciated. I am assuming I need to address the folder path of param1 in a different manner, but am unsure of how to do so.
Note that my exe file will reside on the same level as the "gpo" folder
AD Powershell commands for VB atributes
HI
I am working on a script to get the user information, specifically I need "Domain\username" backbecause my app needs domain\username
Get-ADGroupMember -identity “Group_Name” | select name | Export-csv -path C:names.csv -NoTypeInformation
But I want to get the "ntuserdomainid" which is :Domain:username" because my app needs domain\username and I can use excel to change the : to a \
The problem is when I ask for ntuserdomainid the script returns "Microsoft.ActiveDirectory.Management.ADPropertyValueCollection"
How do I query the "VBScript" type fields?
Tasks
Filtering for error Event logs remotely
Hi there
I've been trying to do a script to search for Application and System error event logs over the last 24 hours so that I can analyse them without going onto the server.
The script is supposed to the following:
1) upload a server list from a text file
2) Set a time stipulation to search from 1 day ago
3) Search the specified eventlog eg Application for all errors within the one day
4) From point 3, it should generate a text file with the server's name and the error logs.
My script goes like this:
$servers = get-content "C:\CompanyA\Patching\April2014\GroupProd\GroupProd1.txt"
$yesterday = (get-date) - (New-TimeSpan -Days 1)
foreach ($obj in $servers) {Get-WinEvent -computername $obj -FilterHashtable @{logname='Application';StartTime=$yesterday;level=2} | select MachineName, Timecreated, Providername, ID, Message > $obj"-Application_errors.txt"}
The error I get is the following:
Get-WinEvent : The specified resource type cannot be found in the image file
At line:1 char:41
+ foreach ($obj in $servers) {Get-WinEvent <<<< -computername $obj -FilterHashtable @{logname='Application';StartTime=
$yesterday;level=2} | select MachineName, Timecreated, Providername, ID, Message > $obj"-Application_errors.txt"}
+ CategoryInfo : NotSpecified: (:) [Get-WinEvent], EventLogException
+ FullyQualifiedErrorId : The specified resource type cannot be found in the image file,Microsoft.PowerShell.Comma
nds.GetWinEventCommand
Any ideas guys?
Thanks